Skip to content

Commit dd92f6c

Browse files
committed
πŸ“ style guide
1 parent d187962 commit dd92f6c

6 files changed

Lines changed: 304 additions & 250 deletions

File tree

β€ŽCONTRIBUTING.mdβ€Ž

Lines changed: 2 additions & 236 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
44
you're new to open source or experienced, your contributions help us
55
grow.
66

@@ -10,240 +10,6 @@ the process forward. Please follow our [Code of
1010
Conduct](https://numpy.org/code-of-conduct/), which applies to all
1111
interactions, 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

1515
Thank 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-->

β€Ždocs/.nav.ymlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ flatten_single_child_sections: true
33
nav:
44
- User Guide: user
55
- API Reference: reference.md
6-
- Development: contributing.md
6+
- Development: dev

β€Ždocs/contributing.mdβ€Ž

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
Β (0)