|
1 | 1 | """Noxfile for the cookiecutter-robust-python template.""" |
2 | | - |
| 2 | +import os |
3 | 3 | import shutil |
4 | 4 | import tempfile |
5 | 5 | from pathlib import Path |
|
15 | 15 | DEFAULT_TEMPLATE_PYTHON_VERSION = "3.9" |
16 | 16 |
|
17 | 17 | REPO_ROOT: Path = Path(__file__).parent.resolve() |
| 18 | +SCRIPTS_FOLDER: Path = REPO_ROOT / "scripts" |
18 | 19 | TEMPLATE_FOLDER: Path = REPO_ROOT / "{{cookiecutter.project_name}}" |
19 | 20 |
|
20 | 21 |
|
|
26 | 27 | ) |
27 | 28 | ).resolve() |
28 | 29 |
|
29 | | -PROJECT_DEMOS_FOLDER: Path = COOKIECUTTER_ROBUST_PYTHON_CACHE_FOLDER / "project_demos" |
30 | | -DEFAULT_DEMO_NAME: str = "demo-project" |
| 30 | +DEFAULT_PROJECT_DEMOS_FOLDER = COOKIECUTTER_ROBUST_PYTHON_CACHE_FOLDER / "project_demos" |
| 31 | +PROJECT_DEMOS_FOLDER: Path = Path(os.getenv( |
| 32 | + "COOKIECUTTER_ROBUST_PYTHON_PROJECT_DEMOS_FOLDER", default=DEFAULT_PROJECT_DEMOS_FOLDER |
| 33 | +)).resolve() |
| 34 | +DEFAULT_DEMO_NAME: str = "robust-python-demo" |
31 | 35 | DEMO_ROOT_FOLDER: Path = PROJECT_DEMOS_FOLDER / DEFAULT_DEMO_NAME |
32 | 36 |
|
| 37 | +GENERATE_DEMO_PROJECT_SCRIPT: Path = SCRIPTS_FOLDER / "generate-demo-project.py" |
33 | 38 | GENERATE_DEMO_PROJECT_OPTIONS: tuple[str, ...] = ( |
34 | 39 | *("--repo-folder", REPO_ROOT), |
35 | 40 | *("--demos-cache-folder", PROJECT_DEMOS_FOLDER), |
36 | 41 | *("--demo-name", DEFAULT_DEMO_NAME), |
37 | 42 | ) |
38 | 43 |
|
| 44 | +SYNC_UV_WITH_DEMO_SCRIPT: Path = SCRIPTS_FOLDER / "sync-uv-with-demo.py" |
39 | 45 | SYNC_UV_WITH_DEMO_OPTIONS: tuple[str, ...] = ( |
40 | 46 | *("--template-folder", TEMPLATE_FOLDER), |
41 | 47 | *("--demos-cache-folder", PROJECT_DEMOS_FOLDER), |
42 | 48 | *("--demo-name", DEFAULT_DEMO_NAME), |
43 | 49 | ) |
44 | 50 |
|
45 | | -TEMPLATE_PYTHON_LOCATIONS: tuple[Path, ...] = (Path("noxfile.py"), Path("scripts"), Path("hooks")) |
46 | | - |
47 | | -TEMPLATE_CONFIG_AND_DOCS: tuple[Path, ...] = ( |
48 | | - Path("pyproject.toml"), |
49 | | - Path(".ruff.toml"), |
50 | | - Path(".editorconfig"), |
51 | | - Path(".gitignore"), |
52 | | - Path(".pre-commit-config.yaml"), |
53 | | - Path(".cz.toml"), |
54 | | - Path("cookiecutter.json"), |
55 | | - Path("README.md"), |
56 | | - Path("LICENSE"), |
57 | | - Path("CODE_OF_CONDUCT.md"), |
58 | | - Path("CHANGELOG.md"), |
59 | | - Path("docs/"), |
60 | | -) |
61 | | - |
62 | 51 |
|
63 | 52 | @nox.session(name="generate-demo-project", python=DEFAULT_TEMPLATE_PYTHON_VERSION) |
64 | 53 | def generate_demo_project(session: Session) -> None: |
| 54 | + """Generates a project demo using the cookiecutter-robust-python template.""" |
65 | 55 | session.install("cookiecutter", "platformdirs", "loguru", "typer") |
66 | 56 | session.run( |
67 | 57 | "python", |
68 | | - "scripts/generate-demo-project.py", |
| 58 | + GENERATE_DEMO_PROJECT_SCRIPT, |
69 | 59 | *GENERATE_DEMO_PROJECT_OPTIONS, |
70 | | - external=True, |
| 60 | + *session.posargs |
71 | 61 | ) |
72 | 62 |
|
73 | 63 |
|
74 | 64 | @nox.session(name="sync-uv-with-demo", python=DEFAULT_TEMPLATE_PYTHON_VERSION) |
75 | 65 | def sync_uv_with_demo(session: Session) -> None: |
| 66 | + """Syncs the uv environment with the current demo project.""" |
76 | 67 | session.install("cookiecutter", "platformdirs", "loguru", "typer") |
77 | 68 | session.run( |
78 | 69 | "python", |
79 | | - "scripts/sync-uv-with-demo.py", |
| 70 | + SYNC_UV_WITH_DEMO_SCRIPT, |
80 | 71 | *SYNC_UV_WITH_DEMO_OPTIONS, |
81 | | - external=True, |
82 | 72 | ) |
83 | 73 |
|
84 | 74 |
|
85 | 75 | @nox.session(name="uv-in-demo", python=DEFAULT_TEMPLATE_PYTHON_VERSION) |
86 | 76 | def uv_in_demo(session: Session) -> None: |
| 77 | + """Runs a uv command in a new project demo project then syncs with it.""" |
87 | 78 | session.install("cookiecutter", "platformdirs", "loguru", "typer") |
88 | 79 | session.run( |
89 | 80 | "python", |
90 | | - "scripts/generate-demo-project.py", |
| 81 | + GENERATE_DEMO_PROJECT_SCRIPT, |
91 | 82 | *GENERATE_DEMO_PROJECT_OPTIONS, |
92 | | - external=True, |
93 | 83 | ) |
94 | 84 | original_dir: Path = Path.cwd() |
95 | 85 | session.cd(DEMO_ROOT_FOLDER) |
96 | 86 | session.run("uv", *session.posargs) |
97 | 87 | session.cd(original_dir) |
98 | 88 | session.run( |
99 | | - "python", |
100 | | - "scripts/sync-uv-with-demo.py", |
| 89 | + SYNC_UV_WITH_DEMO_SCRIPT, |
101 | 90 | *SYNC_UV_WITH_DEMO_OPTIONS, |
102 | 91 | external=True, |
103 | 92 | ) |
104 | 93 |
|
105 | 94 |
|
106 | 95 | @nox.session(name="in-demo", python=DEFAULT_TEMPLATE_PYTHON_VERSION) |
107 | 96 | def in_demo(session: Session) -> None: |
| 97 | + """Generates a project demo and run a uv command in it.""" |
108 | 98 | session.install("cookiecutter", "platformdirs", "loguru", "typer") |
109 | 99 | session.run( |
110 | 100 | "python", |
111 | | - "scripts/generate-demo-project.py", |
| 101 | + GENERATE_DEMO_PROJECT_SCRIPT, |
112 | 102 | *GENERATE_DEMO_PROJECT_OPTIONS, |
113 | 103 | ) |
114 | 104 | original_dir: Path = Path.cwd() |
@@ -141,6 +131,17 @@ def lint(session: Session): |
141 | 131 | session.run("ruff", "check", "--verbose", "--fix") |
142 | 132 |
|
143 | 133 |
|
| 134 | +@nox.session(python=DEFAULT_TEMPLATE_PYTHON_VERSION, name="lint-generated-project", tags=[]) |
| 135 | +def lint_generated_project(session: Session): |
| 136 | + """Lint the generated project's Python files and configurations.""" |
| 137 | + session.log("Installing linting dependencies for the generated project...") |
| 138 | + session.install("-e", ".", "--group", "dev", "--group", "lint") |
| 139 | + session._runner.posargs = ["nox", "-s", "pre-commit"] |
| 140 | + in_demo(session) |
| 141 | + session._runner.posargs = [""] |
| 142 | + session.run("retrocookie") |
| 143 | + |
| 144 | + |
144 | 145 | @nox.session(python=DEFAULT_TEMPLATE_PYTHON_VERSION) |
145 | 146 | def docs(session: Session): |
146 | 147 | """Build the template documentation website.""" |
|
0 commit comments