11"""Noxfile for the cookiecutter-robust-python template."""
2-
2+ import os
33import shutil
44import tempfile
55from pathlib import Path
1515DEFAULT_TEMPLATE_PYTHON_VERSION = "3.9"
1616
1717REPO_ROOT : Path = Path (__file__ ).parent .resolve ()
18+ SCRIPTS_FOLDER : Path = REPO_ROOT / "scripts"
1819TEMPLATE_FOLDER : Path = REPO_ROOT / "{{cookiecutter.project_name}}"
1920
2021
2627 )
2728).resolve ()
2829
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 = os .environ .get (
32+ "COOKIECUTTER_ROBUST_PYTHON_PROJECT_DEMOS_FOLDER" , default = DEFAULT_PROJECT_DEMOS_FOLDER
33+ )
34+ DEFAULT_DEMO_NAME : str = "robust-python-demo"
3135DEMO_ROOT_FOLDER : Path = PROJECT_DEMOS_FOLDER / DEFAULT_DEMO_NAME
3236
37+ GENERATE_DEMO_PROJECT_SCRIPT : Path = SCRIPTS_FOLDER / "generate-demo-project.py"
3338GENERATE_DEMO_PROJECT_OPTIONS : tuple [str , ...] = (
3439 * ("--repo-folder" , REPO_ROOT ),
3540 * ("--demos-cache-folder" , PROJECT_DEMOS_FOLDER ),
3641 * ("--demo-name" , DEFAULT_DEMO_NAME ),
3742)
3843
44+ SYNC_UV_WITH_DEMO_SCRIPT : Path = SCRIPTS_FOLDER / "sync-uv-with-demo.py"
3945SYNC_UV_WITH_DEMO_OPTIONS : tuple [str , ...] = (
4046 * ("--template-folder" , TEMPLATE_FOLDER ),
4147 * ("--demos-cache-folder" , PROJECT_DEMOS_FOLDER ),
@@ -48,9 +54,8 @@ def generate_demo_project(session: Session) -> None:
4854 session .install ("cookiecutter" , "platformdirs" , "loguru" , "typer" )
4955 session .run (
5056 "python" ,
51- "scripts/generate-demo-project.py" ,
57+ GENERATE_DEMO_PROJECT_SCRIPT ,
5258 * GENERATE_DEMO_PROJECT_OPTIONS ,
53- external = True ,
5459 )
5560
5661
@@ -59,9 +64,8 @@ def sync_uv_with_demo(session: Session) -> None:
5964 session .install ("cookiecutter" , "platformdirs" , "loguru" , "typer" )
6065 session .run (
6166 "python" ,
62- "scripts/sync-uv-with-demo.py" ,
67+ SYNC_UV_WITH_DEMO_SCRIPT ,
6368 * SYNC_UV_WITH_DEMO_OPTIONS ,
64- external = True ,
6569 )
6670
6771
@@ -70,17 +74,15 @@ def uv_in_demo(session: Session) -> None:
7074 session .install ("cookiecutter" , "platformdirs" , "loguru" , "typer" )
7175 session .run (
7276 "python" ,
73- "scripts/generate-demo-project.py" ,
77+ GENERATE_DEMO_PROJECT_SCRIPT ,
7478 * GENERATE_DEMO_PROJECT_OPTIONS ,
75- external = True ,
7679 )
7780 original_dir : Path = Path .cwd ()
7881 session .cd (DEMO_ROOT_FOLDER )
7982 session .run ("uv" , * session .posargs )
8083 session .cd (original_dir )
8184 session .run (
82- "python" ,
83- "scripts/sync-uv-with-demo.py" ,
85+ SYNC_UV_WITH_DEMO_SCRIPT ,
8486 * SYNC_UV_WITH_DEMO_OPTIONS ,
8587 external = True ,
8688 )
@@ -91,7 +93,7 @@ def in_demo(session: Session) -> None:
9193 session .install ("cookiecutter" , "platformdirs" , "loguru" , "typer" )
9294 session .run (
9395 "python" ,
94- "scripts/generate-demo-project.py" ,
96+ GENERATE_DEMO_PROJECT_SCRIPT ,
9597 * GENERATE_DEMO_PROJECT_OPTIONS ,
9698 )
9799 original_dir : Path = Path .cwd ()
@@ -124,13 +126,14 @@ def lint(session: Session):
124126 session .run ("ruff" , "check" , "--verbose" , "--fix" )
125127
126128
127- @nox .session (python = DEFAULT_TEMPLATE_PYTHON_VERSION )
129+ @nox .session (python = None )
128130def lint_generated_project (session : Session ):
129131 """Lint the generated project's Python files and configurations."""
130132 session .log ("Installing linting dependencies for the generated project..." )
131- session .install ("-e" , "." , "--group" , "dev" , "--group" , "lint" )
132- session .notify ("in-demo" , ["nox" , "-s" , "pre-commit" ])
133- session .notify ("in-demo" , )
133+ session .install ("-e" , "." , "--group" , "dev" )
134+ session ._runner .posargs = ["nox" , "-s" , "pre-commit" ]
135+ in_demo (session )
136+ session ._runner .posargs = ["" ]
134137 session .run ("retrocookie" )
135138
136139
0 commit comments