Skip to content

Commit 2055afa

Browse files
committed
feat: runs ruff format and check on the template level and adds a few small logic tweaks
1 parent 9bd56a0 commit 2055afa

File tree

13 files changed

+38
-62
lines changed

13 files changed

+38
-62
lines changed

.ruff.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ exclude = [
2828
"node_modules",
2929
"site-packages",
3030
"venv",
31-
"{{cookiecutter.project_name}}",
31+
"[{][{]cookiecutter.project_name[}][}]",
3232
]
3333

3434
# Same as Black.

docs/conf.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from datetime import date
66

7+
78
# --- Project information -----------------------------------------------------
89

910
# General info about the TEMPLATE documentation itself
@@ -59,8 +60,19 @@
5960

6061
# MyST-Parser settings (allows using Markdown + Sphinx features)
6162
myst_enable_extensions = [
62-
"amsmath", "colon_fence", "deflist", "dollarmath", "html_admonition", "html_image", "replacements",
63-
"smartquotes", "strikethrough", "substitution", "tasklist", "attrs_inline", "attrs_block",
63+
"amsmath",
64+
"colon_fence",
65+
"deflist",
66+
"dollarmath",
67+
"html_admonition",
68+
"html_image",
69+
"replacements",
70+
"smartquotes",
71+
"strikethrough",
72+
"substitution",
73+
"tasklist",
74+
"attrs_inline",
75+
"attrs_block",
6476
]
6577

6678
# Intersphinx mapping: Link to documentation of standard libraries or tools mentioned
@@ -85,7 +97,6 @@
8597
"sidebar_hide_name": True, # Hide project name next to logo if logo contains it
8698
# "light_logo": "logo-light.png",
8799
# "dark_logo": "logo-dark.png",
88-
89100
# Footer icons
90101
"footer_icons": [
91102
{

noxfile.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Noxfile for the cookiecutter-robust-python template."""
2-
from pathlib import Path
2+
33
import shutil
44
import tempfile
5+
from pathlib import Path
56

67
import nox
78
import platformdirs
@@ -41,11 +42,7 @@
4142
*("--demo-name", DEFAULT_DEMO_NAME),
4243
)
4344

44-
TEMPLATE_PYTHON_LOCATIONS: tuple[Path, ...] = (
45-
Path("noxfile.py"),
46-
Path("scripts"),
47-
Path("hooks")
48-
)
45+
TEMPLATE_PYTHON_LOCATIONS: tuple[Path, ...] = (Path("noxfile.py"), Path("scripts"), Path("hooks"))
4946

5047
TEMPLATE_CONFIG_AND_DOCS: tuple[Path, ...] = (
5148
Path("pyproject.toml"),
@@ -59,7 +56,7 @@
5956
Path("LICENSE"),
6057
Path("CODE_OF_CONDUCT.md"),
6158
Path("CHANGELOG.md"),
62-
Path("docs/")
59+
Path("docs/"),
6360
)
6461

6562

@@ -84,6 +81,7 @@ def sync_uv_with_demo(session: Session) -> None:
8481
external=True,
8582
)
8683

84+
8785
@nox.session(name="uv-in-demo", python=DEFAULT_TEMPLATE_PYTHON_VERSION)
8886
def uv_in_demo(session: Session) -> None:
8987
session.install("cookiecutter", "platformdirs", "loguru", "typer")
@@ -136,12 +134,11 @@ def lint(session: Session):
136134
session.log("Installing linting dependencies for the template source...")
137135
session.install("-e", ".", "--group", "dev", "--group", "lint")
138136

139-
locations: list[str] = [str(loc) for loc in TEMPLATE_PYTHON_LOCATIONS]
140137
session.log(f"Running Ruff formatter check on template files with py{session.python}.")
141-
session.run("ruff", "format", *locations, "--check")
138+
session.run("ruff", "format")
142139

143140
session.log(f"Running Ruff check on template files with py{session.python}.")
144-
session.run("ruff", "check", *locations, "--verbose")
141+
session.run("ruff", "check", "--verbose", "--fix")
145142

146143

147144
@nox.session(python=DEFAULT_TEMPLATE_PYTHON_VERSION)
@@ -188,11 +185,10 @@ def test(session: Session) -> None:
188185
# Need to find cookiecutter executable - it's in the template dev env installed by uv sync.
189186
cookiecutter_command: list[str] = ["uv", "run", "cookiecutter", "--no-input", "--output-dir", str(temp_dir), "."]
190187

191-
192188
session.run(*cookiecutter_command, external=True)
193189

194190
# Navigate into the generated project directory
195-
generated_project_dir = temp_dir / "test_project" # Use the slug defined in --extra-context
191+
generated_project_dir = temp_dir / "test_project" # Use the slug defined in --extra-context
196192
if not generated_project_dir.exists():
197193
session.error(f"Generated project directory not found: {generated_project_dir}")
198194

@@ -236,12 +232,11 @@ def release_template(session: Session):
236232
cz_bump_args = ["uvx", "cz", "bump", "--changelog"]
237233

238234
if increment:
239-
cz_bump_args.append(f"--increment={increment}")
235+
cz_bump_args.append(f"--increment={increment}")
240236

241237
session.log("Running cz bump with args: %s", cz_bump_args)
242238
# success_codes=[0, 1] -> Allows code 1 which means 'nothing to bump' if no conventional commits since last release
243239
session.run(*cz_bump_args, success_codes=[0, 1], external=True)
244240

245241
session.log("Template version bumped and tag created locally via Commitizen/uvx.")
246242
session.log("IMPORTANT: Push commits and tags to remote (`git push --follow-tags`) to trigger CD for the TEMPLATE.")
247-

scripts/generate-demo-project.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@
77
from typing import Annotated
88

99
import typer
10-
1110
from cookiecutter.main import cookiecutter
1211
from typer.models import OptionInfo
1312

13+
1414
FolderOption: partial[OptionInfo] = partial(
15-
typer.Option,
16-
dir_okay=True,
17-
file_okay=False,
18-
resolve_path=True,
19-
path_type=Path
15+
typer.Option, dir_okay=True, file_okay=False, resolve_path=True, path_type=Path
2016
)
2117

2218

@@ -47,7 +43,7 @@ def _remove_any_existing_demo(parent_path: Path) -> None:
4743
def main(
4844
repo_folder: Annotated[Path, FolderOption("--repo-folder", "-r")],
4945
demos_cache_folder: Annotated[Path, FolderOption("--demos-cache-folder", "-c")],
50-
demo_name: Annotated[str, typer.Option("--demo-name", "-d")]
46+
demo_name: Annotated[str, typer.Option("--demo-name", "-d")],
5147
) -> None:
5248
"""Updates the poetry.lock file."""
5349
try:

scripts/prepare-github-release.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ def main(
146146
description from the draft release notes. The branch contains a single
147147
commit which updates the version number in the documentation.
148148
"""
149-
150149
if tag is None:
151150
today = datetime.date.today()
152151
tag = f"{today:%Y.%-m.%-d}"

scripts/sync-uv-with-demo.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
from typing import Annotated
88

99
import typer
10-
10+
from loguru import logger
1111
from typer.models import OptionInfo
1212

13-
from loguru import logger
1413

1514
FolderOption: partial[OptionInfo] = partial(
1615
typer.Option, dir_okay=True, file_okay=False, resolve_path=True, path_type=Path
@@ -22,9 +21,7 @@ def sync_uv_with_demo(template_folder: Path, demos_cache_folder: Path, demo_name
2221
demo_uv_lock_path: Path = _find_uv_lock_path(demo_root)
2322
output_uv_lock_path: Path = _find_uv_lock_path(template_folder)
2423

25-
_copy_uv_lock_from_demo(
26-
demo_uv_lock_path=demo_uv_lock_path, output_uv_lock_path=output_uv_lock_path
27-
)
24+
_copy_uv_lock_from_demo(demo_uv_lock_path=demo_uv_lock_path, output_uv_lock_path=output_uv_lock_path)
2825
logger.info(f"Copied demo from {demo_uv_lock_path=} to {output_uv_lock_path=}.")
2926

3027

@@ -49,13 +46,11 @@ def _find_uv_lock_path(search_root: Path) -> Path:
4946
def main(
5047
template_folder: Annotated[Path, FolderOption("--template-folder", "-t", exists=True)],
5148
demos_cache_folder: Annotated[Path, FolderOption("--demos-cache-folder", "-c", exists=True)],
52-
demo_name: Annotated[str, typer.Option("--demo-name", "-d")]
49+
demo_name: Annotated[str, typer.Option("--demo-name", "-d")],
5350
) -> None:
5451
"""Updates the uv.lock file."""
5552
try:
56-
sync_uv_with_demo(
57-
template_folder=template_folder, demos_cache_folder=demos_cache_folder, demo_name=demo_name
58-
)
53+
sync_uv_with_demo(template_folder=template_folder, demos_cache_folder=demos_cache_folder, demo_name=demo_name)
5954
except Exception as error:
6055
typer.secho(f"error: {error}", fg="red")
6156
sys.exit(1)

tests/conftest.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import os
44
import subprocess
5-
65
from pathlib import Path
76
from typing import Generator
87

@@ -25,10 +24,7 @@ def robust_python_demo_path(tmp_path_factory: TempPathFactory) -> Path:
2524
no_input=True,
2625
overwrite_if_exists=True,
2726
output_dir=demos_path,
28-
extra_context={
29-
"project_name": "robust-python-demo",
30-
"add_rust_extension": False
31-
}
27+
extra_context={"project_name": "robust-python-demo", "add_rust_extension": False},
3228
)
3329
path: Path = demos_path / "robust-python-demo"
3430
subprocess.run(["uv", "lock"], cwd=path)
@@ -44,10 +40,7 @@ def robust_maturin_demo_path(tmp_path_factory: TempPathFactory) -> Path:
4440
no_input=True,
4541
overwrite_if_exists=True,
4642
output_dir=demos_path,
47-
extra_context={
48-
"project_name": "robust-maturin-demo",
49-
"add_rust_extension": True
50-
}
43+
extra_context={"project_name": "robust-maturin-demo", "add_rust_extension": True},
5144
)
5245
path: Path = demos_path / "robust-maturin-demo"
5346
subprocess.run(["uv", "sync"], cwd=path)

tests/constants.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""Module containing constants used throughout all tests."""
2+
23
import json
34
from pathlib import Path
45
from typing import Any
56

7+
68
REPO_FOLDER: Path = Path(__file__).parent.parent
79
COOKIECUTTER_FOLDER: Path = REPO_FOLDER / "{{cookiecutter.project_name}}"
810
HOOKS_FOLDER: Path = REPO_FOLDER / "hooks"
@@ -36,12 +38,7 @@
3638
"tox",
3739
*CHECK_NOX_SESSIONS,
3840
*FULL_CHECK_NOX_SESSIONS,
39-
"coverage"
41+
"coverage",
4042
]
4143

42-
RUST_NOX_SESSIONS: list[str] = [
43-
"format-rust",
44-
"lint-rust",
45-
"tests-rust",
46-
"publish-rust"
47-
]
44+
RUST_NOX_SESSIONS: list[str] = ["format-rust", "lint-rust", "tests-rust", "publish-rust"]
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
"""Integration tests for cookiecutter-robust-python."""
2-

tests/integration_tests/test_robust_python_demo.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Tests project generation and template functionality using a Python build backend."""
2+
23
import subprocess
34
from pathlib import Path
45

@@ -24,6 +25,3 @@ def test_demo_project_noxfile(robust_python_demo_path: Path, session: str) -> No
2425
print(result.stdout)
2526
print(result.stderr)
2627
result.check_returncode()
27-
28-
29-

0 commit comments

Comments
 (0)