From f84519dfe52b08215e630a7091bc9967b6424480 Mon Sep 17 00:00:00 2001 From: Pushpak-Jaiswal Date: Thu, 16 Jul 2026 23:42:19 +0530 Subject: [PATCH 1/5] added tests and fastapi typed version --- .../tests/test_catalog_fetch.py | 15 +++++++++++++++ .../src/create_python_app_core/paths.py | 9 +++++++-- .../create-python-app-core/tests/test_paths.py | 11 +++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/create-awesome-python-app/tests/test_catalog_fetch.py b/packages/create-awesome-python-app/tests/test_catalog_fetch.py index 6b225f7..0fa3781 100644 --- a/packages/create-awesome-python-app/tests/test_catalog_fetch.py +++ b/packages/create-awesome-python-app/tests/test_catalog_fetch.py @@ -3,6 +3,7 @@ from __future__ import annotations import json +import os from pathlib import Path from unittest.mock import patch @@ -18,6 +19,11 @@ FIXTURE_PATH = ( Path(__file__).resolve().parents[3] / "fixtures" / "catalog" / "templates.json" ) +REPO_ROOT = Path(__file__).resolve().parents[3] +_DEFAULT_CPA_TEMPLATES = (REPO_ROOT.parent / "cpa-templates").resolve() +CPA_TEMPLATES_ROOT = Path( + os.environ.get("CPA_TEMPLATES_ROOT", str(_DEFAULT_CPA_TEMPLATES)) +).resolve() @pytest.fixture(autouse=True) @@ -81,5 +87,14 @@ def test_get_catalog_data_disk_fallback_on_network_error( assert data["templates"][0]["slug"] == "cached" +def test_local_cpa_templates_catalog_includes_typed_fastapi_template() -> None: + catalog_path = CPA_TEMPLATES_ROOT / "templates.json" + assert catalog_path.is_file() + + payload = json.loads(catalog_path.read_text(encoding="utf-8")) + + assert any(template["slug"] == "fastapi-typed-starter" for template in payload["templates"]) + + def test_default_url_points_to_cpa_templates() -> None: assert DEFAULT_CATALOG_URL.endswith("/cpa-templates/main/templates.json") diff --git a/packages/create-python-app-core/src/create_python_app_core/paths.py b/packages/create-python-app-core/src/create_python_app_core/paths.py index dbba7bd..dd270c2 100644 --- a/packages/create-python-app-core/src/create_python_app_core/paths.py +++ b/packages/create-python-app-core/src/create_python_app_core/paths.py @@ -7,6 +7,7 @@ from dataclasses import dataclass from pathlib import Path from urllib.parse import parse_qs, unquote, urlparse +from urllib.request import url2pathname from create_python_app_core.errors import CpaError @@ -54,10 +55,14 @@ def resolve_source(spec: str, *, cache_dir: Path | None = None) -> ResolvedSourc if spec.startswith("file://"): parsed = urlparse(spec) query = parse_qs(parsed.query) - path = Path(unquote(parsed.path)) + raw_path = unquote(parsed.path or "/") if parsed.netloc and parsed.netloc != "localhost": # file://host/path — uncommon; treat netloc+path - path = Path(f"/{parsed.netloc}{unquote(parsed.path)}") + raw_path = f"//{parsed.netloc}{raw_path}" + path_text = url2pathname(raw_path) + if os.name == "nt" and re.match(r"^/[A-Za-z]:", path_text): + path_text = path_text[1:] + path = Path(path_text) subdir = (query.get("subdir") or [None])[0] return ResolvedSource( kind="file", diff --git a/packages/create-python-app-core/tests/test_paths.py b/packages/create-python-app-core/tests/test_paths.py index bd78228..102eeb1 100644 --- a/packages/create-python-app-core/tests/test_paths.py +++ b/packages/create-python-app-core/tests/test_paths.py @@ -1,3 +1,4 @@ +import os from pathlib import Path import pytest @@ -18,6 +19,16 @@ def test_file_url(tmp_path: Path) -> None: assert src.subdir == "templates/foo" +def test_windows_drive_letter_file_url() -> None: + if os.name != "nt": + pytest.skip("Windows path handling is only relevant on Windows") + + src = resolve_source("file:///E:/create-python/cpa-templates?subdir=templates/foo") + assert src.kind == "file" + assert src.subdir == "templates/foo" + assert src.local_path == Path(r"E:\create-python\cpa-templates") + + def test_github_url_with_ref() -> None: src = resolve_source("https://github.com/org/repo?ref=main&subdir=templates/x") assert src.kind == "github" From 0bdba70a4a948e4c68bcf2a98198e6c0781e503d Mon Sep 17 00:00:00 2001 From: ulises-jeremias Date: Thu, 16 Jul 2026 23:36:35 -0300 Subject: [PATCH 2/5] test: skip local cpa-templates catalog check when checkout missing CI does not have a sibling cpa-templates tree; keep the typed-starter assertion for local/dev checkouts only. Co-authored-by: Cursor --- packages/create-awesome-python-app/tests/test_catalog_fetch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/create-awesome-python-app/tests/test_catalog_fetch.py b/packages/create-awesome-python-app/tests/test_catalog_fetch.py index 0fa3781..18d8202 100644 --- a/packages/create-awesome-python-app/tests/test_catalog_fetch.py +++ b/packages/create-awesome-python-app/tests/test_catalog_fetch.py @@ -89,7 +89,8 @@ def test_get_catalog_data_disk_fallback_on_network_error( def test_local_cpa_templates_catalog_includes_typed_fastapi_template() -> None: catalog_path = CPA_TEMPLATES_ROOT / "templates.json" - assert catalog_path.is_file() + if not catalog_path.is_file(): + pytest.skip("local cpa-templates checkout not available") payload = json.loads(catalog_path.read_text(encoding="utf-8")) From ab9e5c4712270e35af95bc84ca77a4be3f34edd2 Mon Sep 17 00:00:00 2001 From: ulises-jeremias Date: Thu, 16 Jul 2026 23:39:29 -0300 Subject: [PATCH 3/5] test: drop local cpa-templates typed-starter assertion That catalog entry lives in cpa-templates#45 and is not on main yet; keep this PR focused on Windows file:// path resolution + unit tests. Co-authored-by: Cursor --- .../tests/test_catalog_fetch.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/packages/create-awesome-python-app/tests/test_catalog_fetch.py b/packages/create-awesome-python-app/tests/test_catalog_fetch.py index 18d8202..3e2f87a 100644 --- a/packages/create-awesome-python-app/tests/test_catalog_fetch.py +++ b/packages/create-awesome-python-app/tests/test_catalog_fetch.py @@ -19,13 +19,6 @@ FIXTURE_PATH = ( Path(__file__).resolve().parents[3] / "fixtures" / "catalog" / "templates.json" ) -REPO_ROOT = Path(__file__).resolve().parents[3] -_DEFAULT_CPA_TEMPLATES = (REPO_ROOT.parent / "cpa-templates").resolve() -CPA_TEMPLATES_ROOT = Path( - os.environ.get("CPA_TEMPLATES_ROOT", str(_DEFAULT_CPA_TEMPLATES)) -).resolve() - - @pytest.fixture(autouse=True) def _reset_cache(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: reset_catalog_cache_for_tests() @@ -87,15 +80,6 @@ def test_get_catalog_data_disk_fallback_on_network_error( assert data["templates"][0]["slug"] == "cached" -def test_local_cpa_templates_catalog_includes_typed_fastapi_template() -> None: - catalog_path = CPA_TEMPLATES_ROOT / "templates.json" - if not catalog_path.is_file(): - pytest.skip("local cpa-templates checkout not available") - - payload = json.loads(catalog_path.read_text(encoding="utf-8")) - - assert any(template["slug"] == "fastapi-typed-starter" for template in payload["templates"]) - def test_default_url_points_to_cpa_templates() -> None: assert DEFAULT_CATALOG_URL.endswith("/cpa-templates/main/templates.json") From 21cd3bf571642d3609bb5dbe4a3092c64da109a9 Mon Sep 17 00:00:00 2001 From: ulises-jeremias Date: Thu, 16 Jul 2026 23:39:40 -0300 Subject: [PATCH 4/5] style: clean unused import and blank lines in catalog tests Co-authored-by: Cursor --- packages/create-awesome-python-app/tests/test_catalog_fetch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/create-awesome-python-app/tests/test_catalog_fetch.py b/packages/create-awesome-python-app/tests/test_catalog_fetch.py index 3e2f87a..ed30428 100644 --- a/packages/create-awesome-python-app/tests/test_catalog_fetch.py +++ b/packages/create-awesome-python-app/tests/test_catalog_fetch.py @@ -3,7 +3,6 @@ from __future__ import annotations import json -import os from pathlib import Path from unittest.mock import patch @@ -19,6 +18,8 @@ FIXTURE_PATH = ( Path(__file__).resolve().parents[3] / "fixtures" / "catalog" / "templates.json" ) + + @pytest.fixture(autouse=True) def _reset_cache(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: reset_catalog_cache_for_tests() From 2e67a6a96ff5024ea76041e657046ae2eff7b29c Mon Sep 17 00:00:00 2001 From: ulises-jeremias Date: Thu, 16 Jul 2026 23:40:59 -0300 Subject: [PATCH 5/5] style: ruff format catalog fetch tests Co-authored-by: Cursor --- packages/create-awesome-python-app/tests/test_catalog_fetch.py | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/create-awesome-python-app/tests/test_catalog_fetch.py b/packages/create-awesome-python-app/tests/test_catalog_fetch.py index ed30428..6b225f7 100644 --- a/packages/create-awesome-python-app/tests/test_catalog_fetch.py +++ b/packages/create-awesome-python-app/tests/test_catalog_fetch.py @@ -81,6 +81,5 @@ def test_get_catalog_data_disk_fallback_on_network_error( assert data["templates"][0]["slug"] == "cached" - def test_default_url_points_to_cpa_templates() -> None: assert DEFAULT_CATALOG_URL.endswith("/cpa-templates/main/templates.json")