diff --git a/.github/actions/ci/version-check/action.yml b/.github/actions/ci/version-check/action.yml index 80594e4..6277f27 100644 --- a/.github/actions/ci/version-check/action.yml +++ b/.github/actions/ci/version-check/action.yml @@ -16,13 +16,13 @@ runs: - name: Check version consistency run: | # Get reference version from pyproject.toml - REFERENCE_VERSION=$(uv run ci-version-pyproject) + REFERENCE_VERSION=$(uv run ci-pyproject-version) echo "Reference version (pyproject.toml): $REFERENCE_VERSION" MISMATCH=false # Check uv.lock - LOCK_VERSION=$(uv run ci-version-uv-lock) + LOCK_VERSION=$(uv run ci-uv-lock-version) if [ "$LOCK_VERSION" != "$REFERENCE_VERSION" ]; then echo "❌ uv.lock: $LOCK_VERSION (expected $REFERENCE_VERSION)" MISMATCH=true diff --git a/docs/WORKFLOWS.md b/docs/WORKFLOWS.md index 2a7aacb..abb1850 100644 --- a/docs/WORKFLOWS.md +++ b/docs/WORKFLOWS.md @@ -167,8 +167,8 @@ steps: - Location: `version-check/action.yml` - Steps: - Uses the `install-python-dev` action - - Extracts version from `pyproject.toml` using `uv run ci-version-pyproject` - - Verifies `uv.lock` version matches using `uv run ci-version-uv-lock` + - Extracts version from `pyproject.toml` using `uv run ci-pyproject-version` + - Verifies `uv.lock` version matches using `uv run ci-uv-lock-version` - Optionally checks additional version files via `additional-versions` input - Fails if any version mismatch is detected diff --git a/pyproject.toml b/pyproject.toml index 5138112..01fc08a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,8 +37,9 @@ dev = [ repository = "https://github.com/javidahmed64592/template-python" [project.scripts] -ci-version-pyproject = "template_python.workflows:print_version_pyproject" -ci-version-uv-lock = "template_python.workflows:print_version_uv_lock" +ci-pyproject-version = "template_python.workflows:print_version_pyproject" +ci-pyproject-name = "template_python.workflows:print_name_pyproject" +ci-uv-lock-version = "template_python.workflows:print_version_uv_lock" example-entrypoint = "template_python.main:example_function" [tool.hatch.metadata] diff --git a/template_python/workflows.py b/template_python/workflows.py index 001a6d6..eb8b547 100644 --- a/template_python/workflows.py +++ b/template_python/workflows.py @@ -27,15 +27,22 @@ def _get_version_pyproject() -> str: return str(pyproject["project"]["version"]) +@cache +def _get_name_pyproject() -> str: + """Get the name from pyproject.toml.""" + pyproject = _load_pyproject() + return str(pyproject["project"]["name"]) + + @cache def _get_version_uv_lock() -> str: """Get the version from uv.lock.""" - pyproject = _load_pyproject() + name = _get_name_pyproject() uv_lock = _load_uv_lock() - if pkg := next((p for p in uv_lock["package"] if p["name"] == pyproject["project"]["name"]), None): + if pkg := next((p for p in uv_lock["package"] if p["name"] == name), None): return str(pkg["version"]) - error_msg = f"Package '{pyproject['project']['name']}' not found in uv.lock" + error_msg = f"Package '{name}' not found in uv.lock" raise ValueError(error_msg) @@ -44,6 +51,11 @@ def print_version_pyproject() -> None: print(_get_version_pyproject()) +def print_name_pyproject() -> None: + """Get the name from pyproject.toml.""" + print(_get_name_pyproject()) + + def print_version_uv_lock() -> None: """Get the version from uv.lock.""" print(_get_version_uv_lock()) diff --git a/tests/test_workflows.py b/tests/test_workflows.py index 5dee2b7..4468b84 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -5,10 +5,12 @@ import pytest from template_python.workflows import ( + _get_name_pyproject, _get_version_pyproject, _get_version_uv_lock, _load_pyproject, _load_uv_lock, + print_name_pyproject, print_version_pyproject, print_version_uv_lock, ) @@ -26,16 +28,21 @@ def test_load_pyproject(self) -> None: def test_load_uv_lock(self) -> None: """Test loading the uv.lock file.""" - pyproject = _load_pyproject() + name = _get_name_pyproject() uv_lock = _load_uv_lock() assert "package" in uv_lock - assert any(p["name"] == pyproject["project"]["name"] for p in uv_lock["package"]) + assert any(p["name"] == name for p in uv_lock["package"]) def test_get_version_pyproject(self) -> None: """Test getting the version from pyproject.toml.""" version = _get_version_pyproject() assert isinstance(version, str) + def test_get_name_pyproject(self) -> None: + """Test getting the name from pyproject.toml.""" + name = _get_name_pyproject() + assert isinstance(name, str) + def test_get_version_uv_lock(self) -> None: """Test getting the version from uv.lock.""" version = _get_version_uv_lock() @@ -57,6 +64,10 @@ def test_print_version_pyproject(self) -> None: """Test printing the version from pyproject.toml.""" print_version_pyproject() + def test_print_name_pyproject(self) -> None: + """Test printing the name from pyproject.toml.""" + print_name_pyproject() + def test_print_version_uv_lock(self) -> None: """Test printing the version from uv.lock.""" print_version_uv_lock() diff --git a/uv.lock b/uv.lock index 1f6cfb8..b059a1b 100644 --- a/uv.lock +++ b/uv.lock @@ -753,7 +753,7 @@ requires-dist = [ { name = "pyhere", specifier = ">=1.0.3" }, { name = "pytest", marker = "extra == 'dev'", specifier = ">=9.0.2" }, { name = "pytest-cov", marker = "extra == 'dev'", specifier = ">=7.0.0" }, - { name = "ruff", marker = "extra == 'dev'", specifier = ">=0.15.4" }, + { name = "ruff", marker = "extra == 'dev'", specifier = ">=0.15.5" }, { name = "validate-pyproject", marker = "extra == 'dev'", specifier = ">=0.25.0" }, ] provides-extras = ["dev"]