Skip to content

Commit ab3f887

Browse files
Add justfile and update CONTRIBUTING.md (#3240)
* Add justfile and update CONTRIBUTING.md * Address PR review comments - Reorder bootstrap: run uv sync before pre-commit install - Add ext-test to pre-mr-check dependencies - Default test args to 'tests' so `just test path/to/file` overrides it - Remove unnecessary -- separator in CONTRIBUTING.md examples * PR feedback * Smart test receipe
1 parent 8776a74 commit ab3f887

File tree

2 files changed

+132
-16
lines changed

2 files changed

+132
-16
lines changed

CONTRIBUTING.md

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,46 +38,89 @@ To do so follow this [official github guide](https://docs.github.com/en/free-pro
3838
We use [uv](https://github.com/astral-sh/uv) to manage our dev dependencies.
3939
To install it, see their [installation guide](https://docs.astral.sh/uv/getting-started/installation/)
4040

41-
Once it's done, simply run the following command to automatically setup a virtual environment and install dev dependencies:
41+
We use [just](https://github.com/casey/just) as a command runner. Install it with:
4242

4343
```bash
44-
uv sync
45-
source .venv/bin/activate
44+
uv tool install rust-just
4645
```
4746

48-
Finally, install the pre-commit hooks:
47+
Then bootstrap your environment (installs pre-commit hooks and syncs dependencies):
4948

5049
```bash
51-
pre-commit install
50+
just bootstrap
51+
```
52+
53+
<details>
54+
<summary>Manual setup (without <code>just</code>)</summary>
55+
56+
```bash
57+
uv sync
58+
source .venv/bin/activate
59+
pre-commit install --install-hooks
5260
```
61+
</details>
5362

5463
### Testing and Linting
5564

56-
We use `mypy`, `pytest`, `ruff`, and `black` for quality control. `ruff` and `black` are executed using pre-commit when you make a commit.
57-
To ensure there are not formatting or typing issues in the entire repository you can run:
65+
Running `just` at the root of the repository lists all available recipes:
5866

59-
```bash
60-
pre-commit run --all-files
67+
```
68+
$ just
69+
Available recipes:
70+
[dev]
71+
bootstrap # Bootstrap dev environment: install pre-commit hooks and sync dependencies
72+
lint # Run pre-commit hooks on all files
73+
pre-mr-check # Run all checks before submitting a PR
74+
clean # Remove mypy cache
75+
76+
[typecheck]
77+
mypy # Run mypy on plugin, ext, scripts, stubs and tests
78+
pyright # Run pyright on test cases
79+
pyrefly # Run pyrefly on test cases
80+
ty # Run ty on test cases
81+
82+
[test]
83+
test +args # Run pytest on specific files or with custom args (no xdist)
84+
all-test # Run full pytest test suite with parallel workers
85+
stubtest *args # Run stubtest to check stubs match runtime
86+
ext-test # Run django-stubs-ext tests
87+
88+
[build]
89+
build # Build all packages
90+
lock-check # Check that uv.lock is up to date
6191
```
6292

63-
NOTE: This command will not only lint but also modify files - so make sure to commit whatever changes you've made before hand.
64-
You can also run pre-commit per file or for a specific path, simply replace "--all-files" with a target (see [this guide](https://codeburst.io/tool-your-django-project-pre-commit-hooks-e1799d84551f) for more info).
93+
Before submitting a PR, run all checks at once:
6594

66-
To execute the unit tests, simply run:
95+
```bash
96+
just pre-mr-check
97+
```
98+
99+
Or run individual checks:
67100

68101
```bash
69-
pytest -n auto
102+
just lint # pre-commit hooks (ruff, codespell, ...)
103+
just mypy # mypy on plugin, ext, scripts, stubs and tests
104+
just test tests/test_xyz.yml # run specific tests (no xdist)
105+
just all-test # full pytest suite (parallel)
106+
just stubtest # stubtest: check stubs match runtime
107+
just pyright # pyright on test cases
108+
just ty # ty on test cases
109+
just pyrefly # pyrefly on test cases
70110
```
71111

72-
If you get some unexpected results or want to be sure that tests run is not affected by previous one, remove `mypy` cache:
112+
Extra arguments can be passed to `test` and `stubtest`:
73113

74114
```bash
75-
rm -r .mypy_cache
115+
just test tests -k test_name
116+
just stubtest --allowlist extra.txt
76117
```
77118

119+
If you get unexpected results, clear the mypy cache with `just clean`.
120+
78121
### Testing stubs with `stubtest`
79122

80-
Run [`./scripts/stubtest.sh`](scripts/stubtest.sh) to test that stubs and sources are in-line.
123+
Run `just stubtest` (or [`./scripts/stubtest.sh`](scripts/stubtest.sh) directly) to test that stubs and sources are in-line.
81124

82125
We have some special files to allow errors:
83126

justfile

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# List all available recipes
2+
_default:
3+
@just --list --unsorted
4+
5+
# Bootstrap dev environment: install pre-commit hooks and sync dependencies
6+
[group('dev')]
7+
bootstrap:
8+
uv tool install pre-commit
9+
uv sync
10+
pre-commit install --install-hooks
11+
12+
# Run pre-commit hooks on all files
13+
[group('dev')]
14+
lint:
15+
pre-commit run --all-files
16+
17+
# Run all checks before submitting a PR
18+
[group('dev')]
19+
pre-mr-check: lint ty pyrefly mypy stubtest pyright ext-test test
20+
21+
# Remove mypy cache
22+
[group('dev')]
23+
clean:
24+
rm -rf .mypy_cache
25+
26+
# Run mypy on plugin, ext, scripts, stubs and tests
27+
[group('typecheck')]
28+
mypy:
29+
uv run mypy --strict ext
30+
uv run mypy --strict scripts
31+
uv run mypy --strict mypy_django_plugin
32+
uv run mypy --cache-dir=/dev/null --no-incremental django-stubs
33+
uv run mypy --strict tests
34+
35+
# Run pyright on test cases
36+
[group('typecheck')]
37+
pyright:
38+
uv run pyright -p pyrightconfig.testcases.json
39+
40+
# Run pyrefly on test cases
41+
[group('typecheck')]
42+
pyrefly:
43+
uv run pyrefly check tests/assert_type
44+
45+
# Run ty on test cases
46+
[group('typecheck')]
47+
ty:
48+
uv run ty check tests/assert_type
49+
50+
# Run pytest tests
51+
[group('test')]
52+
test +args="-n auto tests":
53+
uv run pytest {{ args }}
54+
55+
# Run stubtest to check stubs match runtime
56+
[group('test')]
57+
stubtest *args:
58+
uv run ./scripts/stubtest.sh {{ args }}
59+
60+
# Run django-stubs-ext tests
61+
[group('test')]
62+
ext-test:
63+
uv run pytest ext
64+
65+
# Build all packages
66+
[group('build')]
67+
build:
68+
uv build --all-packages
69+
70+
# Check that uv.lock is up to date
71+
[group('build')]
72+
lock-check:
73+
uv lock --check

0 commit comments

Comments
 (0)