Skip to content

Commit 7ae7a37

Browse files
authored
Merge pull request #2393 from Textualize/contributing-improvements
Additions to CONTRIBUTING.md
2 parents 1b1ac5f + 3287371 commit 7ae7a37

File tree

2 files changed

+97
-69
lines changed

2 files changed

+97
-69
lines changed

CONTRIBUTING.md

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,54 @@ For new features or if there is any doubt in how to fix a bug, you might want
66
to open an issue prior to starting work, or email [email protected]
77
to discuss it first.
88

9-
## Development Environment
9+
## Prerequisites
1010

1111
Rich uses [poetry](https://python-poetry.org/docs/) for packaging and
1212
dependency management. To start developing with Rich, install Poetry
13-
using the [recommended method](https://python-poetry.org/docs/#installation) or run:
13+
using the [recommended method](https://python-poetry.org/docs/#installation).
14+
15+
Next, you'll need to create a _fork_ (your own personal copy) of the Rich repository, and clone that fork
16+
on to your local machine. GitHub offers a great tutorial for this process [here](https://docs.github.com/en/get-started/quickstart/fork-a-repo).
17+
After following this guide, you'll have a local copy of the Rich project installed.
18+
19+
Enter the directory containing your copy of Rich (`cd rich`).
20+
21+
Poetry can be used to create an isolated _virtual environment_ for the project:
1422

1523
```
16-
pip install poetry
24+
poetry shell
1725
```
1826

19-
Once Poetry is installed, install the dependencies with the following command:
27+
The first time we run `poetry shell`, such an isolated environment is created and forever associated with our project.
28+
Any time we wish to enter this virtual environment again, we simply run `poetry shell` again.
29+
30+
Now we can install the dependencies of Rich into the virtual environment:
2031

2132
```
2233
poetry install
2334
```
2435

36+
The rest of this guide assumes you're inside the virtual environment.
37+
If you're having difficulty running any of the commands that follow,
38+
ensure you're inside the virtual environment by running `poetry shell`.
39+
40+
## Developing
41+
42+
At this point, you're ready to start developing.
43+
Some things to consider while developing Rich code include:
44+
45+
* Ensure new code is documented in docstrings
46+
* Avoid abbreviations in variable or class names
47+
* Aim for consistency in coding style and API design
48+
49+
Before each [commit](https://github.com/git-guides/git-commit), you should:
50+
51+
1. Run the tests and ensure they pass
52+
2. Ensure type-checking passes
53+
3. Format the code using `black`
54+
55+
These steps are described in the following sections.
56+
2557
### Tests
2658

2759
Run tests with the following command:
@@ -38,6 +70,10 @@ pytest --cov-report term-missing --cov=rich tests/ -vv
3870

3971
New code should ideally have tests and not break existing tests.
4072

73+
The "Coverage Report" that gets printed to the terminal after the tests run can be used
74+
to identify lines of code that haven't been covered by tests.
75+
If any of the new lines you've added or modified appear in this report, you should strongly consider adding tests which exercise them.
76+
4177
### Type Checking
4278

4379
Rich uses type annotations throughout, and `mypy` to do the checking.
@@ -53,7 +89,7 @@ Or if you don't have `make`:
5389
mypy -p rich --config-file= --ignore-missing-imports --no-implicit-optional --warn-unreachable
5490
```
5591

56-
Please add type annotations for all new code.
92+
Please add type annotations for all new code, and ensure that type checking succeeds before creating a pull request.
5793

5894
### Code Formatting
5995

@@ -62,3 +98,57 @@ I recommend setting up black in your editor to format on save.
6298

6399
To run black from the command line, use `make format-check` to check your formatting,
64100
and use `make format` to format and write to the files.
101+
102+
### Consider Documentation
103+
104+
Consider whether the change you made would benefit from documentation - if the feature has any user impact at all, the answer is almost certainly yes!
105+
Documentation can be found in the `docs` directory.
106+
There are some additional dependencies required to build the documentation.
107+
These dependencies can be installed by running (from the `docs` directory):
108+
109+
```
110+
pip install -r requirements.txt
111+
```
112+
113+
After updating the documentation, you can build them (from the project root directory) by running:
114+
115+
```
116+
make docs
117+
```
118+
119+
This will generate the static HTML for the documentation site at `docs/build/html`.
120+
121+
### Update CHANGELOG and CONTRIBUTORS
122+
123+
Before submitting your pull request, update the `CHANGELOG.md` file describing, briefly, what you've done.
124+
Be sure to follow the format seen in the rest of the document.
125+
126+
If this is your first time contributing to Rich:
127+
128+
1. Welcome!
129+
2. Be sure to add your name to `CONTRIBUTORS.md`.
130+
131+
### Pre-Commit
132+
133+
We strongly recommend you [install the pre-commit hooks](https://pre-commit.com/#installation) included in the repository.
134+
These automatically run some of the checks described earlier each time you run `git commit`,
135+
and over time can reduce development overhead quite considerably.
136+
137+
## Creating A Pull Request
138+
139+
Once your happy with your change and have ensured that all steps above have been followed (and checks have passed), you can create a pull request.
140+
GitHub offers a guide on how to do this [here](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork).
141+
Please ensure that you include a good description of what your change does in your pull request, and link it to any relevant issues or discussions.
142+
143+
When you create your pull request, we'll run the checks described earlier. If they fail, please attempt to fix them as we're unlikely to be able to review your code until then.
144+
If you've exhausted all options on trying to fix a failing check, feel free to leave a note saying so in the pull request and someone may be able to offer assistance.
145+
146+
### Code Review
147+
148+
After the checks in your pull request pass, someone will review your code.
149+
There may be some discussion and, in most cases, a few iterations will be required to find a solution that works best.
150+
151+
## Afterwards
152+
153+
When the pull request is approved, it will be merged into the `master` branch.
154+
Your change will only be available to users the next time Rich is released.

0 commit comments

Comments
 (0)