Skip to content

Commit b812a7e

Browse files
committed
🐛 ruff + mypy updates
1 parent 9b3d10f commit b812a7e

7 files changed

Lines changed: 121 additions & 105 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,4 @@ dmypy.json
141141
# Cookiecutter Examples
142142
example-project/
143143
!tests/example-project/
144+
!tests/example-project/.env

.pre-commit-config.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
default_stages: [commit]
22
fail_fast: false
3-
exclude: "{{cookiecutter.repo_name}}"
3+
exclude: |
4+
(?x)(
5+
{{cookiecutter.repo_name}}/|
6+
test/example-project/
7+
)
48
repos:
59
- repo: https://github.com/pre-commit/pre-commit-hooks
610
rev: v4.5.0
@@ -23,3 +27,8 @@ repos:
2327
(?x)(
2428
.github/semantic_release/release_notes.hbs
2529
)
30+
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
31+
rev: v2.11.0
32+
hooks:
33+
- id: pretty-format-toml
34+
args: [--autofix]

pyproject.toml

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ requires = ["hatchling"]
66
authors = [
77
{name = "Justin Flannery", email = "juftin@juftin.com"}
88
]
9+
dependencies = [
10+
"cookiecutter~=2.4.0"
11+
]
912
description = "Brief description of the project"
1013
license = "MIT"
1114
name = "example-project"
1215
readme = "README.md"
1316
requires-python = ">=3.8"
1417
version = "0.0.0"
15-
dependencies = [
16-
"cookiecutter~=2.4.0",
17-
]
1818

1919
[tool.hatch.envs.default]
2020
dependencies = [
@@ -37,8 +37,8 @@ cov-report = [
3737
"- coverage combine",
3838
"coverage report -m"
3939
]
40-
test = "pytest {args:tests}"
41-
test-cov = "coverage run -m pytest {args:tests}"
40+
test = "pytest {args:tests/test_cookiecutter.py}"
41+
test-cov = "coverage run -m pytest {args:tests/test_cookiecutter.py}"
4242

4343
[tool.hatch.envs.docs]
4444
dependencies = [
@@ -70,8 +70,8 @@ reqs-update = "pip-compile {args:} --upgrade --generate-hashes --output-file req
7070

7171
[tool.hatch.envs.lint]
7272
dependencies = [
73-
"mypy>=1.0.0",
74-
"ruff~=0.1.3"
73+
"mypy>=1.6.1",
74+
"ruff~=0.1.4"
7575
]
7676
detached = true
7777

@@ -113,31 +113,31 @@ ignore = [
113113
]
114114
line-length = 100
115115
select = [
116-
"A",
117-
"ARG",
118-
"B",
119-
"C",
120-
"DTZ",
121-
"E",
122-
"EM",
123-
"F",
124-
"FBT",
125-
"I",
126-
"ICN",
127-
"ISC",
128-
"N",
129-
"PLC",
130-
"PLE",
131-
"PLR",
132-
"PLW",
133-
"Q",
134-
"RUF",
135-
"S",
136-
"T",
137-
"TID",
138-
"UP",
139-
"W",
140-
"YTT"
116+
"A", # flake8-builtins
117+
"ARG", # flake8-unused-arguments
118+
"B", # flake8-bugbear
119+
"C", # mccabe
120+
"DTZ", # flake8-datetimez
121+
"E", # pycodestyle (Error)
122+
"EM", # flake8-errmsg
123+
"F", # Pyflakes
124+
"FBT", # flake8-boolean-trap
125+
"I", # isort
126+
"ICN", # flake8-import-conventions
127+
"ISC", # flake8-implicit-str-concat
128+
"N", # pep8-naming
129+
"PLC", # Pylint (Convention message)
130+
"PLE", # Pylint (Error message)
131+
"PLR", # Pylint (Refactor message)
132+
"PLW", # Pylint (Warning message)
133+
"Q", # flake8-quotes
134+
"RUF", # Ruff-specific rules
135+
"S", # flake8-bandit
136+
"T", # flake8-debugger (T10) and flake8-print (T20)
137+
"TID", # flake8-tidy-imports
138+
"UP", # pyupgrade
139+
"W", # pycodestyle (Warning)
140+
"YTT" # flake8-2020
141141
]
142142
target-version = "py38"
143143
unfixable = [

tests/example-project/.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PERSONAL_ACCESS_TOKEN="xxxxx"
2+
PYPI_TOKEN="xxxxx"
3+
DOCKER_USERNAME="xxxxx"
4+
DOCKER_TOKEN="xxxxx"

tests/example-project/pyproject.toml

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ reqs-update = "pip-compile {args:} --upgrade --generate-hashes --output-file req
115115

116116
[tool.hatch.envs.lint]
117117
dependencies = [
118-
"mypy>=1.0.0",
119-
"ruff~=0.1.3"
118+
"mypy>=1.6.1",
119+
"ruff~=0.1.4"
120120
]
121121
detached = true
122122

@@ -167,31 +167,31 @@ ignore = [
167167
]
168168
line-length = 100
169169
select = [
170-
"A",
171-
"ARG",
172-
"B",
173-
"C",
174-
"DTZ",
175-
"E",
176-
"EM",
177-
"F",
178-
"FBT",
179-
"I",
180-
"ICN",
181-
"ISC",
182-
"N",
183-
"PLC",
184-
"PLE",
185-
"PLR",
186-
"PLW",
187-
"Q",
188-
"RUF",
189-
"S",
190-
"T",
191-
"TID",
192-
"UP",
193-
"W",
194-
"YTT"
170+
"A", # flake8-builtins
171+
"ARG", # flake8-unused-arguments
172+
"B", # flake8-bugbear
173+
"C", # mccabe
174+
"DTZ", # flake8-datetimez
175+
"E", # pycodestyle (Error)
176+
"EM", # flake8-errmsg
177+
"F", # Pyflakes
178+
"FBT", # flake8-boolean-trap
179+
"I", # isort
180+
"ICN", # flake8-import-conventions
181+
"ISC", # flake8-implicit-str-concat
182+
"N", # pep8-naming
183+
"PLC", # Pylint (Convention message)
184+
"PLE", # Pylint (Error message)
185+
"PLR", # Pylint (Refactor message)
186+
"PLW", # Pylint (Warning message)
187+
"Q", # flake8-quotes
188+
"RUF", # Ruff-specific rules
189+
"S", # flake8-bandit
190+
"T", # flake8-debugger (T10) and flake8-print (T20)
191+
"TID", # flake8-tidy-imports
192+
"UP", # pyupgrade
193+
"W", # pycodestyle (Warning)
194+
"YTT" # flake8-2020
195195
]
196196
target-version = "py38"
197197
unfixable = [

tests/test_cookiecutter.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,34 @@
33
"""
44

55
import pathlib
6-
import tempfile
6+
import shutil
77

88
import pytest
99
from cookiecutter.main import cookiecutter
1010

1111

12-
@pytest.fixture(scope="session", autouse=True)
12+
@pytest.fixture
1313
def cookiecutter_dir() -> pathlib.Path:
1414
"""
1515
CookieCutter Tests
1616
"""
17-
with tempfile.TemporaryDirectory() as tmpdir:
18-
tmp_path = pathlib.Path(tmpdir)
19-
_this_file = pathlib.Path(__file__).resolve()
20-
cookiecutter_dir = _this_file.parent.parent
21-
cookiecutter(
22-
template=str(cookiecutter_dir),
23-
output_dir=str(tmp_path),
24-
no_input=True,
25-
extra_context={
26-
"build_docker_image": True,
27-
"publish_to_pypi": True,
28-
"publish_to_docker_hub": True,
29-
}
30-
)
31-
yield tmp_path / "example-project"
17+
_this_file = pathlib.Path(__file__).resolve()
18+
cookiecutter_dir = _this_file.parent.parent
19+
test_dir = cookiecutter_dir / "tests"
20+
output_dir = test_dir / "output"
21+
output_repo = output_dir / "example-project"
22+
shutil.rmtree(output_dir, ignore_errors=True)
23+
cookiecutter(
24+
template=str(cookiecutter_dir),
25+
output_dir=str(output_dir),
26+
no_input=True,
27+
extra_context={
28+
"build_docker_image": True,
29+
"publish_to_pypi": True,
30+
"publish_to_docker_hub": True,
31+
}
32+
)
33+
return output_repo
3234

3335

3436
def test_cookiecutter_dir(cookiecutter_dir: pathlib.Path) -> None:
@@ -48,7 +50,7 @@ def test_cookiecutter_dir(cookiecutter_dir: pathlib.Path) -> None:
4850
try:
4951
assert expected == actual
5052
except AssertionError as e:
51-
msg = f"Unexpected File Difference - {test_path}"
53+
msg = f"Unexpected File Difference - {test_path} - {generated_file}"
5254
raise ValueError(msg) from e
5355
file_counter += 1
5456
assert file_counter > 0

{{cookiecutter.repo_name}}/pyproject.toml

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ reqs-update = "pip-compile {args:} --upgrade --generate-hashes --output-file req
117117

118118
[tool.hatch.envs.lint]
119119
dependencies = [
120-
"mypy>=1.0.0",
121-
"ruff~=0.1.3"
120+
"mypy>=1.6.1",
121+
"ruff~=0.1.4"
122122
]
123123
detached = true
124124

@@ -169,31 +169,31 @@ ignore = [
169169
]
170170
line-length = 100
171171
select = [
172-
"A",
173-
"ARG",
174-
"B",
175-
"C",
176-
"DTZ",
177-
"E",
178-
"EM",
179-
"F",
180-
"FBT",
181-
"I",
182-
"ICN",
183-
"ISC",
184-
"N",
185-
"PLC",
186-
"PLE",
187-
"PLR",
188-
"PLW",
189-
"Q",
190-
"RUF",
191-
"S",
192-
"T",
193-
"TID",
194-
"UP",
195-
"W",
196-
"YTT"
172+
"A", # flake8-builtins
173+
"ARG", # flake8-unused-arguments
174+
"B", # flake8-bugbear
175+
"C", # mccabe
176+
"DTZ", # flake8-datetimez
177+
"E", # pycodestyle (Error)
178+
"EM", # flake8-errmsg
179+
"F", # Pyflakes
180+
"FBT", # flake8-boolean-trap
181+
"I", # isort
182+
"ICN", # flake8-import-conventions
183+
"ISC", # flake8-implicit-str-concat
184+
"N", # pep8-naming
185+
"PLC", # Pylint (Convention message)
186+
"PLE", # Pylint (Error message)
187+
"PLR", # Pylint (Refactor message)
188+
"PLW", # Pylint (Warning message)
189+
"Q", # flake8-quotes
190+
"RUF", # Ruff-specific rules
191+
"S", # flake8-bandit
192+
"T", # flake8-debugger (T10) and flake8-print (T20)
193+
"TID", # flake8-tidy-imports
194+
"UP", # pyupgrade
195+
"W", # pycodestyle (Warning)
196+
"YTT" # flake8-2020
197197
]
198198
target-version = "py38"
199199
unfixable = [

0 commit comments

Comments
 (0)