88import sys
99
1010import nox
11+ import platformdirs
1112from nox .sessions import Session
1213
1314nox .options .default_venv_backend = "uv"
1415
15- DEFAULT_TEMPLATE_PYTHON_VERSION = "3.12"
16+ DEFAULT_TEMPLATE_PYTHON_VERSION = "3.9"
17+
18+ REPO_ROOT : Path = Path (__file__ ).parent .resolve ()
19+ TEMPLATE_FOLDER : Path = REPO_ROOT / "{{cookiecutter.project_name}}"
20+
21+
22+ COOKIECUTTER_ROBUST_PYTHON_CACHE_FOLDER : Path = Path (
23+ platformdirs .user_cache_path (
24+ appname = "cookiecutter-robust-python" ,
25+ appauthor = "56kyle" ,
26+ ensure_exists = True ,
27+ )
28+ ).resolve ()
29+
30+ PROJECT_DEMOS_FOLDER : Path = COOKIECUTTER_ROBUST_PYTHON_CACHE_FOLDER / "project_demos"
31+ DEFAULT_DEMO_NAME : str = "demo-project"
32+ DEMO_ROOT_FOLDER : Path = PROJECT_DEMOS_FOLDER / DEFAULT_DEMO_NAME
33+
34+ GENERATE_DEMO_PROJECT_OPTIONS : tuple [str , ...] = (
35+ * ("--repo-folder" , REPO_ROOT ),
36+ * ("--demos-cache-folder" , PROJECT_DEMOS_FOLDER ),
37+ * ("--demo-name" , DEFAULT_DEMO_NAME ),
38+ )
39+
40+ SYNC_UV_WITH_DEMO_OPTIONS : tuple [str , ...] = (
41+ * ("--template-folder" , TEMPLATE_FOLDER ),
42+ * ("--demos-cache-folder" , PROJECT_DEMOS_FOLDER ),
43+ * ("--demo-name" , DEFAULT_DEMO_NAME ),
44+ )
1645
1746TEMPLATE_PYTHON_LOCATIONS : tuple [Path , ...] = (
1847 Path ("noxfile.py" ),
3463)
3564
3665
37- # === TEMPLATE MAINTENANCE TASKS ===
38- # Sessions for checking, formatting, building, and releasing the template itself.
66+ @nox .session (name = "generate-demo-project" , python = DEFAULT_TEMPLATE_PYTHON_VERSION )
67+ def generate_demo_project (session : Session ) -> None :
68+ session .install ("cookiecutter" , "platformdirs" , "loguru" , "typer" )
69+ session .run (
70+ "python" ,
71+ "scripts/generate-demo-project.py" ,
72+ * GENERATE_DEMO_PROJECT_OPTIONS ,
73+ external = True ,
74+ )
75+
76+
77+ @nox .session (name = "sync-uv-with-demo" , python = DEFAULT_TEMPLATE_PYTHON_VERSION )
78+ def sync_uv_with_demo (session : Session ) -> None :
79+ session .install ("cookiecutter" , "platformdirs" , "loguru" , "typer" )
80+ session .run (
81+ "python" ,
82+ "scripts/sync-uv-with-demo.py" ,
83+ * SYNC_UV_WITH_DEMO_OPTIONS ,
84+ external = True ,
85+ )
86+
87+ @nox .session (name = "uv-in-demo" , python = DEFAULT_TEMPLATE_PYTHON_VERSION )
88+ def uv_in_demo (session : Session ) -> None :
89+ session .install ("cookiecutter" , "platformdirs" , "loguru" , "typer" )
90+ session .run (
91+ "python" ,
92+ "scripts/generate-demo-project.py" ,
93+ * GENERATE_DEMO_PROJECT_OPTIONS ,
94+ external = True ,
95+ )
96+ original_dir : Path = Path .cwd ()
97+ session .cd (DEMO_ROOT_FOLDER )
98+ session .run ("uv" , * session .posargs )
99+ session .cd (original_dir )
100+ session .run (
101+ "python" ,
102+ "scripts/sync-uv-with-demo.py" ,
103+ * SYNC_UV_WITH_DEMO_OPTIONS ,
104+ external = True ,
105+ )
39106
40107
41108@nox .session (python = DEFAULT_TEMPLATE_PYTHON_VERSION )
@@ -74,15 +141,6 @@ def docs(session: Session):
74141 session .log (f"Template documentation built in { docs_build_dir .resolve ()} ." )
75142
76143
77- @nox .session (python = DEFAULT_TEMPLATE_PYTHON_VERSION )
78- def generate_project (session : Session ) -> None :
79- """Generate a demo project using the template."""
80- session .log ("Installing demo project generation dependencies..." )
81- session .install ("cookiecutter" , "typer" )
82- session .run ("generate-demo-project" , "--repo-folder=." , "--demos-cache-folder=." , "--demo-name=demo_project" )
83-
84-
85-
86144@nox .session (python = DEFAULT_TEMPLATE_PYTHON_VERSION )
87145def test (session : Session ) -> None :
88146 """Run tests for the template's own functionality.
@@ -104,19 +162,7 @@ def test(session: Session) -> None:
104162 # Run cookiecutter to generate a project
105163 # Need to find cookiecutter executable - it's in the template dev env installed by uv sync.
106164 cookiecutter_command : list [str ] = ["uv" , "run" , "cookiecutter" , "--no-input" , "--output-dir" , str (temp_dir ), "." ]
107- # Add cookiecutter variables to customize the generated project for testing, using --extra-context
108- cookiecutter_command .extend ([
109- "--extra-context" ,
110- "project_name='Test Project'" ,
111- "project_slug='test_project'" ,
112- "package_name='test_package'" ,
113- "author_name='Test Author'" ,
114- "author_email='test@example.com'" ,
115- "license='MIT'" ,
116- "python_version='3.13'" , # Use a fixed version for test stability
117- "add_rust_extension='n'" , # Test without Rust initially, add another test session for Rust
118- # Add other variables needed by cookiecutter.json here to ensure no prompts
119- ])
165+
120166
121167 session .run (* cookiecutter_command , external = True )
122168
0 commit comments