Skip to content

Commit 128cfd5

Browse files
committed
feat: add syncing generated project to existing uv.lock
1 parent c3aca2a commit 128cfd5

File tree

4 files changed

+1589
-8
lines changed

4 files changed

+1589
-8
lines changed

noxfile.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
nox.options.default_venv_backend = "uv"
1515

16-
DEFAULT_TEMPLATE_PYTHON_VERSION = "3.13"
16+
DEFAULT_TEMPLATE_PYTHON_VERSION = "3.9"
1717

1818
REPO_ROOT: Path = Path(__file__).parent.resolve()
1919
TEMPLATE_FOLDER: Path = REPO_ROOT / "{{cookiecutter.project_name}}"
@@ -37,6 +37,12 @@
3737
*("--demo-name", DEFAULT_DEMO_NAME),
3838
)
3939

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+
)
45+
4046
TEMPLATE_PYTHON_LOCATIONS: tuple[Path, ...] = (
4147
Path("noxfile.py"),
4248
)
@@ -68,6 +74,37 @@ def generate_demo_project(session: Session) -> None:
6874
)
6975

7076

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+
)
106+
107+
71108
@nox.session(python=DEFAULT_TEMPLATE_PYTHON_VERSION)
72109
def lint(session: Session):
73110
"""Lint the template's own Python files and configurations."""

scripts/sync-uv-with-demo.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import sys
55
from functools import partial
66
from pathlib import Path
7+
from typing import Annotated
78

89
import typer
910

1011
from typer.models import OptionInfo
1112

1213
from loguru import logger
1314

14-
1515
FolderOption: partial[OptionInfo] = partial(
1616
typer.Option, dir_okay=True, file_okay=False, resolve_path=True, path_type=Path
1717
)
@@ -28,7 +28,6 @@ def sync_uv_with_demo(template_folder: Path, demos_cache_folder: Path, demo_name
2828
logger.info(f"Copied demo from {demo_uv_lock_path=} to {output_uv_lock_path=}.")
2929

3030

31-
3231
def _copy_uv_lock_from_demo(demo_uv_lock_path: Path, output_uv_lock_path: Path) -> None:
3332
"""Copies over the uv.lock file from the provided demo project root."""
3433
shutil.copy(
@@ -48,8 +47,8 @@ def _find_uv_lock_path(search_root: Path) -> Path:
4847

4948
@cli.callback(invoke_without_command=True)
5049
def main(
51-
template_folder: Annotated[Path, FolderOption("--template-folder", "-t", exist=True)],
52-
demos_cache_folder: Annotated[Path, FolderOption("--demos-cache-folder", "-c", exist=True)],
50+
template_folder: Annotated[Path, FolderOption("--template-folder", "-t", exists=True)],
51+
demos_cache_folder: Annotated[Path, FolderOption("--demos-cache-folder", "-c", exists=True)],
5352
demo_name: Annotated[str, typer.Option("--demo-name", "-d")]
5453
) -> None:
5554
"""Updates the uv.lock file."""
@@ -58,7 +57,7 @@ def main(
5857
template_folder=template_folder, demos_cache_folder=demos_cache_folder, demo_name=demo_name
5958
)
6059
except Exception as error:
61-
click.secho(f"error: {error}", fg="red")
60+
typer.secho(f"error: {error}", fg="red")
6261
sys.exit(1)
6362

6463

{{cookiecutter.project_name}}/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ classifiers = [
2020
]
2121

2222
dependencies = [
23-
# Add core production dependencies here, e.g.,
24-
# "requests>=2.31.0",
23+
"loguru",
24+
"platformdirs>=4.3.8",
2525
]
2626

2727
[project.optional-dependencies]

0 commit comments

Comments
 (0)