2929PACKAGE_NAME : str = "{{cookiecutter.package_name}}"
3030GITHUB_USER : str = "{{cookiecutter.github_user}}"
3131
32-
33- @nox .session (python = None , name = "setup-repo" )
34- def setup_repo (session : Session ) -> None :
35- """Set up the repository for development.
36-
37- Really this should only ever be used once upon repo creation. However, it is helpful to use in generating fake repos
38- for use in testing the template itself.
39- """
40- session .log ("Installing development dependencies..." )
41- session .notify ("setup-git" )
42- session .notify ("setup-venv" )
43-
44-
45- @nox .session (python = None , name = "setup-git" )
32+ ENV : str = "env"
33+ STYLE : str = "style"
34+ LINT : str = "lint"
35+ TYPE : str = "type"
36+ TEST : str = "test"
37+ COVERAGE : str = "coverage"
38+ SECURITY : str = "security"
39+ PERF : str = "perf"
40+ DOCS : str = "docs"
41+ BUILD : str = "build"
42+ RELEASE : str = "release"
43+ MAINTENANCE : str = "maintenance"
44+ CI : str = "ci"
45+
46+
47+ @nox .session (python = None , name = "setup-git" , tags = [ENV ])
4648def setup_git (session : Session ) -> None :
4749 """Set up the git repo for the current project."""
4850 session .run (
4951 "python" , SCRIPTS_FOLDER / "setup-git.py" , REPO_ROOT , "-u" , GITHUB_USER , "-n" , PACKAGE_NAME , external = True
5052 )
5153
5254
53- @nox .session (python = None , name = "setup-venv" )
55+ @nox .session (python = None , name = "setup-venv" , tags = [ ENV ] )
5456def setup_venv (session : Session ) -> None :
5557 """Set up the virtual environment for the current project."""
5658 session .run ("python" , SCRIPTS_FOLDER / "setup-venv.py" , REPO_ROOT , "-p" , PYTHON_VERSIONS [0 ], external = True )
@@ -69,68 +71,7 @@ def precommit(session: Session) -> None:
6971 activate_virtualenv_in_precommit_hooks (session )
7072
7173
72- @nox .session (python = None , name = "format" )
73- def _format (session : Session ) -> None :
74- """Run all formatting checks (Ruff, Pydocstyle)."""
75- session .log ("Installing formatting dependencies..." )
76- if "format_rust" in dir ():
77- session .notify ("format-rust" )
78- session .notify ("format-python" )
79-
80-
81- @nox .session (python = DEFAULT_PYTHON_VERSION , name = "format-python" )
82- def format_python (session : Session ) -> None :
83- """Run Python code formatter (Ruff format)."""
84- session .log ("Installing formatting dependencies..." )
85- session .install ("-e" , "." , "--group" , "dev" , "--group" , "lint" )
86-
87- session .log (f"Running Ruff formatter check with py{ session .python } ." )
88- # Use --check, not fix. Fixing is done by pre-commit or manual run.
89- session .run ("ruff" , "format" , * session .posargs )
90-
91-
92- {% if cookiecutter .add_rust_extension == "y" - % }
93- @nox .session (python = None , name = "format-rust" )
94- def format_rust (session : Session ) -> None :
95- """Run Rust code formatter (cargo fmt)."""
96- session .log ("Installing formatting dependencies..." )
97- session .run ("cargo" , "install" , "cargo-fmt" , external = True )
98- session .run ("cargo" , "fmt" , "--all" , "--" , "--check" , external = True )
99- session .run ("cargo" , "fmt" , "--all" , "--" , "--write" , external = True )
100-
101-
102- {% endif - % }
103- @nox .session (python = None , name = "lint" )
104- def lint (session : Session ) -> None :
105- """Run all linting checks (Ruff, Pydocstyle)."""
106- session .log ("Installing linting dependencies..." )
107- if "lint_rust" in dir ():
108- session .notify ("lint-rust" )
109- session .notify ("lint-python" )
110-
111-
112- @nox .session (python = DEFAULT_PYTHON_VERSION , name = "lint-python" )
113- def lint_python (session : Session ) -> None :
114- """Run Python code linters (Ruff check, Pydocstyle rules)."""
115- session .log ("Installing linting dependencies..." )
116- session .install ("-e" , "." , "--group" , "dev" , "--group" , "lint" )
117-
118- session .log (f"Running Ruff check with py{ session .python } ." )
119- session .run ("ruff" , "check" , "--verbose" )
120-
121-
122- {% if cookiecutter .add_rust_extension == "y" - % }
123- @nox .session (python = None , name = "lint-rust" )
124- def lint_rust (session : Session ) -> None :
125- """Run Rust code linters (cargo clippy)."""
126- session .log ("Installing linting dependencies..." )
127- session .run ("cargo" , "install" , "cargo-clippy" , external = True )
128- session .run ("cargo" , "clippy" , "--all-features" , "--" , "--check" , external = True )
129- session .run ("cargo" , "clippy" , "--all-features" , "--" , "--write" , external = True )
130-
131-
132- {% endif - % }
133- @nox .session (python = PYTHON_VERSIONS )
74+ @nox .session (python = PYTHON_VERSIONS , name = "typecheck" , tags = [TYPE ])
13475def typecheck (session : Session ) -> None :
13576 """Run static type checking (Pyright) on Python code."""
13677 session .log ("Installing type checking dependencies..." )
@@ -140,16 +81,7 @@ def typecheck(session: Session) -> None:
14081 session .run ("pyright" )
14182
14283
143- @nox .session (python = None , name = "security" )
144- def security (session : Session ) -> None :
145- """Run code security checks."""
146- session .log ("Installing security dependencies..." )
147- if "security_rust" in dir ():
148- session .notify ("security-rust" )
149- session .notify ("security-python" )
150-
151-
152- @nox .session (python = DEFAULT_PYTHON_VERSION , name = "security-python" )
84+ @nox .session (python = DEFAULT_PYTHON_VERSION , name = "security-python" , tags = [SECURITY ])
15385def security_python (session : Session ) -> None :
15486 """Run code security checks (Bandit) on Python code."""
15587 session .log ("Installing security dependencies..." )
@@ -163,7 +95,7 @@ def security_python(session: Session) -> None:
16395
16496
16597{% if cookiecutter .add_rust_extension == 'y' - % }
166- @nox .session (python = None , name = "security-rust" )
98+ @nox .session (python = None , name = "security-rust" , tags = [ SECURITY ] )
16799def security_rust (session : Session ) -> None :
168100 """Run code security checks (cargo audit)."""
169101 session .log ("Installing security dependencies..." )
@@ -172,15 +104,7 @@ def security_rust(session: Session) -> None:
172104
173105
174106{% endif - % }
175- @nox .session (python = None , name = "tests" )
176- def tests (session : Session ) -> None :
177- """Run all Python and Rust tests."""
178- if "tests_rust" in dir ():
179- session .notify ("tests-rust" )
180- session .notify ("tests-python" )
181-
182-
183- @nox .session (python = PYTHON_VERSIONS , name = "tests-python" )
107+ @nox .session (python = PYTHON_VERSIONS , name = "tests-python" , tags = [TEST ])
184108def tests_python (session : Session ) -> None :
185109 """Run the Python test suite (pytest with coverage)."""
186110 session .log ("Installing test dependencies..." )
@@ -201,7 +125,7 @@ def tests_python(session: Session) -> None:
201125
202126
203127{% if cookiecutter .add_rust_extension == 'y' - % }
204- @nox .session (python = None , name = "tests-rust" )
128+ @nox .session (python = None , name = "tests-rust" , tags = [ TEST ] )
205129def tests_rust (session : Session ) -> None :
206130 """Test the project's rust crates."""
207131 crates : list [Path ] = [cargo_toml .parent for cargo_toml in CRATES_FOLDER .glob ("*/Cargo.toml" )]
@@ -211,7 +135,7 @@ def tests_rust(session: Session) -> None:
211135
212136
213137{% endif - % }
214- @nox .session (python = DEFAULT_PYTHON_VERSION , name = "docs-build" )
138+ @nox .session (python = DEFAULT_PYTHON_VERSION , name = "docs-build" , tags = [ DOCS , BUILD ] )
215139def docs_build (session : Session ) -> None :
216140 """Build the project documentation (Sphinx)."""
217141 session .log ("Installing documentation dependencies..." )
@@ -227,15 +151,7 @@ def docs_build(session: Session) -> None:
227151 session .run ("sphinx-build" , "-b" , "html" , "docs" , str (docs_build_dir ), "-W" )
228152
229153
230- @nox .session (python = None , name = "build" )
231- def build (session : Session ) -> None :
232- """Build the project artifacts (Python packages, Rust crates)."""
233- if "build_rust" in dir ():
234- session .notify ("build-rust" )
235- session .notify ("build-python" )
236-
237-
238- @nox .session (python = DEFAULT_PYTHON_VERSION , name = "build-python" )
154+ @nox .session (python = DEFAULT_PYTHON_VERSION , name = "build-python" , tags = [BUILD ])
239155def build_python (session : Session ) -> None :
240156 """Build sdist and wheel packages (uv build)."""
241157 session .log ("Installing build dependencies..." )
@@ -254,7 +170,7 @@ def build_python(session: Session) -> None:
254170 session .log (f"- { path .name } " )
255171
256172
257- @nox .session (python = DEFAULT_PYTHON_VERSION , name = "build-container" )
173+ @nox .session (python = DEFAULT_PYTHON_VERSION , name = "build-container" , tags = [ BUILD ] )
258174def build_container (session : Session ) -> None :
259175 """Build the Docker container image.
260176
@@ -285,15 +201,7 @@ def build_container(session: Session) -> None:
285201 session .log (f"Container image { project_image_name } :latest built locally." )
286202
287203
288- @nox .session (python = None , name = "publish" )
289- def publish (session : Session ) -> None :
290- """Publish the project artifacts (Python packages, Rust crates)."""
291- if "publish_rust" in dir ():
292- session .notify ("publish-rust" )
293- session .notify ("publish-python" )
294-
295-
296- @nox .session (python = DEFAULT_PYTHON_VERSION , name = "publish-python" )
204+ @nox .session (python = DEFAULT_PYTHON_VERSION , name = "publish-python" , tags = [RELEASE ])
297205def publish_python (session : Session ) -> None :
298206 """Publish sdist and wheel packages to PyPI via uv publish.
299207
@@ -310,7 +218,7 @@ def publish_python(session: Session) -> None:
310218
311219
312220{% if cookiecutter .add_rust_extension == "y" - % }
313- @nox .session (python = None , name = "publish-rust" )
221+ @nox .session (python = None , name = "publish-rust" , tags = [ RELEASE ] )
314222def publish_rust (session : Session ) -> None :
315223 """Publish built crates to crates.io."""
316224 session .log ("Publishing crates to crates.io" )
@@ -320,7 +228,7 @@ def publish_rust(session: Session) -> None:
320228
321229
322230{% endif - % }
323- @nox .session (venv_backend = "none" )
231+ @nox .session (venv_backend = "none" , tags = [ RELEASE ] )
324232def release (session : Session ) -> None :
325233 """Run the release process using Commitizen.
326234
@@ -359,10 +267,7 @@ def release(session: Session) -> None:
359267 )
360268
361269
362- # --- COMPATIBILITY SESSIONS ---
363- # Sessions needed for compatibility with other tools or ecosystems.
364-
365- @nox .session (venv_backend = "none" )
270+ @nox .session (venv_backend = "none" , tags = [MAINTENANCE ])
366271def tox (session : Session ) -> None :
367272 """Run the 'tox' test matrix.
368273
@@ -385,47 +290,7 @@ def tox(session: Session) -> None:
385290 session .run ("tox" , * session .posargs )
386291
387292
388- # --- COMBINED/ORCHESTRATION SESSIONS ---
389- # These sessions provide easy entry points by notifying or calling granular sessions.
390- # Their names often align with the intended CI workflow steps (e.g., 'build' orchestrates builds).
391-
392- @nox .session (python = None ) # Run the orchestrator on the default Python version
393- def build (session : Session ) -> None :
394- """Orchestrates building all project artifacts (Python packages, potentially Rust)."""
395- session .log (f"Queueing build sessions for py{ session .python } if applicable." )
396- if "build_rust" in dir ():
397- session .notify ("build-rust" )
398- session .notify ("build-python" )
399-
400-
401- @nox .session (python = None ) # Run the orchestrator on the default Python version
402- def publish (session : Session ) -> None :
403- """Orchestrates publishing all project artifacts (Python packages, potentially Rust)."""
404- session .log (f"Queueing publish sessions for py{ session .python } if applicable." )
405- if "publish_rust" in dir ():
406- session .notify ("publish-rust" )
407- session .notify ("publish-python" )
408-
409-
410- @nox .session (python = None )
411- def check (session : Session ) -> None :
412- """Run primary quality checks (format, lint, typecheck, security)."""
413- session .log (f"Queueing core check sessions for py{ session .python } if applicable." )
414- session .notify ("format" )
415- session .notify ("lint" )
416- session .notify ("typecheck" )
417- session .notify ("security-python" )
418-
419-
420- @nox .session (python = None , name = "full-check" )
421- def full_check (session : Session ) -> None :
422- """Run all core quality checks and tests."""
423- session .log (f"Queueing all check and test sessions for py{ session .python } if applicable." )
424- session .notify ("check" )
425- session .notify ("tests-python" )
426-
427-
428- @nox .session (python = DEFAULT_PYTHON_VERSION )
293+ @nox .session (python = DEFAULT_PYTHON_VERSION , tags = [COVERAGE ])
429294def coverage (session : Session ) -> None :
430295 """Collect and report coverage.
431296
0 commit comments