|
1 | 1 | """Nox sessions.""" |
2 | 2 |
|
| 3 | +from __future__ import annotations |
| 4 | + |
3 | 5 | from pathlib import Path |
4 | 6 | import shutil |
5 | 7 |
|
|
8 | 10 | from nox.sessions import Session |
9 | 11 |
|
10 | 12 |
|
| 13 | +python_versions = ["3.12", "3.11", "3.10", "3.9"] |
| 14 | + |
11 | 15 | nox.options.sessions = ["docs"] |
12 | | -owner, repository = "cjolowicz", "cookiecutter-hypermodern-python" |
| 16 | +owner, repository = "56kyle", "cookiecutter-hypermodern-python" |
13 | 17 | labels = "cookiecutter", "documentation" |
14 | 18 | bump_paths = "README.md", "docs/guide.rst", "docs/index.rst", "docs/quickstart.md" |
15 | 19 |
|
16 | | -REPO_ROOT: Path = Path(__file__).parent |
17 | | -NEXTGEN_STARTER_CACHE_FOLDER: Path = platformdirs.user_cache_path( |
18 | | - appname="cookiecutter-hypermodern-python", |
19 | | - appauthor="56kyle", |
20 | | - ensure_exists=True |
21 | | -) |
| 20 | +REPO_ROOT: Path = Path(__file__).parent.resolve() |
| 21 | +TEMPLATE_FOLDER: Path = REPO_ROOT / "{{cookiecutter.project_name}}" |
| 22 | + |
| 23 | + |
| 24 | +COOKIECUTTER_HYPERMODERN_PYTHON_CACHE_FOLDER: Path = Path( |
| 25 | + platformdirs.user_cache_path( |
| 26 | + appname="cookiecutter-hypermodern-python", |
| 27 | + appauthor="56kyle", |
| 28 | + ensure_exists=True, |
| 29 | + ) |
| 30 | +).resolve() |
22 | 31 |
|
23 | | -PROJECT_DEMOS_FOLDER: Path = NEXTGEN_STARTER_CACHE_FOLDER / "project_demos" |
| 32 | +PROJECT_DEMOS_FOLDER: Path = COOKIECUTTER_HYPERMODERN_PYTHON_CACHE_FOLDER / "project_demos" |
24 | 33 | DEFAULT_DEMO_NAME: str = "demo-project" |
| 34 | +DEMO_ROOT_FOLDER: Path = PROJECT_DEMOS_FOLDER / DEFAULT_DEMO_NAME |
25 | 35 |
|
| 36 | +GENERATE_DEMO_PROJECT_OPTIONS: tuple[str, ...] = ( |
| 37 | + *("--repo-folder", REPO_ROOT), |
| 38 | + *("--demos-cache-folder", PROJECT_DEMOS_FOLDER), |
| 39 | + *("--demo-name", DEFAULT_DEMO_NAME), |
| 40 | +) |
| 41 | + |
| 42 | +SYNC_POETRY_WITH_DEMO_OPTIONS: tuple[str, ...] = ( |
| 43 | + *("--template-folder", TEMPLATE_FOLDER), |
| 44 | + *("--demos-cache-folder", PROJECT_DEMOS_FOLDER), |
| 45 | + *("--demo-name", DEFAULT_DEMO_NAME), |
| 46 | +) |
26 | 47 |
|
27 | | -@nox.session(name="generate-demo-project") |
28 | | -def generate_demo_project(session: Session) -> Session: |
29 | | - pass |
| 48 | + |
| 49 | +@nox.session(name="generate-demo-project", python=python_versions[-1]) |
| 50 | +def generate_demo_project(session: Session) -> None: |
| 51 | + session.install("cookiecutter", "platformdirs", "loguru") |
| 52 | + session.run( |
| 53 | + "python", |
| 54 | + "tools/generate-demo-project.py", |
| 55 | + *GENERATE_DEMO_PROJECT_OPTIONS, |
| 56 | + external=True, |
| 57 | + ) |
| 58 | + |
| 59 | + |
| 60 | +@nox.session(name="sync-poetry-with-demo", python=python_versions[-1]) |
| 61 | +def sync_poetry_with_demo(session: Session) -> None: |
| 62 | + session.install("cookiecutter", "platformdirs", "loguru") |
| 63 | + session.run( |
| 64 | + "python", |
| 65 | + "tools/sync-poetry-with-demo.py", |
| 66 | + *SYNC_POETRY_WITH_DEMO_OPTIONS, |
| 67 | + external=True, |
| 68 | + ) |
| 69 | + |
| 70 | + |
| 71 | +@nox.session(name="poetry-in-demo", python=python_versions[-1]) |
| 72 | +def poetry_in_demo(session: Session) -> None: |
| 73 | + session.install("cookiecutter", "platformdirs", "loguru") |
| 74 | + session.run( |
| 75 | + "python", |
| 76 | + "tools/generate-demo-project.py", |
| 77 | + *GENERATE_DEMO_PROJECT_OPTIONS, |
| 78 | + external=True, |
| 79 | + ) |
| 80 | + original_dir: Path = Path.cwd() |
| 81 | + session.cd(DEMO_ROOT_FOLDER) |
| 82 | + session.run("poetry", *session.posargs) |
| 83 | + session.cd(original_dir) |
| 84 | + session.run( |
| 85 | + "python", |
| 86 | + "tools/sync-poetry-with-demo.py", |
| 87 | + *SYNC_POETRY_WITH_DEMO_OPTIONS, |
| 88 | + external=True, |
| 89 | + ) |
| 90 | + |
| 91 | + |
| 92 | +@nox.session(name="poetry-lock") |
| 93 | +def poetry_lock(session: Session) -> None: |
| 94 | + """Shorthand for poetry-in-demo -- lock.""" |
| 95 | + session._runner.posargs = ["lock", *session.posargs] |
| 96 | + poetry_in_demo(session) |
| 97 | + |
| 98 | + |
| 99 | +@nox.session(name="poetry-update") |
| 100 | +def poetry_update(session: Session) -> None: |
| 101 | + """Shorthand for poetry-in-demo -- update.""" |
| 102 | + session._runner.posargs = ["update", *session.posargs] |
| 103 | + poetry_in_demo(session) |
30 | 104 |
|
31 | 105 |
|
32 | 106 | @nox.session(name="prepare-release") |
@@ -77,7 +151,14 @@ def docs(session: Session) -> None: |
77 | 151 | @nox.session |
78 | 152 | def linkcheck(session: Session) -> None: |
79 | 153 | """Build the documentation.""" |
80 | | - args = session.posargs or ["-b", "linkcheck", "-W", "--keep-going", "docs", "docs/_build"] |
| 154 | + args = session.posargs or [ |
| 155 | + "-b", |
| 156 | + "linkcheck", |
| 157 | + "-W", |
| 158 | + "--keep-going", |
| 159 | + "docs", |
| 160 | + "docs/_build", |
| 161 | + ] |
81 | 162 |
|
82 | 163 | builddir = Path("docs", "_build") |
83 | 164 | if builddir.exists(): |
|
0 commit comments