Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/create-python-app-core/pyproject.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ description = "Scaffolding engine for Create Awesome Python App (stub)"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"httpx>=0.28.1",
"packaging>=24.0",
]

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,8 +35,20 @@ def check_python_version(required: str, package_name: str) -> None:

async def check_for_latest_version(package_name: str) -> str | None:
"""Fetch latest version from PyPI. Returns None on failure."""
_ = package_name
return None
import httpx

url = f"https://pypi.org/pypi/{package_name}/json"
try:
async with httpx.AsyncClient(
headers={"User-Agent": CPA_USER_AGENT},
timeout=10.0,
) as client:
response = await client.get(url)
response.raise_for_status()
data = response.json()
return str(data["info"]["version"])
except Exception:
return None


def print_env_info() -> None:
Expand Down
25 changes: 25 additions & 0 deletions packages/create-python-app-core/tests/test_pypi_version.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
import pytest
from create_python_app_core.api import check_for_latest_version


@pytest.mark.asyncio
async def test_check_for_latest_version_handles_failure(
monkeypatch: pytest.MonkeyPatch,
) -> None:
import httpx

class FakeClient:
def __init__(self, *args, **kwargs):
pass

async def __aenter__(self):
return self

async def __aexit__(self, *args):
return None

async def get(self, url: str):
raise httpx.ConnectError("offline")

monkeypatch.setattr("httpx.AsyncClient", FakeClient)
assert await check_for_latest_version("create-awesome-python-app") is None
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,7 @@ dev = [
"pyright>=1.1.400",
"pre-commit>=4.0.0",
"pytest-cov>=6.0.0",
"pytest-asyncio>=0.25.0",
"pytest>=8.0.0",
]

Expand All@@ -44,6 +45,7 @@ venv = ".venv"


[tool.pytest.ini_options]
asyncio_mode = "auto"
testpaths = ["packages"]
pythonpath = ["packages/create-python-app-core/src", "packages/create-awesome-python-app/src"]

Expand Down
88 changes: 87 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.