Skip to content

Commit 7b9625d

Browse files
committed
Move options to pyproject.toml
It is possible to define most options within the `pyproject.toml` file, which offers several advantages: the tool can be used from the command line directly (bypassing the need for `nox`), without having to remember the options. It also facilitates other integrations that need to invoke mypy directly. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent e36434b commit 7b9625d

File tree

9 files changed

+53
-3
lines changed

9 files changed

+53
-3
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ required_plugins = ["pytest-asyncio", "pytest-mock"]
169169
{%- else %}
170170
testpaths = ["pytests"]
171171
{%- endif %}
172+
173+
[tool.mypy]
174+
explicit_package_bases = true
175+
namespace_packages = true
176+
strict = true
172177
{%- if cookiecutter.type != "api" %}
173178

174179
[[tool.mypy.overrides]]

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ disable = [
153153
"unnecessary-lambda-assignment",
154154
]
155155

156+
[tool.mypy]
157+
explicit_package_bases = true
158+
namespace_packages = true
159+
strict = true
160+
156161
[[tool.mypy.overrides]]
157162
module = ["cookiecutter", "cookiecutter.*", "sybil", "sybil.*"]
158163
ignore_missing_imports = true

src/frequenz/repo/config/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
nox.configure(config)
5353
```
5454
55+
!!! note
56+
57+
When possible, it is recommended to define options in the `pyproject.toml` file
58+
(most tools can do this), so they can be consistently used even if the tool is used
59+
outside of `nox`.
60+
5561
If you need further customization or to define new sessions, you can use the
5662
following modules:
5763
@@ -167,6 +173,18 @@
167173
]
168174
```
169175
176+
## `mypy` (static type checking)
177+
178+
To configure `mypy` you can add the recommended options to the `pyproject.toml` file as
179+
follows:
180+
181+
```toml
182+
[tool.mypy]
183+
explicit_package_bases = true
184+
namespace_packages = true
185+
strict = true
186+
```
187+
170188
## `mkdocs` (generating documentation)
171189
172190
### API reference generation

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@
3737
],
3838
mypy=[
3939
"--install-types",
40-
"--namespace-packages",
4140
"--non-interactive",
42-
"--explicit-package-bases",
43-
"--strict",
4441
],
4542
# SDK: pylint "--extension-pkg-whitelist=pydantic"
4643
pytest=[

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ testpaths = ["tests", "src"]
143143
asyncio_mode = "auto"
144144
required_plugins = ["pytest-asyncio", "pytest-mock"]
145145

146+
[tool.mypy]
147+
explicit_package_bases = true
148+
namespace_packages = true
149+
strict = true
150+
146151
[[tool.mypy.overrides]]
147152
module = ["async_solipsism", "async_solipsism.*", "sybil", "sybil.*"]
148153
ignore_missing_imports = true

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ disable = [
135135
[tool.pytest.ini_options]
136136
testpaths = ["pytests"]
137137

138+
[tool.mypy]
139+
explicit_package_bases = true
140+
namespace_packages = true
141+
strict = true
142+
138143
[tool.setuptools.package-dir]
139144
"" = "py"
140145

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ testpaths = ["tests", "src"]
142142
asyncio_mode = "auto"
143143
required_plugins = ["pytest-asyncio", "pytest-mock"]
144144

145+
[tool.mypy]
146+
explicit_package_bases = true
147+
namespace_packages = true
148+
strict = true
149+
145150
[[tool.mypy.overrides]]
146151
module = ["async_solipsism", "async_solipsism.*", "sybil", "sybil.*"]
147152
ignore_missing_imports = true

tests_golden/integration/test_cookiecutter_generation/lib/frequenz-test-python/pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ testpaths = ["tests", "src"]
139139
asyncio_mode = "auto"
140140
required_plugins = ["pytest-asyncio", "pytest-mock"]
141141

142+
[tool.mypy]
143+
explicit_package_bases = true
144+
namespace_packages = true
145+
strict = true
146+
142147
[[tool.mypy.overrides]]
143148
module = ["async_solipsism", "async_solipsism.*", "sybil", "sybil.*"]
144149
ignore_missing_imports = true

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ testpaths = ["tests", "src"]
143143
asyncio_mode = "auto"
144144
required_plugins = ["pytest-asyncio", "pytest-mock"]
145145

146+
[tool.mypy]
147+
explicit_package_bases = true
148+
namespace_packages = true
149+
strict = true
150+
146151
[[tool.mypy.overrides]]
147152
module = ["async_solipsism", "async_solipsism.*", "sybil", "sybil.*"]
148153
ignore_missing_imports = true

0 commit comments

Comments
 (0)