Skip to content

Commit b9d02c5

Browse files
Merge pull request #11932 Add pre-commit hook and fix pyproject.toml
- [pyproject-fmt] Add pre-commit hook and autofix existing - Proper setuptools version for pyproject.toml
2 parents 404d31a + d109542 commit b9d02c5

File tree

2 files changed

+110
-102
lines changed

2 files changed

+110
-102
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ repos:
4242
# for mypy running on python>=3.11 since exceptiongroup is only a dependency
4343
# on <3.11
4444
- exceptiongroup>=1.0.0rc8
45+
- repo: https://github.com/tox-dev/pyproject-fmt
46+
rev: "1.7.0"
47+
hooks:
48+
- id: pyproject-fmt
49+
# https://pyproject-fmt.readthedocs.io/en/latest/#calculating-max-supported-python-version
50+
additional_dependencies: ["tox>=4.9"]
4551
- repo: local
4652
hooks:
4753
- id: rst

pyproject.toml

Lines changed: 104 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
[project]
22
name = "pytest"
3-
dynamic = ["version"]
43
description = "pytest: simple powerful testing with Python"
4+
readme = "README.rst"
5+
keywords = [
6+
"test",
7+
"unittest",
8+
]
9+
license = {text = "MIT"}
510
authors = [
611
{name = "Holger Krekel"},
712
{name = "Bruno Oliveira"},
@@ -11,18 +16,15 @@ authors = [
1116
{name = "Florian Bruhin"},
1217
{name = "Others (See AUTHORS)"},
1318
]
14-
readme = "README.rst"
15-
license = {text = "MIT"}
16-
keywords = ["test", "unittest"]
19+
requires-python = ">=3.8"
1720
classifiers = [
1821
"Development Status :: 6 - Mature",
1922
"Intended Audience :: Developers",
2023
"License :: OSI Approved :: MIT License",
2124
"Operating System :: MacOS",
2225
"Operating System :: Microsoft :: Windows",
23-
"Operating System :: Unix",
2426
"Operating System :: POSIX",
25-
"Programming Language :: Python :: 3",
27+
"Operating System :: Unix",
2628
"Programming Language :: Python :: 3 :: Only",
2729
"Programming Language :: Python :: 3.8",
2830
"Programming Language :: Python :: 3.9",
@@ -33,46 +35,44 @@ classifiers = [
3335
"Topic :: Software Development :: Testing",
3436
"Topic :: Utilities",
3537
]
36-
38+
dynamic = [
39+
"version",
40+
]
3741
dependencies = [
38-
"colorama;sys_platform=='win32'",
39-
"exceptiongroup>=1.0.0rc8;python_version<'3.11'",
42+
'colorama; sys_platform == "win32"',
43+
'exceptiongroup>=1.0.0rc8; python_version < "3.11"',
4044
"iniconfig",
4145
"packaging",
42-
"pluggy>=1.4.0,<2.0",
43-
"tomli>=1.0.0;python_version<'3.11'",
46+
"pluggy<2.0,>=1.4",
47+
'tomli>=1; python_version < "3.11"',
4448
]
45-
requires-python = ">=3.8"
46-
4749
[project.optional-dependencies]
4850
testing = [
4951
"argcomplete",
50-
"attrs>=19.2.0",
52+
"attrs>=19.2",
5153
"hypothesis>=3.56",
5254
"mock",
5355
"pygments>=2.7.2",
5456
"requests",
5557
"setuptools",
5658
"xmlschema",
5759
]
58-
59-
[project.scripts]
60-
"py.test" = "pytest:console_main"
61-
pytest = "pytest:console_main"
62-
6360
[project.urls]
64-
Homepage = "https://docs.pytest.org/en/latest/"
6561
Changelog = "https://docs.pytest.org/en/stable/changelog.html"
66-
Twitter = "https://twitter.com/pytestdotorg"
62+
Homepage = "https://docs.pytest.org/en/latest/"
6763
Source = "https://github.com/pytest-dev/pytest"
6864
Tracker = "https://github.com/pytest-dev/pytest/issues"
65+
Twitter = "https://twitter.com/pytestdotorg"
66+
[project.scripts]
67+
"py.test" = "pytest:console_main"
68+
pytest = "pytest:console_main"
6969

7070
[build-system]
71+
build-backend = "setuptools.build_meta"
7172
requires = [
72-
"setuptools>=45.0",
73-
"setuptools-scm[toml]>=6.2.3",
73+
"setuptools>=61",
74+
"setuptools-scm[toml]>=6.2.3",
7475
]
75-
build-backend = "setuptools.build_meta"
7676

7777
[tool.setuptools.package-data]
7878
"_pytest" = ["py.typed"]
@@ -81,6 +81,86 @@ build-backend = "setuptools.build_meta"
8181
[tool.setuptools_scm]
8282
write_to = "src/_pytest/_version.py"
8383

84+
[tool.black]
85+
target-version = ['py38']
86+
87+
[tool.ruff]
88+
src = ["src"]
89+
line-length = 88
90+
select = [
91+
"B", # bugbear
92+
"D", # pydocstyle
93+
"E", # pycodestyle
94+
"F", # pyflakes
95+
"I", # isort
96+
"PYI", # flake8-pyi
97+
"UP", # pyupgrade
98+
"RUF", # ruff
99+
"W", # pycodestyle
100+
]
101+
ignore = [
102+
# bugbear ignore
103+
"B004", # Using `hasattr(x, "__call__")` to test if x is callable is unreliable.
104+
"B007", # Loop control variable `i` not used within loop body
105+
"B009", # Do not call `getattr` with a constant attribute value
106+
"B010", # [*] Do not call `setattr` with a constant attribute value.
107+
"B011", # Do not `assert False` (`python -O` removes these calls)
108+
"B028", # No explicit `stacklevel` keyword argument found
109+
# pycodestyle ignore
110+
# pytest can do weird low-level things, and we usually know
111+
# what we're doing when we use type(..) is ...
112+
"E721", # Do not compare types, use `isinstance()`
113+
# pydocstyle ignore
114+
"D100", # Missing docstring in public module
115+
"D101", # Missing docstring in public class
116+
"D102", # Missing docstring in public method
117+
"D103", # Missing docstring in public function
118+
"D104", # Missing docstring in public package
119+
"D105", # Missing docstring in magic method
120+
"D106", # Missing docstring in public nested class
121+
"D107", # Missing docstring in `__init__`
122+
"D209", # [*] Multi-line docstring closing quotes should be on a separate line
123+
"D205", # 1 blank line required between summary line and description
124+
"D400", # First line should end with a period
125+
"D401", # First line of docstring should be in imperative mood
126+
"D402", # First line should not be the function's signature
127+
"D404", # First word of the docstring should not be "This"
128+
"D415", # First line should end with a period, question mark, or exclamation point
129+
# ruff ignore
130+
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
131+
]
132+
133+
[tool.ruff.format]
134+
docstring-code-format = true
135+
136+
[tool.ruff.lint.pycodestyle]
137+
# In order to be able to format for 88 char in ruff format
138+
max-line-length = 120
139+
140+
[tool.ruff.lint.pydocstyle]
141+
convention = "pep257"
142+
143+
[tool.ruff.lint.isort]
144+
force-single-line = true
145+
combine-as-imports = true
146+
force-sort-within-sections = true
147+
order-by-type = false
148+
known-local-folder = ["pytest", "_pytest"]
149+
lines-after-imports = 2
150+
151+
[tool.ruff.lint.per-file-ignores]
152+
"src/_pytest/_py/**/*.py" = ["B", "PYI"]
153+
"src/_pytest/_version.py" = ["I001"]
154+
"testing/python/approx.py" = ["B015"]
155+
156+
[tool.check-wheel-contents]
157+
# check-wheel-contents is executed by the build-and-inspect-python-package action.
158+
# W009: Wheel contains multiple toplevel library entries
159+
ignore = "W009"
160+
161+
[tool.pyproject-fmt]
162+
indent = 4
163+
84164
[tool.pytest.ini_options]
85165
minversion = "2.0"
86166
addopts = "-rfEX -p pytester --strict-markers"
@@ -140,7 +220,6 @@ markers = [
140220
"uses_pexpect",
141221
]
142222

143-
144223
[tool.towncrier]
145224
package = "pytest"
146225
package_dir = "src"
@@ -189,83 +268,6 @@ template = "changelog/_template.rst"
189268
name = "Trivial/Internal Changes"
190269
showcontent = true
191270

192-
[tool.black]
193-
target-version = ['py38']
194-
195-
# check-wheel-contents is executed by the build-and-inspect-python-package action.
196-
[tool.check-wheel-contents]
197-
# W009: Wheel contains multiple toplevel library entries
198-
ignore = "W009"
199-
200-
[tool.ruff]
201-
src = ["src"]
202-
line-length = 88
203-
select = [
204-
"B", # bugbear
205-
"D", # pydocstyle
206-
"E", # pycodestyle
207-
"F", # pyflakes
208-
"I", # isort
209-
"PYI", # flake8-pyi
210-
"UP", # pyupgrade
211-
"RUF", # ruff
212-
"W", # pycodestyle
213-
]
214-
ignore = [
215-
# bugbear ignore
216-
"B004", # Using `hasattr(x, "__call__")` to test if x is callable is unreliable.
217-
"B007", # Loop control variable `i` not used within loop body
218-
"B009", # Do not call `getattr` with a constant attribute value
219-
"B010", # [*] Do not call `setattr` with a constant attribute value.
220-
"B011", # Do not `assert False` (`python -O` removes these calls)
221-
"B028", # No explicit `stacklevel` keyword argument found
222-
# pycodestyle ignore
223-
# pytest can do weird low-level things, and we usually know
224-
# what we're doing when we use type(..) is ...
225-
"E721", # Do not compare types, use `isinstance()`
226-
# pydocstyle ignore
227-
"D100", # Missing docstring in public module
228-
"D101", # Missing docstring in public class
229-
"D102", # Missing docstring in public method
230-
"D103", # Missing docstring in public function
231-
"D104", # Missing docstring in public package
232-
"D105", # Missing docstring in magic method
233-
"D106", # Missing docstring in public nested class
234-
"D107", # Missing docstring in `__init__`
235-
"D209", # [*] Multi-line docstring closing quotes should be on a separate line
236-
"D205", # 1 blank line required between summary line and description
237-
"D400", # First line should end with a period
238-
"D401", # First line of docstring should be in imperative mood
239-
"D402", # First line should not be the function's signature
240-
"D404", # First word of the docstring should not be "This"
241-
"D415", # First line should end with a period, question mark, or exclamation point
242-
# ruff ignore
243-
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
244-
]
245-
246-
[tool.ruff.format]
247-
docstring-code-format = true
248-
249-
[tool.ruff.lint.pycodestyle]
250-
# In order to be able to format for 88 char in ruff format
251-
max-line-length = 120
252-
253-
[tool.ruff.lint.pydocstyle]
254-
convention = "pep257"
255-
256-
[tool.ruff.lint.isort]
257-
force-single-line = true
258-
combine-as-imports = true
259-
force-sort-within-sections = true
260-
order-by-type = false
261-
known-local-folder = ["pytest", "_pytest"]
262-
lines-after-imports = 2
263-
264-
[tool.ruff.lint.per-file-ignores]
265-
"src/_pytest/_py/**/*.py" = ["B", "PYI"]
266-
"src/_pytest/_version.py" = ["I001"]
267-
"testing/python/approx.py" = ["B015"]
268-
269271
[tool.mypy]
270272
mypy_path = ["src"]
271273
check_untyped_defs = true

0 commit comments

Comments
 (0)