Skip to content

Commit 857d916

Browse files
PUSHPAK-JAISWALulises-jeremiascursoragent
authored
added tests and fastapi typed version (#186)
* added tests and fastapi typed version * 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 <cursoragent@cursor.com> * 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 <cursoragent@cursor.com> * style: clean unused import and blank lines in catalog tests Co-authored-by: Cursor <cursoragent@cursor.com> * style: ruff format catalog fetch tests Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: ulises-jeremias <ulisescf.24@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent dc74680 commit 857d916

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

packages/create-python-app-core/src/create_python_app_core/paths.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from dataclasses import dataclass
88
from pathlib import Path
99
from urllib.parse import parse_qs, unquote, urlparse
10+
from urllib.request import url2pathname
1011

1112
from create_python_app_core.errors import CpaError
1213

@@ -54,10 +55,14 @@ def resolve_source(spec: str, *, cache_dir: Path | None = None) -> ResolvedSourc
5455
if spec.startswith("file://"):
5556
parsed = urlparse(spec)
5657
query = parse_qs(parsed.query)
57-
path = Path(unquote(parsed.path))
58+
raw_path = unquote(parsed.path or "/")
5859
if parsed.netloc and parsed.netloc != "localhost":
5960
# file://host/path — uncommon; treat netloc+path
60-
path = Path(f"/{parsed.netloc}{unquote(parsed.path)}")
61+
raw_path = f"//{parsed.netloc}{raw_path}"
62+
path_text = url2pathname(raw_path)
63+
if os.name == "nt" and re.match(r"^/[A-Za-z]:", path_text):
64+
path_text = path_text[1:]
65+
path = Path(path_text)
6166
subdir = (query.get("subdir") or [None])[0]
6267
return ResolvedSource(
6368
kind="file",

packages/create-python-app-core/tests/test_paths.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from pathlib import Path
23

34
import pytest
@@ -18,6 +19,16 @@ def test_file_url(tmp_path: Path) -> None:
1819
assert src.subdir == "templates/foo"
1920

2021

22+
def test_windows_drive_letter_file_url() -> None:
23+
if os.name != "nt":
24+
pytest.skip("Windows path handling is only relevant on Windows")
25+
26+
src = resolve_source("file:///E:/create-python/cpa-templates?subdir=templates/foo")
27+
assert src.kind == "file"
28+
assert src.subdir == "templates/foo"
29+
assert src.local_path == Path(r"E:\create-python\cpa-templates")
30+
31+
2132
def test_github_url_with_ref() -> None:
2233
src = resolve_source("https://github.com/org/repo?ref=main&subdir=templates/x")
2334
assert src.kind == "github"

0 commit comments

Comments
 (0)