Skip to content

Commit dd2313a

Browse files
authored
[red-knot] Add mypy_primer usage documentation (#16679)
## Summary Add documentation on how to run mypy_primer locally.
1 parent 057e497 commit dd2313a

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

crates/red_knot/docs/mypy_primer.md

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Running `mypy_primer`
2+
3+
## Basics
4+
5+
For now, we use our own [fork of mypy primer]. It can be run using `uvx --from "…" mypy_primer`. For example, to see the help message, run:
6+
7+
```sh
8+
uvx --from "git+https://github.com/astral-sh/mypy_primer.git@add-red-knot-support" mypy_primer -h
9+
```
10+
11+
Alternatively, you can install the forked version of `mypy_primer` using:
12+
13+
```sh
14+
uv tool install "git+https://github.com/astral-sh/mypy_primer.git@add-red-knot-support"
15+
```
16+
17+
and then run it using `uvx mypy_primer` or just `mypy_primer`, if your `PATH` is set up accordingly (see: [Tool executables]).
18+
19+
## Showing the diagnostics diff between two Git revisions
20+
21+
To show the diagnostics diff between two Git revisions (e.g. your feature branch and `main`), run:
22+
23+
```sh
24+
mypy_primer \
25+
--type-checker knot \
26+
--old origin/main \
27+
--new my/feature \
28+
--debug \
29+
--output concise \
30+
--project-selector '/black$'
31+
```
32+
33+
This will show the diagnostics diff for the `black` project between the `main` branch and your `my/feature` branch. To run the
34+
diff for all projects, you currently need to copy the project-selector regex from the CI pipeline in `.github/workflows/mypy_primer.yaml`.
35+
36+
You can also take a look at the [full list of ecosystem projects]. Note that some of them might still need a `knot_paths` configuration
37+
option to work correctly.
38+
39+
## Avoiding recompilation
40+
41+
If you want to run `mypy_primer` repeatedly, e.g. for different projects, but for the same combination of `--old` and `--new`, you
42+
can use set the `MYPY_PRIMER_NO_REBUILD` environment variable to avoid recompilation of Red Knot:
43+
44+
```sh
45+
MYPY_PRIMER_NO_REBUILD=1 mypy_primer …
46+
```
47+
48+
## Running from a local copy of the repository
49+
50+
If you are working on a local branch, you can use `mypy_primer`'s `--repo` option to specify the path to your local copy of the `ruff` repository.
51+
This allows `mypy_primer` to check out local branches:
52+
53+
```sh
54+
mypy_primer --repo /path/to/ruff --old origin/main --new my/local-branch …
55+
```
56+
57+
Note that you might need to clean up `/tmp/mypy_primer` in order for this to work correctly.
58+
59+
[fork of mypy primer]: https://github.com/astral-sh/mypy_primer/tree/add-red-knot-support
60+
[full list of ecosystem projects]: https://github.com/astral-sh/mypy_primer/blob/add-red-knot-support/mypy_primer/projects.py
61+
[tool executables]: https://docs.astral.sh/uv/concepts/tools/#tool-executables

0 commit comments

Comments
 (0)