Debian Codegraph @

CONTRIBUTING.md

raw
1 # Contributing to Rich
2
3 This project welcomes contributions in the form of Pull Requests.
4 For clear bug-fixes / typos etc. just submit a PR.
5 For new features or if there is any doubt in how to fix a bug, you might want
6 to open an issue prior to starting work, or email [email protected]
7 to discuss it first.
8
9 See also [AI_POLICY.md](https://github.com/Textualize/rich/blob/master/AI_POLICY.md) if you will be using AI.
10
11 ## Prerequisites
12
13 Rich uses [poetry](https://python-poetry.org/docs/) for packaging and
14 dependency management. To start developing with Rich, install Poetry
15 using the [recommended method](https://python-poetry.org/docs/#installation).
16
17 Next, you'll need to create a _fork_ (your own personal copy) of the Rich repository, and clone that fork
18 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).
19 After following this guide, you'll have a local copy of the Rich project installed.
20
21 Enter the directory containing your copy of Rich (`cd rich`).
22
23 Next create and activate a [virtual environment](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#create-and-use-virtual-environments) for Rich.
24
25 Now we can install the dependencies of Rich into the virtual environment:
26
27 ```
28 poetry install
29 ```
30
31 The rest of this guide assumes you're inside the virtual environment.
32 If you're having difficulty running any of the commands that follow,
33 ensure you're inside the virtual environment by running `poetry shell`.
34
35 ## Developing
36
37 At this point, you're ready to start developing.
38 Some things to consider while developing Rich code include:
39
40 * Ensure new code is documented in docstrings
41 * Avoid abbreviations in variable or class names
42 * Aim for consistency in coding style and API design
43
44 Before each [commit](https://github.com/git-guides/git-commit), you should:
45
46 1. Run the tests and ensure they pass
47 2. Ensure type-checking passes
48 3. Format the code using `black`
49
50 These steps are described in the following sections.
51
52 ### Tests
53
54 Run tests with the following command:
55
56 ```
57 make test
58 ```
59
60 Or if you don't have `make`, run the following:
61
62 ```
63 pytest --cov-report term-missing --cov=rich tests/ -vv
64 ```
65
66 New code should ideally have tests and not break existing tests.
67
68 The "Coverage Report" that gets printed to the terminal after the tests run can be used
69 to identify lines of code that haven't been covered by tests.
70 If any of the new lines you've added or modified appear in this report, you should strongly consider adding tests which exercise them.
71
72 ### Type Checking
73
74 Rich uses type annotations throughout, and `mypy` to do the checking.
75 Run the following to type check Rich:
76
77 ```
78 make typecheck
79 ```
80
81 Or if you don't have `make`:
82
83 ```
84 mypy -p rich --config-file= --ignore-missing-imports --no-implicit-optional --warn-unreachable
85 ```
86
87 Please add type annotations for all new code, and ensure that type checking succeeds before creating a pull request.
88
89 ### Code Formatting
90
91 Rich uses [`black`](https://github.com/psf/black) for code formatting.
92 I recommend setting up black in your editor to format on save.
93
94 To run black from the command line, use `make format-check` to check your formatting,
95 and use `make format` to format and write to the files.
96
97 ### Consider Documentation
98
99 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!
100 Documentation can be found in the `docs` directory.
101 There are some additional dependencies required to build the documentation.
102 These dependencies can be installed by running (from the `docs` directory):
103
104 ```
105 pip install -r requirements.txt
106 ```
107
108 After updating the documentation, you can build them (from the project root directory) by running:
109
110 ```
111 make docs
112 ```
113
114 This will generate the static HTML for the documentation site at `docs/build/html`.
115
116 ### Update CHANGELOG and CONTRIBUTORS
117
118 Before submitting your pull request, update the `CHANGELOG.md` file describing, briefly, what you've done.
119 Be sure to follow the format seen in the rest of the document.
120
121 If this is your first time contributing to Rich:
122
123 1. Welcome!
124 2. Be sure to add your name to `CONTRIBUTORS.md`.
125
126 ### Pre-Commit
127
128 We strongly recommend you [install the pre-commit hooks](https://pre-commit.com/#installation) included in the repository.
129 These automatically run some of the checks described earlier each time you run `git commit`,
130 and over time can reduce development overhead quite considerably.
131
132 ## Creating A Pull Request
133
134 Once you're happy with your change and have ensured that all steps above have been followed (and checks have passed), you can create a pull request.
135 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).
136 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.
137
138 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.
139 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.
140
141 ### Code Review
142
143 After the checks in your pull request pass, someone will review your code.
144 There may be some discussion and, in most cases, a few iterations will be required to find a solution that works best.
145
146 ## Afterwards
147
148 When the pull request is approved, it will be merged into the `master` branch.
149 Your change will only be available to users the next time Rich is released.