-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyproject.toml
230 lines (200 loc) · 6.21 KB
/
pyproject.toml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
####################
# Project Metadata #
####################
[project]
authors = [{ name = "Henrik Holm", email = "[email protected]" }]
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = []
description = "Python template project using the Hatch project manager."
dynamic = ["version"]
license = { file = "LICENSE" }
name = "python-project"
readme = "README.md"
requires-python = ">=3.13"
[project.urls]
Documentation = "https://github.com/h-holm/python-project"
Source = "https://github.com/h-holm/python-project"
#########
# Hatch #
#########
[tool.hatch]
metadata.allow-direct-references = true
[tool.hatch.env]
requires = ["hatch-pip-compile~=1.11.3"]
[tool.hatch.version]
path = "src/python_project/__version__.py"
raw-options = { version_scheme = "no-guess-dev" }
######################
# Hatch Environments #
######################
# "Base" env to ensure the same Python version is used across all Hatch envs. Note that this env is not supposed to be
# used directly, but rather as a template for other envs.
[tool.hatch.envs.base]
python = "3.13"
# Skip (local) installation of the project itself. This assumes the project is not supposed to be packaged.
skip-install = true
template = "base"
[tool.hatch.envs.base.scripts]
upgrade-all = "PIP_COMPILE_UPGRADE=1 hatch env run --env {env_name} -- python --version"
upgrade-pkg = "PIP_COMPILE_UPGRADE_PACKAGE='{args}' hatch env run --env {env_name} -- python --version"
#######################
# Default Environment #
#######################
# Default environment used by Hatch if no other env is explicitly specified.
[tool.hatch.envs.default]
dependencies = ["typer~=0.15.1"]
installer = "uv"
pip-compile-constraint = "default" # Keep locks between default and other environments consistent.
pip-compile-hashes = true
pip-compile-resolver = "uv"
pip-compile-installer = "uv"
template = "base"
type = "pip-compile"
####################
# Test Environment #
####################
[tool.hatch.envs.test]
# Use `extra-dependencies` to inherit and extend upon the dependencies of the default env.
extra-dependencies = [
"pytest~=8.3.4",
"pytest-asyncio~=0.25.3",
"pytest-cov~=6.0.0",
"pytest-mock~=3.14.0",
]
[tool.hatch.envs.test.scripts]
debug = "python -m pytest --pdb"
test = "python -m pytest --verbose --cov-report=term-missing --cov=src/python_project {args}"
no-cov = "test --no-cov {args}"
cov-xml = "test --cov-report=xml"
# By leveraging the Hatch matrix feature we can test against multiple Python versions.
[[tool.hatch.envs.test.matrix]]
template = ["test"]
python = ["3.13"]
####################
# Lint Environment #
####################
[tool.hatch.envs.lint]
extra-dependencies = [
"mypy~=1.15.0",
"pip~=25.0.0", # To enable `mypy` to `pip install` stubs.
"pre-commit~=4.1.0",
"pydantic~=2.10.6",
"pytest~=8.3.4",
"ruff~=0.9.5",
]
[tool.hatch.envs.lint.scripts]
# Set up and run `pre-commit` hooks.
hooks = [
"python -m pre_commit install",
"python -m pre_commit",
]
# Check the code style and formatting.
style = [
"echo \"VERSION: `ruff --version`\"",
"python -m ruff check {args:.}",
"python -m ruff format --check {args:.}",
]
# Fix code style and formatting issues where possible.
# Run `style` at the end to generate feedback on non-fixable issues.
fix = [
"python -m ruff format {args:.}",
"python -m ruff check --fix {args:.}",
"style",
]
# Perform static type checking.
typing = [
"echo \"VERSION: `mypy --version`\"",
"python -m mypy --install-types --non-interactive {args}",
]
# For use as a `pre-commit` hook, define a simpler `typing` script that (1) ignores missing imports
# and (2) does not `--install-types`.
simple-typing = [
"echo \"VERSION: `mypy --version`\"",
"python -m mypy --ignore-missing-imports {args}",
]
# Define a `lint` script that runs full-scale style, formatting and type checks ...
lint = [
"style",
"typing",
]
# ... and a simpler `simple-lint` script for use as a pre-commit hook.
simple-lint = [
"style",
"simple-typing",
]
##################
# External Tools #
##################
[tool.coverage.paths]
source = ["src/python_project"]
[tool.coverage.report]
exclude_lines = ["pragma: no cover", "if __name__ == .__main__.:"]
skip_empty = true
[tool.coverage.run]
branch = true
omit = ["src/python_project/__version__.py", "tests/*"]
relative_files = true
source = ["src/python_project"]
[tool.mypy]
check_untyped_defs = true
disallow_untyped_defs = true
disallow_any_unimported = true
files = ["src/python_project", "tests"]
# Set to "silent" to not follow.
follow_imports = "normal"
no_implicit_optional = true
plugins = ["pydantic.mypy"]
pretty = true
show_column_numbers = true
show_error_codes = true
warn_return_any = true
warn_unused_ignores = true
[tool.pytest.ini_options]
addopts = "--cov=src/python_project --cov-report=term-missing --doctest-glob='*.md'"
asyncio_default_fixture_loop_scope = "function"
asyncio_mode = "strict"
minversion = "8.3.4"
pythonpath = ["src"]
testpaths = ["tests"]
[tool.ruff]
exclude = ["src/python_project/__version__.py"]
indent-width = 4
line-length = 120
target-version = "py313"
[tool.ruff.lint]
select = ["ALL"]
ignore = [
"COM812", # "May cause conflicts when used with the formatter".
"CPY001", # Requires copyright notices at the top of files.
"D203", # If enabled, this requires one blank line before Class docstrings. Conflicts with D211.
"D213", # Conflicts with D212.
"ISC001", # Causes unexpected behaviour with formatter.
"G004", # Disallows f-strings in logging statements.
"PLC1901", # Disallows comparing to the empty string ("").
]
[tool.ruff.lint.flake8-tidy-imports]
ban-relative-imports = "all"
[tool.ruff.lint.isort]
known-first-party = ["python_project"]
lines-after-imports = 2
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["D104"]
"tests/**/*" = [
# Tests can use magic values, assertions, and relative imports.
"PLR2004",
"S101",
"TID252",
# Tests can skip docstrings.
"D100",
"D103",
# Allow boolean-typed positional arguments in test function definitions.
"FBT001",
]
[tool.ruff.lint.pydocstyle]
convention = "google"