Skip to content

Commit 8fa9e60

Browse files
committed
Move mypy configuration to pyproject.toml from setup.cfg
1 parent 0b9d654 commit 8fa9e60

File tree

6 files changed

+260
-36
lines changed

6 files changed

+260
-36
lines changed

plugins/ext_test/pyproject.toml

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
[build-system]
2+
requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"]
3+
4+
[tool.mypy]
5+
disallow_incomplete_defs = true
6+
disallow_untyped_calls = true
7+
disallow_untyped_defs = true
8+
exclude = [
9+
"^examples/", # examples directory
10+
"^noxfile\\.py$", # nox config file
11+
"setup\\.py$", # any files named setup.py
12+
"^tasks\\.py$", # tasks.py invoke config file
13+
"^tests/", # tests directory
14+
]
15+
show_column_numbers = true
16+
show_error_codes = true
17+
show_error_context = true
18+
strict = true
19+
warn_redundant_casts = true
20+
warn_return_any = true
21+
warn_unreachable = true
22+
warn_unused_ignores = false
23+
24+
[tool.ruff]
25+
# Exclude a variety of commonly ignored directories.
26+
exclude = [
27+
".bzr",
28+
".direnv",
29+
".eggs",
30+
".git",
31+
".git-rewrite",
32+
".hg",
33+
".ipynb_checkpoints",
34+
".mypy_cache",
35+
".nox",
36+
".pants.d",
37+
".pyenv",
38+
".pytest_cache",
39+
".pytype",
40+
".ruff_cache",
41+
".svn",
42+
".tox",
43+
".venv",
44+
".vscode",
45+
"__pypackages__",
46+
"_build",
47+
"buck-out",
48+
"build",
49+
"dist",
50+
"node_modules",
51+
"site-packages",
52+
"venv",
53+
]
54+
55+
# Same as Black.
56+
line-length = 127
57+
indent-width = 4
58+
59+
# Assume Python 3.13
60+
target-version = "py313"
61+
output-format = "full"
62+
63+
[tool.ruff.lint]
64+
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
65+
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
66+
# McCabe complexity (`C901`) by default.
67+
select = [
68+
# https://beta.ruff.rs/docs/rules
69+
# "A", # flake8-builtins
70+
# "ANN", # flake8-annotations
71+
# "ARG", # flake8-unused-arguments
72+
"ASYNC", # flake8-async
73+
# "B", # flake8-bugbear
74+
# "BLE", # flake8-blind-except
75+
# "C4", # flake8-comprehensions
76+
"C90", # McCabe cyclomatic complexity
77+
# "COM", # flake8-commas
78+
# "D", # pydocstyle
79+
"DJ", # flake8-django
80+
# "DTZ", # flake8-datetimez
81+
"E", # pycodestyle
82+
# "EM", # flake8-errmsg
83+
# "ERA", # eradicate
84+
# "EXE", # flake8-executable
85+
"F", # Pyflakes
86+
"FA", # flake8-future-annotations
87+
# "FBT", # flake8-boolean-trap
88+
"G", # flake8-logging-format
89+
# "I", # isort
90+
"ICN", # flake8-import-conventions
91+
# "INP", # flake8-no-pep420
92+
"INT", # flake8-gettext
93+
# "ISC", # flake8-implicit-str-concat
94+
# "N", # pep8-naming
95+
"NPY", # NumPy-specific rules
96+
"PD", # pandas-vet
97+
# "PGH", # pygrep-hooks
98+
# "PIE", # flake8-pie
99+
# "PL", # Pylint
100+
# "PT", # flake8-pytest-style
101+
# "PTH", # flake8-use-pathlib
102+
# "PYI", # flake8-pyi
103+
# "RET", # flake8-return
104+
"RSE", # flake8-raise
105+
# "Q", # flake8-quotes
106+
# "RUF", # Ruff-specific rules
107+
# "S", # flake8-bandit
108+
# "SIM", # flake8-simplify
109+
# "SLF", # flake8-self
110+
# "T10", # flake8-debugger
111+
# "T20", # flake8-print
112+
# "TCH", # flake8-type-checking
113+
# "TD", # flake8-todos
114+
# "TID", # flake8-tidy-imports
115+
# "TRY", # tryceratops
116+
# "UP", # pyupgrade
117+
# "W", # pycodestyle
118+
# "YTT", # flake8-2020
119+
]
120+
ignore = [
121+
# `ruff rule S101` for a description of that rule
122+
"B904", # Within an `except` clause, raise exceptions with `raise ... from err` -- FIX ME
123+
"B905", # `zip()` without an explicit `strict=` parameter -- FIX ME
124+
"E501", # Line too long
125+
"EM101", # Exception must not use a string literal, assign to variable first
126+
"EXE001", # Shebang is present but file is not executable -- DO NOT FIX
127+
"G004", # Logging statement uses f-string
128+
"PLC1901", # `{}` can be simplified to `{}` as an empty string is falsey
129+
"PLW060", # Using global for `{name}` but no assignment is done -- DO NOT FIX
130+
"PLW2901", # PLW2901: Redefined loop variable -- FIX ME
131+
"PT011", # `pytest.raises(Exception)` is too broad, set the `match` parameter or use a more specific exception
132+
"PT018", # Assertion should be broken down into multiple parts
133+
"S101", # Use of `assert` detected -- DO NOT FIX
134+
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes -- FIX ME
135+
"SLF001", # Private member accessed: `_Iterator` -- FIX ME
136+
"UP038", # Use `X | Y` in `{}` call instead of `(X, Y)` -- DO NOT FIX
137+
]
138+
139+
# Allow fix for all enabled rules (when `--fix`) is provided.
140+
fixable = ["ALL"]
141+
unfixable = []
142+
143+
# Allow unused variables when underscore-prefixed.
144+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
145+
146+
mccabe.max-complexity = 49
147+
148+
per-file-ignores."cmd2/__init__.py" = [
149+
"E402", # Module level import not at top of file
150+
"F401", # Unused import
151+
]
152+
153+
per-file-ignores."docs/conf.py" = [
154+
"F401", # Unused import
155+
]
156+
157+
per-file-ignores."examples/override_parser.py" = [
158+
"E402", # Module level import not at top of file
159+
]
160+
161+
per-file-ignores."examples/scripts/*.py" = [
162+
"F821", # Undefined name `app`
163+
]
164+
165+
per-file-ignores."tests/pyscript/*.py" = [
166+
"F821", # Undefined name `app`
167+
]
168+
169+
[tool.ruff.format]
170+
# Like Black, use double quotes for strings.
171+
quote-style = "preserve"
172+
173+
# Like Black, indent with spaces, rather than tabs.
174+
indent-style = "space"
175+
176+
# Like Black, respect magic trailing commas.
177+
skip-magic-trailing-comma = false
178+
179+
# Like Black, automatically detect the appropriate line ending.
180+
line-ending = "auto"
181+
182+
# Enable auto-formatting of code examples in docstrings. Markdown,
183+
# reStructuredText code/literal blocks and doctests are all supported.
184+
#
185+
# This is currently disabled by default, but it is planned for this
186+
# to be opt-out in the future.
187+
docstring-code-format = false
188+
189+
# Set the line length limit used when formatting code snippets in
190+
# docstrings.
191+
#
192+
# This only has an effect when the `docstring-code-format` setting is
193+
# enabled.
194+
docstring-code-line-length = "dynamic"

plugins/ext_test/tasks.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ def pytest_clean(context):
8282
def mypy(context):
8383
"""Run mypy optional static type checker"""
8484
with context.cd(TASK_ROOT_STR):
85-
context.run("mypy cmd2_ext_test")
86-
namespace.add_task(mypy)
85+
context.run("mypy .")
8786

8887

8988
namespace.add_task(mypy)
@@ -194,15 +193,22 @@ def pypi_test(context):
194193
namespace.add_task(pypi_test)
195194

196195

197-
# Flake8 - linter and tool for style guide enforcement and linting
196+
# ruff fast linter
198197
@invoke.task
199-
def flake8(context):
200-
"""Run flake8 linter and tool for style guide enforcement"""
198+
def lint(context):
199+
"""Run ruff fast linter"""
201200
with context.cd(TASK_ROOT_STR):
202-
context.run(
203-
"flake8 --ignore=E252,W503 --max-complexity=26 --max-line-length=127 --show-source --statistics "
204-
"--exclude=.git,__pycache__,.tox,.nox,.eggs,*.egg,.venv,.idea,.pytest_cache,.vscode,build,dist,htmlcov"
205-
)
201+
context.run("ruff check")
206202

207203

208-
namespace.add_task(flake8)
204+
namespace.add_task(lint)
205+
206+
207+
@invoke.task
208+
def format(context):
209+
"""Run ruff format --check"""
210+
with context.cd(TASK_ROOT_STR):
211+
context.run("ruff format --check")
212+
213+
214+
namespace.add_task(format)

plugins/tasks.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- setuptools >= 39.1.0
1010
"""
1111

12+
import pathlib
13+
1214
import invoke
1315

1416
from plugins.ext_test import (
@@ -32,6 +34,9 @@
3234
#
3335
#####
3436

37+
TASK_ROOT = pathlib.Path(__file__).resolve().parent
38+
TASK_ROOT_STR = str(TASK_ROOT)
39+
3540

3641
@invoke.task(pre=[ext_test_tasks.pytest])
3742
@invoke.task()
@@ -130,11 +135,22 @@ def wheel(_):
130135
namespace.add_task(wheel)
131136

132137

133-
# Flake8 - linter and tool for style guide enforcement and linting
134-
@invoke.task(pre=[ext_test_tasks.flake8])
135-
def flake8(_):
136-
"""Run flake8 linter and tool for style guide enforcement"""
137-
pass
138+
# ruff linter
139+
@invoke.task(pre=[ext_test_tasks.lint])
140+
def lint(context):
141+
with context.cd(TASK_ROOT_STR):
142+
context.run("ruff check")
143+
144+
145+
namespace.add_task(lint)
146+
147+
148+
# ruff formatter
149+
@invoke.task(pre=[ext_test_tasks.format])
150+
def format(context):
151+
"""Run formatter"""
152+
with context.cd(TASK_ROOT_STR):
153+
context.run("ruff format --check")
138154

139155

140-
namespace.add_task(flake8)
156+
namespace.add_task(format)

pyproject.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@ ignore-path = [
2525
max-line-length = 120
2626
verbose = 0
2727

28+
[tool.mypy]
29+
disallow_incomplete_defs = true
30+
disallow_untyped_calls = true
31+
disallow_untyped_defs = true
32+
exclude = [
33+
"^docs/", # docs directory
34+
"^examples/", # examples directory
35+
"^plugins/*", # plugins directory
36+
"^noxfile\\.py$", # nox config file
37+
"setup\\.py$", # any files named setup.py
38+
"^tasks\\.py$", # tasks.py invoke config file
39+
"^tests/", # tests directory
40+
"^tests_isolated/" # tests_isolated directory
41+
]
42+
show_column_numbers = true
43+
show_error_codes = true
44+
show_error_context = true
45+
strict = true
46+
warn_redundant_casts = true
47+
warn_return_any = true
48+
warn_unreachable = true
49+
warn_unused_ignores = false
50+
2851
[tool.ruff]
2952
# Exclude a variety of commonly ignored directories.
3053
exclude = [

setup.cfg

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,3 @@ addopts =
66
--cov-append
77
--cov-report=term
88
--cov-report=html
9-
10-
[mypy]
11-
disallow_incomplete_defs = True
12-
disallow_untyped_defs = True
13-
disallow_untyped_calls = True
14-
warn_redundant_casts = True
15-
warn_unused_ignores = False
16-
warn_return_any = True
17-
warn_unreachable = True
18-
strict = True
19-
show_error_context = True
20-
show_column_numbers = True
21-
show_error_codes = True

tasks.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,17 @@ def pytest_clean(context):
9595
namespace_clean.add_task(pytest_clean, 'pytest')
9696

9797

98-
@invoke.task(post=[plugin_tasks.mypy])
98+
@invoke.task()
9999
def mypy(context):
100100
"""Run mypy optional static type checker"""
101101
with context.cd(TASK_ROOT_STR):
102-
context.run("mypy cmd2")
103-
with context.cd(str(TASK_ROOT / 'examples')):
104-
context.run("mypy decorator_example.py")
102+
context.run("mypy .")
105103

106104

107105
namespace.add_task(mypy)
108106

109107

110-
@invoke.task(post=[plugin_tasks.mypy_clean])
108+
@invoke.task()
111109
def mypy_clean(context):
112110
"""Remove mypy cache directory"""
113111
# pylint: disable=unused-argument
@@ -348,7 +346,7 @@ def pypi_test(context):
348346

349347

350348
# ruff fast linter
351-
@invoke.task(post=[plugin_tasks.flake8])
349+
@invoke.task()
352350
def lint(context):
353351
"""Run ruff fast linter"""
354352
with context.cd(TASK_ROOT_STR):
@@ -361,7 +359,7 @@ def lint(context):
361359
# ruff fast formatter
362360
@invoke.task()
363361
def format(context):
364-
"""Run ruff format --checkt"""
362+
"""Run ruff format --check"""
365363
with context.cd(TASK_ROOT_STR):
366364
context.run("ruff format --check")
367365

0 commit comments

Comments
 (0)