Skip to content

Commit 562729f

Browse files
committed
Don't install stubs automatically with mypy
When installing stubs automatically with `mypy` we can't pin the dependencies, and we make it harder to just run `mypy` without going through `nox`. From now on, dependencies must be explicitly declared in the `pyproject.toml` file, in the optional `dev-mypy` dependencies. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 4aee2fc commit 562729f

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

cookiecutter/{{cookiecutter.github_repo_name}}/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ dev-mkdocs = [
7979
]
8080
dev-mypy = [
8181
"mypy == 1.5.1",
82+
{%- if cookiecutter.type == "api" %}
83+
"grpc-stubs == 1.53.0.2",
84+
{%- endif %}
8285
# For checking the noxfile, docs/ script, and tests
8386
"{{cookiecutter.pypi_package_name}}[dev-mkdocs,dev-noxfile,dev-pytest]",
8487
]

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ dev-mkdocs = [
7979
]
8080
dev-mypy = [
8181
"mypy == 1.5.1",
82-
"types-setuptools >= 67.6.0, < 68", # Should match the global dependency
82+
"types-setuptools == 68.1.0.0", # Should match the build dependency
83+
"types-Markdown == 3.4.2.10",
84+
"types-PyYAML == 6.0.12.11",
85+
"types-babel == 2.11.0.15",
86+
"types-colorama == 0.4.15.12",
8387
# For checking the noxfile, docs/ script, and tests
8488
"frequenz-repo-config[dev-mkdocs,dev-noxfile,dev-pytest]",
8589
]

src/frequenz/repo/config/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,23 @@
189189
You can just call `mypy` to check the package of your sources or you can use `mypy
190190
tests` to check the tests, for example.
191191
192+
You might also need to extra optional dependencies to install type checking stubs for
193+
some packages. For example for API projects you need the `grpc-stubs` package:
194+
195+
```toml
196+
[project.optional-dependencies]
197+
# ...
198+
dev-mypy = [
199+
# ...
200+
"grpc-stubs == 1.53.0.2",
201+
# ...
202+
]
203+
```
204+
205+
You can use `mypy --install-types` to install to get a list of missing stubs, `mypy`
206+
will list them for you and ask if you want to proceed with the installation. You can
207+
answer no and copy the list of missing stubs to the `pyproject.toml` file.
208+
192209
## `mkdocs` (generating documentation)
193210
194211
### API reference generation

src/frequenz/repo/config/nox/default.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@
3535
"--diff",
3636
"--check",
3737
],
38-
mypy=[
39-
"--install-types",
40-
"--non-interactive",
41-
],
38+
mypy=[],
4239
pytest=[
4340
"-W=all",
4441
"-vv",

tests_golden/integration/test_cookiecutter_generation/api/frequenz-api-test/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ dev-mkdocs = [
5959
]
6060
dev-mypy = [
6161
"mypy == 1.5.1",
62+
"grpc-stubs == 1.53.0.2",
6263
# For checking the noxfile, docs/ script, and tests
6364
"frequenz-api-test[dev-mkdocs,dev-noxfile,dev-pytest]",
6465
]

0 commit comments

Comments
 (0)