11# NumType's Contributing guidelines
22
3- Welcome to the NumPy community! We're excited to have you here. Whether
3+ Welcome to the NumType community! We're excited to have you here. Whether
44you're new to open source or experienced, your contributions help us
55grow.
66
@@ -10,240 +10,6 @@ the process forward. Please follow our [Code of
1010Conduct] ( https://numpy.org/code-of-conduct/ ) , which applies to all
1111interactions, including issues and PRs.
1212
13- For more, please read < https://www. numpy.org/devdocs /dev/index.html >
13+ For more, please read < https://numpy.org/numtype /dev/ >
1414
1515Thank you for contributing, and happy coding!
16-
17- ______________________________________________________________________
18-
19- <!-- overview-start-->
20-
21- ## Setting up the environment
22-
23- Ensure you have [ ` uv ` ] ( https://docs.astral.sh/uv/getting-started/installation/ )
24- installed. Now you can install the project with the dev dependencies:
25-
26- ``` shell
27- uv sync
28- ```
29-
30- You can also install it with a specific Python version, e.g. ` 3.10 ` , as
31-
32- ``` shell
33- uv sync --python 3.10
34- ```
35-
36- ## Linting and formatting with ` ruff `
37-
38- NumType uses ` ruff ` for linting and formatting, and is automatically installed
39- as a local development dependency. This way, you can lint all ` .py ` and ` .pyi `
40- files with:
41-
42- ``` bash
43- $ uv run ruff check
44- All checks passed!
45- ```
46-
47- Or, to format your code, run
48-
49- ``` bash
50- $ uv run ruff format
51- 351 files left unchanged
52- ```
53-
54- Be sure to do this before you open a pull request β the CI will complain
55- if you don't.
56-
57- For more details, see < https://docs.astral.sh/ruff/ > .
58-
59- ## Type-checking and Testing
60-
61- To validate that the annotations are correct and run tests, we use several tools:
62- [ basedpyright] , [ mypy] , and [ pytest] . All are included as development
63- dependency-group, so that ` uv sync ` will install them by default.
64-
65- ### basedpyright
66-
67- You can run basedpyright on the entire project using:
68-
69- ``` bash
70- $ uv run basedpyright
71- 0 errors, 0 warnings, 0 notes
72- ```
73-
74- Since this can take somewhere between 20 to 50 seconds to run, you may want to
75- limit this to a subdirectory or a specific file that you're working on.
76-
77- See < https://docs.basedpyright.com/ > for IDE integration and other info.
78-
79- ### mypy
80-
81- Mypy is used for type-checking the codebase and the type-tests. It takes more effort to run it on the codebase than ` basedpyright ` .
82- This is primarily a consequence of mypy's inconsequent prioritization of the stubs bundled
83- with NumPy over the ` numpy-stubs ` within a local development environment.
84- To get around this, you can delete all ` *.pyi ` from your ** local** ` numpy ` installation directory by running ` uv tool/unstub.py ` .
85-
86- ** General Type Checking**
87-
88- To run mypy generally (excluding the main numpy dependency group):
89-
90- ``` shell
91- uv run --no-editable --no-group=numpy mypy .
92- ```
93-
94- ** Cache Issues**
95-
96- In rare cases, the cache (` .mypy_cache ` in the ` numtype ` root) can get corrupted,
97- leading to incorrect results. If CI output differs from your local output, delete
98- this directory.
99-
100- The documentation can be found at < https://mypy.readthedocs.io/ > , and issues can
101- be reported at < https://github.com/python/mypy > .
102-
103- ### pytest
104-
105- Pytest runs runtime tests located in ` src/*/@test ` . It works out-of-the-box:
106-
107- ``` bash
108- uv run pytest [OPTIONS]
109- ```
110-
111- For available options, see the [ pytest documentation] ( https://docs.pytest.org/en/stable/how-to/usage.html#args-from-file ) .
112-
113- ## Lefthook
114-
115- [ Lefthook] is a modern Git hooks manager, which automatically lints and formats
116- your code before you committing it. It will also keep your ` uv ` environment
117- up-to-date with the lockfile when you ` git pull ` .
118-
119- To install it as a ` uv ` tool, run
120-
121- ``` shell
122- uv tool install lefthook --upgrade
123- ```
124-
125- To set it up, navigate to the root of the ` numtype ` repo, and run
126-
127- ``` shell
128- lefthook install
129- ```
130-
131- or
132-
133- ``` shell
134- uvx lefthook install
135- ```
136-
137- Now let's see it all works:
138-
139- ``` bash
140- $ lefthook validate
141- All good
142- ```
143-
144- See < https://lefthook.dev/ > for more information.
145-
146- ## Tox
147-
148- You can run the linters, type-checkers, runtime tests, and ` stubtest ` , all at
149- once through a single [ tox] command.
150-
151- It's easiest to install it as a ` uv ` tool:
152-
153- ``` shell
154- uv tool install tox --with tox-uv --upgrade
155- ```
156-
157- To run it, navigate to the root of the cloned ` numtype ` directory, and run
158-
159- ``` shell
160- tox p
161- ```
162-
163- or alternatively,
164-
165- ``` shell
166- uvx tox p
167- ```
168-
169- If all is good, then you should see something like this appear:
170-
171- ``` plaintext
172- ruff: OK β in 0.05 seconds
173- pytest: OK β in 0.34 seconds
174- 3.11: OK β in 20.44 seconds
175- 3.10: OK β in 21.53 seconds
176- 3.12: OK β in 22.32 seconds
177- 3.13: OK β in 26.41 seconds
178- basedpyright: OK β in 27.33 seconds
179- ruff: OK (0.05=setup[0.03]+cmd[0.01,0.01] seconds)
180- pytest: OK (0.34=setup[0.02]+cmd[0.32] seconds)
181- basedpyright: OK (27.33=setup[0.02]+cmd[27.31] seconds)
182- mypy: OK (36.39=setup[0.02]+cmd[36.37] seconds)
183- 3.10: OK (21.53=setup[0.43]+cmd[21.10] seconds)
184- 3.11: OK (20.44=setup[0.42]+cmd[20.01] seconds)
185- 3.12: OK (22.32=setup[0.44]+cmd[21.88] seconds)
186- 3.13: OK (26.41=setup[0.48]+cmd[25.93] seconds)
187- congratulations :) (36.44 seconds)
188- ```
189-
190- Tox installs everything in isolated environments, so you don't have to worry
191- about your local or global ` pip ` or ` uv ` environments.
192-
193- See < https://tox.wiki/en/stable/ > for more information.
194-
195- ## Documentation
196-
197- The documentation lives in ` docs/ ` , the ` README.md ` , and ` CONTRIBUTING.md ` .
198- Please read it carefully before proposing any changes.
199- Ensure that the markdown is formatted correctly with [ markdownlint] .
200-
201- ### Previewing Documentation Site
202-
203- NumType uses [ MkDocs] for documentation static site generation. To preview the documentation site locally:
204-
205- ``` shell
206- uv run mkdocs serve
207- ```
208-
209- This will start a local server at < http://127.0.0.1:8000/numtype/ > where you can preview your changes.
210- The server automatically refreshes when you make changes to the documentation files.
211-
212- ## Development Tools
213-
214- NumType provides several development tools to help with development.
215-
216- For detailed usage of each tool, please refer to the ` README.md `
217- in the [ ` tool ` ] [ tool-docs ] directory or the docstrings within each tool.
218-
219- ## Commit message style
220-
221- For the most part, commit messages in NumType should follow
222- [ NumPy's guidelines for writing commit messages] [ numpy-commit-style ] .
223- The main difference is that we don't use the prefix acronyms (e.g. ` TYP ` ).
224- Instead, we use [ Gitmoji] as a modern alternative.
225- Using it gitmoji is not a hard requirement, just a colorful recommendation.
226- For VSCode users it's most convenient to use the
227- [ ` gitmoji-vscode ` extension] ( https://github.com/seatonjiang/gitmoji-vscode ) .
228-
229- ## Code style
230-
231- For ` .py ` files, NumType follows the ` black ` style, and the ` .pyi ` stubs follow
232- the official [ style guide for stubs] [ stub-style ] .
233- Both ` .py ` and ` .pyi ` are linted and formatted using [ ` ruff ` ] [ ruff ] , which is
234- one of the development dependencies.
235-
236- [ basedpyright ] : https://github.com/detachhead/basedpyright
237- [ gitmoji ] : https://gitmoji.dev/
238- [ lefthook ] : https://lefthook.dev/
239- [ markdownlint ] : https://github.com/DavidAnson/markdownlint/tree/main
240- [ mkdocs ] : https://www.mkdocs.org/
241- [ mypy ] : https://github.com/python/mypy
242- [ numpy-commit-style ] : https://numpy.org/devdocs/dev/development_workflow.html#writing-the-commit-message
243- [ pytest ] : https://docs.pytest.org/en/latest/
244- [ ruff ] : https://docs.astral.sh/ruff/
245- [ stub-style ] : https://typing.python.org/en/latest/guides/writing_stubs.html#style-guide
246- [ tool-docs ] : https://github.com/numpy/numtype/tree/main/tool
247- [ tox ] : https://github.com/tox-dev/tox
248-
249- <!-- overview-end-->
0 commit comments