|
6 | 6 |
|
7 | 7 | import os |
8 | 8 | import shutil |
| 9 | +from dataclasses import asdict |
| 10 | +from dataclasses import dataclass |
9 | 11 | from pathlib import Path |
| 12 | +from typing import Any |
10 | 13 |
|
11 | 14 | import nox |
12 | 15 | import platformdirs |
|
66 | 69 | ) |
67 | 70 |
|
68 | 71 |
|
| 72 | +@dataclass |
| 73 | +class RepoMetadata: |
| 74 | + """Metadata for a given repo.""" |
| 75 | + app_name: str |
| 76 | + app_author: str |
| 77 | + remote: str |
| 78 | + main_branch: str |
| 79 | + develop_branch: str |
| 80 | + |
| 81 | + |
| 82 | +TEMPLATE: RepoMetadata = RepoMetadata( |
| 83 | + app_name=os.getenv("COOKIECUTTER_ROBUST_PYTHON__APP_NAME"), |
| 84 | + app_author=os.getenv("COOKIECUTTER_ROBUST_PYTHON__APP_AUTHOR"), |
| 85 | + remote=os.getenv("COOKIECUTTER_ROBUST_PYTHON__REMOTE"), |
| 86 | + main_branch=os.getenv("COOKIECUTTER_ROBUST_PYTHON__MAIN_BRANCH"), |
| 87 | + develop_branch=os.getenv("COOKIECUTTER_ROBUST_PYTHON__DEVELOP_BRANCH") |
| 88 | +) |
| 89 | + |
| 90 | +PYTHON_DEMO: RepoMetadata = RepoMetadata( |
| 91 | + app_name=os.getenv("ROBUST_PYTHON_DEMO__APP_NAME"), |
| 92 | + app_author=os.getenv("ROBUST_PYTHON_DEMO__APP_AUTHOR"), |
| 93 | + remote=os.getenv("ROBUST_PYTHON_DEMO__REMOTE"), |
| 94 | + main_branch=os.getenv("ROBUST_PYTHON_DEMO__MAIN_BRANCH"), |
| 95 | + develop_branch=os.getenv("ROBUST_PYTHON_DEMO__DEVELOP_BRANCH") |
| 96 | +) |
| 97 | + |
| 98 | +MATURIN_DEMO: RepoMetadata = RepoMetadata( |
| 99 | + app_name=os.getenv("ROBUST_MATURIN_DEMO__APP_NAME"), |
| 100 | + app_author=os.getenv("ROBUST_MATURIN_DEMO__APP_AUTHOR"), |
| 101 | + remote=os.getenv("ROBUST_MATURIN_DEMO__REMOTE"), |
| 102 | + main_branch=os.getenv("ROBUST_MATURIN_DEMO__MAIN_BRANCH"), |
| 103 | + develop_branch=os.getenv("ROBUST_MATURIN_DEMO__DEVELOP_BRANCH") |
| 104 | +) |
| 105 | + |
| 106 | + |
69 | 107 | @nox.session(python=DEFAULT_TEMPLATE_PYTHON_VERSION, name="generate-demo") |
70 | 108 | def generate_demo(session: Session) -> None: |
71 | 109 | """Generates a project demo using the cookiecutter-robust-python template.""" |
@@ -143,17 +181,26 @@ def test(session: Session) -> None: |
143 | 181 | session.run("pytest", "tests") |
144 | 182 |
|
145 | 183 |
|
146 | | -@nox.parametrize(arg_names="add_rust_extension", arg_values_list=[False, True], ids=["no-rust", "rust"]) |
| 184 | +@nox.parametrize( |
| 185 | + arg_names="demo", |
| 186 | + arg_values_list=[PYTHON_DEMO, MATURIN_DEMO], |
| 187 | + ids=["robust-python-demo", "robust-maturin-demo"] |
| 188 | +) |
147 | 189 | @nox.session(python=DEFAULT_TEMPLATE_PYTHON_VERSION, name="update-demo") |
148 | | -def update_demo(session: Session, add_rust_extension: bool) -> None: |
| 190 | +def update_demo(session: Session, demo: RepoMetadata) -> None: |
149 | 191 | session.log("Installing script dependencies for updating generated project demos...") |
150 | 192 | session.install("cookiecutter", "cruft", "platformdirs", "loguru", "python-dotenv", "typer") |
151 | 193 |
|
152 | 194 | session.log("Updating generated project demos...") |
153 | 195 | args: list[str] = [*UPDATE_DEMO_OPTIONS] |
154 | | - if add_rust_extension: |
| 196 | + if "maturin" in demo.app_name: |
155 | 197 | args.append("--add-rust-extension") |
156 | | - session.run("python", UPDATE_DEMO_SCRIPT, *args) |
| 198 | + |
| 199 | + if session.posargs: |
| 200 | + args.extend(session.posargs) |
| 201 | + |
| 202 | + demo_env: dict[str, Any] = {f"ROBUST_DEMO__{key.upper()}": value for key, value in asdict(demo).items()} |
| 203 | + session.run("python", UPDATE_DEMO_SCRIPT, *args, env=demo_env) |
157 | 204 |
|
158 | 205 |
|
159 | 206 | @nox.session(python=False, name="release-template") |
|
0 commit comments