Skip to content

Commit 3dd5856

Browse files
committed
Update templates for new projects
1 parent eddb974 commit 3dd5856

14 files changed

+418
-141
lines changed

docs/config/project-templates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The list of licenses should be composed of [SPDX identifiers](https://spdx.org/l
3232

3333
### Tests
3434

35-
This adds a `tests` directory with [pytest](https://github.com/pytest-dev/pytest) functionality.
35+
This adds a `tests` directory with environments for testing and linting.
3636

3737
=== ":octicons-file-code-16: config.toml"
3838

docs/environment.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ hatch run python -c "import sys;print(sys.executable)"
5959

6060
You can also run any [scripts](config/environment/overview.md#scripts) that have been defined.
6161

62-
You'll notice that in the `pyproject.toml` file there are already scripts defined in the `default` environment. Try running the `cov` command, which invokes [pytest](https://github.com/pytest-dev/pytest) with some flags for tracking [coverage](https://github.com/nedbat/coveragepy):
62+
You'll notice that in the `pyproject.toml` file there are already scripts defined in the `default` environment. Try running the `test` command, which invokes [pytest](https://github.com/pytest-dev/pytest) with some default arguments:
6363

6464
```
65-
hatch run cov
65+
hatch run test
6666
```
6767

68-
All additional arguments are passed through to scripts, so for example if you wanted to see the version of `pytest` and which plugins are installed you could do:
68+
All additional arguments are passed through to that script, so for example if you wanted to see the version of `pytest` and which plugins are installed you could do:
6969

7070
```
71-
hatch run cov -VV
71+
hatch run test -VV
7272
```
7373

7474
## Dependencies

docs/intro.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ This would create the following structure in your current working directory:
1818

1919
```
2020
hatch-demo
21-
├── hatch_demo
22-
│ ├── __about__.py
23-
│ └── __init__.py
21+
├── src
22+
│ └── hatch_demo
23+
│ ├── __about__.py
24+
│ └── __init__.py
2425
├── tests
2526
│ └── __init__.py
2627
├── LICENSE.txt

docs/version.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ The `regex` source requires an option `path` that represents a relative path to
1212

1313
```toml
1414
[tool.hatch.version]
15-
path = "hatch_demo/__about__.py"
15+
path = "src/hatch_demo/__about__.py"
1616
```
1717

1818
=== ":octicons-file-code-16: hatch.toml"
1919

2020
```toml
2121
[version]
22-
path = "hatch_demo/__about__.py"
22+
path = "src/hatch_demo/__about__.py"
2323
```
2424

2525
The default pattern looks for a variable named `__version__` or `VERSION` that is set to a string containing the version, optionally prefixed with the lowercase letter `v`.

pyproject.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ exclude = [
7777
]
7878

7979
[tool.black]
80-
include = '\.pyi?$'
8180
line-length = 120
8281
skip-string-normalization = true
8382
target-version = ["py37"]
@@ -104,12 +103,17 @@ select = [
104103
"YTT",
105104
]
106105
ignore = [
106+
# Allow non-abstract empty methods in abstract base classes
107107
"B027",
108-
"FBT003",
108+
# Ignore McCabe complexity
109109
"C901",
110-
"S105",
110+
# Allow boolean positional values in function calls, like `dict.get(... True)`
111+
"FBT003",
112+
# Ignore checks for possible passwords
113+
"S105", "S106", "S107",
111114
]
112115
unfixable = [
116+
# Don't touch unused imports
113117
"F401",
114118
]
115119

src/hatch/template/files_default.py

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class PyProject(File):
6868
6969
[project]
7070
name = "{project_name_normalized}"
71+
dynamic = ["version"]
7172
description = {description!r}
7273
readme = "{readme_file_path}"
7374
requires-python = ">=3.7"
@@ -88,7 +89,6 @@ class PyProject(File):
8889
"Programming Language :: Python :: Implementation :: PyPy",
8990
]
9091
dependencies = {dependency_data}
91-
dynamic = ["version"]
9292
9393
[project.urls]{project_url_data}{cli_scripts}
9494
@@ -137,28 +137,62 @@ def __init__(self, template_config: dict, plugin_config: dict):
137137
[tool.hatch.envs.default]
138138
dependencies = [
139139
"pytest",
140-
"pytest-cov",
141140
]
142141
[tool.hatch.envs.default.scripts]
143-
cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov={package_location}{template_config['package_name']} --cov=tests {{args}}"
144-
no-cov = "cov --no-cov {{args}}"
142+
test = "pytest {{args:tests}}"
145143
146-
[[tool.hatch.envs.test.matrix]]
144+
[[tool.hatch.envs.all.matrix]]
147145
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
148146
149-
[tool.coverage.run]
150-
branch = true
151-
parallel = true
152-
omit = [
153-
"{package_location}{template_config['package_name']}/__about__.py",
147+
[envs.lint]
148+
detached = true
149+
dependencies = [
150+
"black",
151+
"mypy",
152+
"ruff",
153+
]
154+
[envs.lint.scripts]
155+
typing = "mypy --install-types --non-interactive {{args:{package_location}{template_config['package_name']} tests}}"
156+
style = [
157+
"ruff {{args:.}}",
158+
"black --check --diff {{args:.}}",
159+
]
160+
fmt = [
161+
"black {{args:.}}",
162+
"ruff --fix {{args:.}}",
163+
"style",
164+
]
165+
all = [
166+
"style",
167+
"typing",
168+
]
169+
170+
[tool.black]
171+
target-version = ["py37"]
172+
line-length = 120
173+
skip-string-normalization = true
174+
175+
[tool.ruff]
176+
target-version = "py37"
177+
line-length = 120
178+
select = ["A", "B", "C", "E", "F", "FBT", "I", "M", "N", "Q", "RUF", "S", "T", "U", "W", "YTT"]
179+
ignore = [
180+
# Allow non-abstract empty methods in abstract base classes
181+
"B027",
182+
# Ignore McCabe complexity
183+
"C901",
184+
# Allow boolean positional values in function calls, like `dict.get(... True)`
185+
"FBT003",
186+
# Ignore checks for possible passwords
187+
"S105", "S106", "S107",
188+
]
189+
unfixable = [
190+
# Don't touch unused imports
191+
"F401",
154192
]
155193
156-
[tool.coverage.report]
157-
exclude_lines = [
158-
"no cov",
159-
"if __name__ == .__main__.:",
160-
"if TYPE_CHECKING:",
161-
]""" # noqa: E501
194+
[tool.ruff.isort]
195+
known-first-party = ["{template_config['package_name']}"]"""
162196

163197
super().__init__(
164198
Path('pyproject.toml'),

tests/helpers/templates/new/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def get_files(**kwargs):
6464
6565
[project]
6666
name = "{kwargs['project_name_normalized']}"
67+
dynamic = ["version"]
6768
description = ''
6869
readme = "README.md"
6970
requires-python = ">=3.7"
@@ -84,7 +85,6 @@ def get_files(**kwargs):
8485
"Programming Language :: Python :: Implementation :: PyPy",
8586
]
8687
dependencies = []
87-
dynamic = ["version"]
8888
8989
[project.urls]
9090
Documentation = "https://github.com/unknown/{kwargs['project_name_normalized']}#readme"

tests/helpers/templates/new/default.py

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def get_files(**kwargs):
7474
7575
[project]
7676
name = "{kwargs['project_name_normalized']}"
77+
dynamic = ["version"]
7778
description = '{description}'
7879
readme = "README.md"
7980
requires-python = ">=3.7"
@@ -94,7 +95,6 @@ def get_files(**kwargs):
9495
"Programming Language :: Python :: Implementation :: PyPy",
9596
]
9697
dependencies = []
97-
dynamic = ["version"]
9898
9999
[project.urls]
100100
Documentation = "https://github.com/unknown/{kwargs['project_name_normalized']}#readme"
@@ -107,28 +107,62 @@ def get_files(**kwargs):
107107
[tool.hatch.envs.default]
108108
dependencies = [
109109
"pytest",
110-
"pytest-cov",
111110
]
112111
[tool.hatch.envs.default.scripts]
113-
cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=src/{kwargs['package_name']} --cov=tests {{args}}"
114-
no-cov = "cov --no-cov {{args}}"
112+
test = "pytest {{args:tests}}"
115113
116-
[[tool.hatch.envs.test.matrix]]
114+
[[tool.hatch.envs.all.matrix]]
117115
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
118116
119-
[tool.coverage.run]
120-
branch = true
121-
parallel = true
122-
omit = [
123-
"src/{kwargs['package_name']}/__about__.py",
117+
[envs.lint]
118+
detached = true
119+
dependencies = [
120+
"black",
121+
"mypy",
122+
"ruff",
123+
]
124+
[envs.lint.scripts]
125+
typing = "mypy --install-types --non-interactive {{args:src/{kwargs['package_name']} tests}}"
126+
style = [
127+
"ruff {{args:.}}",
128+
"black --check --diff {{args:.}}",
129+
]
130+
fmt = [
131+
"black {{args:.}}",
132+
"ruff --fix {{args:.}}",
133+
"style",
134+
]
135+
all = [
136+
"style",
137+
"typing",
124138
]
125139
126-
[tool.coverage.report]
127-
exclude_lines = [
128-
"no cov",
129-
"if __name__ == .__main__.:",
130-
"if TYPE_CHECKING:",
140+
[tool.black]
141+
target-version = ["py37"]
142+
line-length = 120
143+
skip-string-normalization = true
144+
145+
[tool.ruff]
146+
target-version = "py37"
147+
line-length = 120
148+
select = ["A", "B", "C", "E", "F", "FBT", "I", "M", "N", "Q", "RUF", "S", "T", "U", "W", "YTT"]
149+
ignore = [
150+
# Allow non-abstract empty methods in abstract base classes
151+
"B027",
152+
# Ignore McCabe complexity
153+
"C901",
154+
# Allow boolean positional values in function calls, like `dict.get(... True)`
155+
"FBT003",
156+
# Ignore checks for possible passwords
157+
"S105", "S106", "S107",
131158
]
132-
""", # noqa: E501
159+
unfixable = [
160+
# Don't touch unused imports
161+
"F401",
162+
]
163+
164+
[tool.ruff.isort]
165+
known-first-party = ["{kwargs['package_name']}"]
166+
""",
133167
),
134168
]

tests/helpers/templates/new/feature_cli.py

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def {kwargs['package_name']}(ctx: click.Context):
104104
105105
[project]
106106
name = "{kwargs['project_name_normalized']}"
107+
dynamic = ["version"]
107108
description = ''
108109
readme = "README.md"
109110
requires-python = ">=3.7"
@@ -126,7 +127,6 @@ def {kwargs['package_name']}(ctx: click.Context):
126127
dependencies = [
127128
"click",
128129
]
129-
dynamic = ["version"]
130130
131131
[project.urls]
132132
Documentation = "https://github.com/unknown/{kwargs['project_name_normalized']}#readme"
@@ -142,28 +142,62 @@ def {kwargs['package_name']}(ctx: click.Context):
142142
[tool.hatch.envs.default]
143143
dependencies = [
144144
"pytest",
145-
"pytest-cov",
146145
]
147146
[tool.hatch.envs.default.scripts]
148-
cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=src/{kwargs['package_name']} --cov=tests {{args}}"
149-
no-cov = "cov --no-cov {{args}}"
147+
test = "pytest {{args:tests}}"
150148
151-
[[tool.hatch.envs.test.matrix]]
149+
[[tool.hatch.envs.all.matrix]]
152150
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
153151
154-
[tool.coverage.run]
155-
branch = true
156-
parallel = true
157-
omit = [
158-
"src/{kwargs['package_name']}/__about__.py",
152+
[envs.lint]
153+
detached = true
154+
dependencies = [
155+
"black",
156+
"mypy",
157+
"ruff",
158+
]
159+
[envs.lint.scripts]
160+
typing = "mypy --install-types --non-interactive {{args:src/{kwargs['package_name']} tests}}"
161+
style = [
162+
"ruff {{args:.}}",
163+
"black --check --diff {{args:.}}",
164+
]
165+
fmt = [
166+
"black {{args:.}}",
167+
"ruff --fix {{args:.}}",
168+
"style",
169+
]
170+
all = [
171+
"style",
172+
"typing",
159173
]
160174
161-
[tool.coverage.report]
162-
exclude_lines = [
163-
"no cov",
164-
"if __name__ == .__main__.:",
165-
"if TYPE_CHECKING:",
175+
[tool.black]
176+
target-version = ["py37"]
177+
line-length = 120
178+
skip-string-normalization = true
179+
180+
[tool.ruff]
181+
target-version = "py37"
182+
line-length = 120
183+
select = ["A", "B", "C", "E", "F", "FBT", "I", "M", "N", "Q", "RUF", "S", "T", "U", "W", "YTT"]
184+
ignore = [
185+
# Allow non-abstract empty methods in abstract base classes
186+
"B027",
187+
# Ignore McCabe complexity
188+
"C901",
189+
# Allow boolean positional values in function calls, like `dict.get(... True)`
190+
"FBT003",
191+
# Ignore checks for possible passwords
192+
"S105", "S106", "S107",
166193
]
167-
""", # noqa: E501
194+
unfixable = [
195+
# Don't touch unused imports
196+
"F401",
197+
]
198+
199+
[tool.ruff.isort]
200+
known-first-party = ["{kwargs['package_name']}"]
201+
""",
168202
),
169203
]

0 commit comments

Comments
 (0)