Skip to content

Commit e42d2dd

Browse files
committed
Update CONTRIBUTING.md
1 parent 7e1576e commit e42d2dd

File tree

1 file changed

+112
-47
lines changed

1 file changed

+112
-47
lines changed

CONTRIBUTING.md

Lines changed: 112 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
* [4.6 To contribute changes](#46-to-contribute-changes)
1414
* [4.7 How To Report A Bug](#47-how-to-report-a-bug)
1515
* [4.8 How To Suggest A Feature Or Enhancement](#48-how-to-suggest-a-feature-or-enhancement)
16-
* [5. Code Review Process](#5-code-review-process)
17-
* [5.1 Issues](#51-issues)
18-
* [5.2 Pull Requests](#52-pull-requests)
19-
* [5.3 Differences between "new features" and "improvements"](#53-differences-between-new-features-and-improvements)
20-
* [6. Community](#6-community)
16+
* [5. Community](#5-community)
2117

2218
# 1. Introduction
2319
**Welcome!** First off, thank you for contributing to the further development of Red. We're always looking for new ways to improve our project and we appreciate any help you can give us.
@@ -29,25 +25,25 @@ Red is an open source project. This means that each and every one of the develop
2925
We love receiving contributions from our community. Any assistance you can provide with regards to bug fixes, feature enhancements, and documentation is more than welcome.
3026

3127
# 2. Ground Rules
32-
1. Ensure cross compatibility for Windows, Mac OS and Linux.
28+
1. Ensure cross compatibility for Windows, macOS and Linux.
3329
2. Ensure all Python features used in contributions exist and work in Python 3.8.1 and above.
34-
3. Create new tests for code you add or bugs you fix. It helps us help you by making sure we don't accidentally break anything :grinning:
30+
3. If you're working on code that's covered by tests, create new tests for code you add or bugs you fix.
31+
It helps us help you by making sure we don't accidentally break anything :grinning:
3532
4. Create any issues for new features you'd like to implement and explain why this feature is useful to everyone and not just you personally.
36-
5. Don't add new cogs unless specifically given approval in an issue discussing said cog idea.
33+
5. Don't make Pull Requests adding new functionality if there is no accepted issue discussing said functionality.
3734
6. Be welcoming to newcomers and encourage diverse new contributors from all backgrounds. See [Python Community Code of Conduct](https://www.python.org/psf/codeofconduct/).
3835

3936
# 3. Your First Contribution
4037
Unsure of how to get started contributing to Red? Please take a look at the Issues section of this repo and sort by the following labels:
4138

42-
* beginner - issues that can normally be fixed in just a few lines of code and maybe a test or two.
43-
* help-wanted - issues that are currently unassigned to anyone and may be a bit more involved/complex than issues tagged with beginner.
39+
* Good First Issue - issues that can normally be fixed in just a few lines of code.
40+
* Help Wanted - issues that are currently unassigned to anyone and may be a bit more involved/complex than issues tagged with Good First Issue.
4441

4542
**Working on your first Pull Request?** You can learn how from this *free* series [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github)
4643

47-
At this point you're ready to start making changes. Feel free to ask for help; everyone was a beginner at some point!
44+
At this point you're ready to start making changes. Feel free to ask for help (see information about [Community](#5-community) below); everyone was a beginner at some point!
4845

4946
# 4. Getting Started
50-
5147
Red's repository is configured to follow a particular development workflow, using various reputable tools. We kindly ask that you stick to this workflow when contributing to Red, by following the guides below. This will help you to easily produce quality code, identify errors early, and streamline the code review process.
5248

5349
### 4.1 Setting up your development environment
@@ -59,6 +55,10 @@ The following requirements must be installed prior to setting up:
5955
If you're not on Windows, you should also have GNU make installed, and you can optionally install [pyenv](https://github.com/pyenv/pyenv), which can help you run tests for different python versions.
6056

6157
1. Fork and clone the repository to a directory on your local machine.
58+
```bash
59+
git clone https://github.com/Cog-Creators/Red-DiscordBot
60+
cd Red-DiscordBot
61+
```
6262
2. Open a command line in that directory and execute the following command:
6363
```bash
6464
make newenv
@@ -74,16 +74,20 @@ If you're not on Windows, you should also have GNU make installed, and you can o
7474
.venv\Scripts\activate
7575
```
7676
Each time you open a new command line, you should execute this command first. From here onwards, we will assume you are executing commands from within this activated virtual environment.
77+
4. (optional but recommended) Install pre-commit hook which automatically ensures that you meet our style guide when you make a commit:
78+
```bash
79+
pre-commit install
80+
```
7781

78-
**Note:** If you're comfortable with setting up virtual environments yourself and would rather do it manually, just run `pip install -Ur tools/dev-requirements.txt` after setting it up.
82+
**Note:** If you're comfortable with setting up virtual environments yourself and would rather do it manually, just run `pip install -Ur tools/dev-requirements.txt` after setting it up and optionally install a pre-commit hook with `pre-commit install`.
7983
8084
### 4.2 Testing
8185
We're using [tox](https://github.com/tox-dev/tox) to run all of our tests. It's extremely simple to use, and if you followed the previous section correctly, it is already installed to your virtual environment.
8286
8387
Currently, tox does the following, creating its own virtual environments for each stage:
8488
- Runs all of our unit tests with [pytest](https://github.com/pytest-dev/pytest) on python 3.8 (test environment `py38`)
8589
- Ensures documentation builds without warnings, and all hyperlinks have a valid destination (test environment `docs`)
86-
- Ensures that the code meets our style guide with [black](https://github.com/psf/black) (test environment `style`)
90+
- Ensures that the code meets our style guide (test environment `pre-commit`, does not run by default because it changes state of project folder and it is already checked by `pre-commit`)
8791
8892
To run all of these tests, just run the command `tox` in the project directory.
8993
@@ -92,14 +96,97 @@ To run a subset of these tests, use the command `tox -e <env>`, where `<env>` is
9296
Your PR will not be merged until all of these tests pass.
9397
9498
### 4.3 Style
95-
Our style checker of choice, [black](https://github.com/psf/black), actually happens to be an auto-formatter. The checking functionality simply detects whether or not it would try to reformat something in your code, should you run the formatter on it. For this reason, we recommend using this tool as a formatter, regardless of any disagreements you might have with the style it enforces.
96-
97-
Use the command `black --help` to see how to use this tool. The full style guide is explained in detail on [black's GitHub repository](https://github.com/psf/black). **There is one exception to this**, however, which is that we set the line length to 99, instead of black's default 88. This is already set in `pyproject.toml` configuration file in the repo so you can simply format code with Black like so: `black <src>`.
99+
This project uses a bunch of style checks to ensure that all of the code is formatted consistently.
100+
We use [pre-commit](https://pre-commit.com/) to ensure that all of these are fulfilled by all PRs made on our repositories.
101+
102+
If you've done the optional step of installing a pre-commit hook [4.1 Setting up your development environment](#41-setting-up-your-development-environment) section,
103+
you actually don't have to worry about anything as all of these style checks are ran automatically whenever you make a commit. However, if you chose not to, you can:
104+
- run all hooks on currently **staged** (`git add`ed) files with:
105+
```bash
106+
pre-commit
107+
```
108+
- or run all hooks on all files with:
109+
```bash
110+
pre-commit run --all-files
111+
```
112+
113+
Now let's get itnot the specifics of the checks that we have.
114+
115+
Primarily, we use [Black](https://github.com/psf/black) and [isort](https://github.com/PyCQA/black) which both are actually auto-formatters.
116+
This means that the checking functionality simply detects whether or not it would try to reformat something in your code, should you run the formatter on it.
117+
For this reason, we recommend using these tools as formatters, regardless of any disagreements you might have with the style they enforce.
118+
119+
The full style guide is explained in detail in [Black's documentation](https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html).
120+
121+
**There are two exceptions to this**.
122+
Firstly, we set the line length to 99, instead of Black's default 88. This is already set in `pyproject.toml` configuration file in the repo so you do not need to specify this when running Black.
123+
Secondly, we do not allow the usage of `# fmt: skip` and `# fmt: on/off` comments for excluding parts of code from being reformatted. **All** of the code should be formatted with Black in full.
124+
125+
The other auto-formatter that we use - [isort](https://github.com/PyCQA/black) - only focuses on sorting imports alphabetically, and automatically separated into sections and by type.
126+
127+
Imports are sectioned based on where they import from in order:
128+
- future imports (`from __future__ import ...`)
129+
- imports from Python's standard library (e.g. `import collections` or `from typing import Any`)
130+
- imports from third-party libraries (e.g. `import aiohttp` or `from discord.ext import commands`)
131+
- imports from first-party libraries (imports from `redbot`)
132+
- relative imports (e.g. `from .submodule import ...`)
133+
134+
Within a section, `from ... import ...` statements are placed *after* `import ...` statements and the imports are sorted alphabetically.
135+
136+
Other checks and formatters that we are using:
137+
- [flake8](https://flake8.pycqa.org/en/stable/):
138+
This linter (check) is primarily used to prevent some common errors and bad practices.
139+
It might also report on some style issues though that should happen rarely when using Black formatter.
140+
141+
When necessary, specific errors can be ignored with a `# noqa: CODE` annotation written above or at the end of the relevant line.
142+
The explanation of how this annotation works can be found in
143+
[flake8's documentation](https://flake8.pycqa.org/en/latest/user/violations.html#in-line-ignoring-errors).
144+
- [end-of-file-fixer](https://github.com/pre-commit/pre-commit-hooks#end-of-file-fixer):
145+
This ensures that all text files have exactly one empty line at the end. This is a common practice and is often required by Unix tools.
146+
147+
References:
148+
- [why you should end a file in a newline (beginner) anthony explains #083 on YouTube](https://www.youtube.com/watch?v=r5nWtfwK_dk)
149+
- [Why should text files end with a newline? on Stack Overflow](https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline)
150+
- [mixed-line-ending](https://github.com/pre-commit/pre-commit-hooks#mixed-line-ending):
151+
This replaces usage of `CRLF` (`\r\n`) as the line ending with `LF` (`\n`). This improves consistency, minimizes git diffs
152+
and generally causes less problems than using `CRLF` as the line ending.
153+
- [trailing-whitespace](https://github.com/pre-commit/pre-commit-hooks#trailing-whitespace):
154+
This formatter removes trailing whitespace from all lines in text files. Trailing whitespace can be somewhat annoying when working on a file
155+
and it can also introduce subtle bugs with multi-line string literals in Python.
156+
157+
References:
158+
- [Why is trailing whitespace a big deal?](https://softwareengineering.stackexchange.com/questions/121555/why-is-trailing-whitespace-a-big-deal)
159+
- [check-ast](https://github.com/pre-commit/pre-commit-hooks#check-ast),
160+
[check-json](https://github.com/pre-commit/pre-commit-hooks#check-json),
161+
[check-toml](https://github.com/pre-commit/pre-commit-hooks#check-toml),
162+
[check-yaml](https://github.com/pre-commit/pre-commit-hooks#check-yaml):
163+
These checks just verify that `.py`, `.json`, `.toml`, and `.yaml` files are using valid syntax.
164+
- [pretty-format-json](https://github.com/pre-commit/pre-commit-hooks#pretty-format-json):
165+
This is an auto-formatter ensuring consistent indentation across all JSON files in the repository.
166+
- [check-case-conflict](https://github.com/pre-commit/pre-commit-hooks#check-case-conflict):
167+
This checks that the repository does not contain two or more files with names that only differ in their casing (i.e. `file` and `File`).
168+
This is done to ensure that the repository can actually be checked out on a case-insensitive filesystem that are commonly used on
169+
macOS (e.g. HFS+) and Windows (e.g. NTFS and FAT).
170+
- [check-merge-conflict](https://github.com/pre-commit/pre-commit-hooks#check-merge-conflict):
171+
This checks that the files do not contain merge conflict strings which can sometimes accidentally happen when resolving conflicts with git.
172+
- [no-commit-to-branch](https://github.com/pre-commit/pre-commit-hooks#no-commit-to-branch):
173+
This ensures that you don't accidentally commit changes to `V3/develop` branch directly. `V3/develop` branch should never be committed
174+
and pushed to directly, it should only ever be modified through Pull Requests.
175+
- [python-check-blanket-noqa](https://github.com/pre-commit/pygrep-hooks#provided-hooks):
176+
This checks that `noqa` annotations added to ignore errors from flake8 always specify specific codes to ignore.
177+
- [rst-directive-colons](https://github.com/pre-commit/pygrep-hooks#provided-hooks),
178+
[rst-inline-touching-normal](https://github.com/pre-commit/pygrep-hooks#provided-hooks):
179+
These check for two common issues with RST documents.
180+
- [codespell](https://github.com/codespell-project/codespell):
181+
This checks for common misspellings in text files.
182+
183+
When necessary, specific lines can be ignored with `.codespell-ignore-lines` file and specific words can be ignored with `.codespell-ignore-words` file.
184+
Usage of `.codespell-ignore-words` is generally discouraged.
98185
99186
### 4.4 Make
100187
You may have noticed we have a `Makefile` and a `make.bat` in the top-level directory. For now, you can do a few things with them:
101-
1. `make reformat`: Reformat all python files in the project with Black
102-
2. `make stylecheck`: Check if any `.py` files in the project need reformatting
188+
1. `make reformat`: Reformat all python files in the project with Black and isort
189+
2. `make stylecheck`: Check if any `.py` files in the project need reformatting with Black or isort
103190
3. `make newenv`: Set up a new virtual environment in the `.venv` subdirectory, and install Red and its dependencies. If one already exists, it is cleared out and replaced.
104191
4. `make syncenv`: Sync your environment with Red's latest dependencies.
105192

@@ -115,45 +202,23 @@ Whenever you pull from upstream (V3/develop on the main repository) and you noti
115202
1. Create a new branch on your fork
116203
2. Make the changes
117204
3. If you like the changes and think the main Red project could use it:
118-
* Run tests with `tox` to ensure your code is up to scratch
205+
* Run style checks with `pre-commit`.
206+
* (optional, advised if it's your first non-trivial PR to this project) Run tests with `tox` to ensure your code is up to scratch
119207
* Create a Pull Request on GitHub with your changes
120208
- If you are contributing a behavior change, please keep in mind that behavior changes
121209
are conditional on them being appropriate for the project's current goals.
122210
If you would like to reduce the risk of putting in effort for something we aren't
123211
going to use, open an issue discussing it first.
124212

125213
### 4.7 How To Report A Bug
126-
Please see our **ISSUES.MD** for more information.
214+
After checking that the bug has not already been reported by someone else on our issue tracker, you should create a new issue
215+
by choosing appropriate type of issue and **carefully** filling out the issue form. Please make sure that you include reproduction steps
216+
and describe the issue as precisely as you can.
127217

128218
### 4.8 How To Suggest A Feature Or Enhancement
129219
The goal of Red is to be as useful to as many people as possible, this means that all features must be useful to anyone and any server that uses Red.
130220

131221
If you find yourself wanting a feature that Red does not already have, you're probably not alone. There's bound to be a great number of users out there needing the same thing and a lot of the features that Red has today have been added because of the needs of our users. Open an issue on our issues list and describe the feature you would like to see, how you would use it, how it should work, and why it would be useful to the Red community as a whole.
132222

133-
# 5. Code Review Process
134-
135-
We have a core team working tirelessly to implement new features and fix bugs for the Red community. This core team looks at and evaluates new issues and PRs on a daily basis.
136-
137-
The decisions we make are based on a simple majority of that team or by decree of the project owner.
138-
139-
### 5.1 Issues
140-
Any new issues will be looked at and evaluated for validity of a bug or for the usefulness of a suggested feature. If we have questions about your issue we will get back as soon as we can (usually in a day or two) and will try to make a decision within a week.
141-
142-
### 5.2 Pull Requests
143-
Pull requests are evaluated by their quality and how effectively they solve their corresponding issue. The process for reviewing pull requests is as follows:
144-
145-
1. A pull request is submitted
146-
2. Core team members will review and test the pull request (usually within a week)
147-
3. After a member of the core team approves your pull request:
148-
* If your pull request is considered an improvement or enhancement the project owner will have 1 day to veto or approve your pull request.
149-
* If your pull request is considered a new feature the project owner will have 1 week to veto or approve your pull request.
150-
4. If any feedback is given we expect a response within 1 week or we may decide to close the PR.
151-
5. If your pull request is not vetoed and no core member requests changes then it will be approved and merged into the project.
152-
153-
### 5.3 Differences between "new features" and "improvements"
154-
The difference between a new feature and improvement can be quite fuzzy and the project owner reserves all rights to decide under which category your PR falls.
155-
156-
At a very basic level a PR is a new feature if it changes the intended way any part of the Red project currently works or if it modifies the user experience (UX) in any significant way. Otherwise, it is likely to be considered an improvement.
157-
158-
# 6. Community
223+
# 5. Community
159224
You can chat with the core team and other community members about issues or pull requests in the #coding channel of the Red support server located [here](https://discord.gg/red).

0 commit comments

Comments
 (0)