From ad1d41190cafe61588449500901b990f72ba1d01 Mon Sep 17 00:00:00 2001 From: Arthur Pastel Date: Mon, 9 Dec 2024 10:41:35 +0100 Subject: [PATCH] refactor: remove the scripted semver generation --- pyproject.toml | 1 - scripts/generate_semver.py | 41 ----------------------------------- tests/test_generate_semver.py | 19 ---------------- 3 files changed, 61 deletions(-) delete mode 100644 scripts/generate_semver.py delete mode 100644 tests/test_generate_semver.py diff --git a/pyproject.toml b/pyproject.toml index 67bf8d1..8b152a6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,6 @@ dependencies = [ ] [project.optional-dependencies] -build = ["semver>=3.0.2"] lint = ["mypy ~= 1.11.2", "ruff ~= 0.6.5"] compat = [ "pytest-benchmark ~= 5.0.0", diff --git a/scripts/generate_semver.py b/scripts/generate_semver.py deleted file mode 100644 index 98372b2..0000000 --- a/scripts/generate_semver.py +++ /dev/null @@ -1,41 +0,0 @@ -""" -This script converts a PyPI version string to a semantic version string and updates the -__semver_version__ variable in the __init__.py file of the pytest_codspeed package. -""" - -import re -from pathlib import Path - -from packaging.version import Version as PyPIVersion -from semver import Version as SemVerVersion - - -def pypi_version_to_semver(pypi_version_str: str) -> str: - py_version = PyPIVersion(pypi_version_str) - if py_version.epoch != 0: - raise ValueError("Can't convert an epoch to semver") - if py_version.post is not None: - raise ValueError("Can't convert a post part to semver") - - pre = None if not py_version.pre else "".join([str(i) for i in py_version.pre]) - semver = SemVerVersion(*py_version.release, prerelease=pre, build=py_version.dev) - return str(semver) - - -def main(): - from pytest_codspeed import __version__ as pypi_version - - semver_version = pypi_version_to_semver(pypi_version) - init_file_path = Path("./src/pytest_codspeed/__init__.py") - content = init_file_path.read_text() - - content = re.sub( - r'__semver_version__\s*=\s*".*"', - f'__semver_version__ = "{semver_version}"', - content, - ) - init_file_path.write_text(content) - - -if __name__ == "__main__": - main() diff --git a/tests/test_generate_semver.py b/tests/test_generate_semver.py deleted file mode 100644 index b2a8c24..0000000 --- a/tests/test_generate_semver.py +++ /dev/null @@ -1,19 +0,0 @@ -import pytest -from generate_semver import pypi_version_to_semver - - -def test_pypi_version_to_semver_valid(): - # Test cases for valid PyPI version strings - assert pypi_version_to_semver("1.0.0") == "1.0.0" - assert pypi_version_to_semver("1.0.0a1") == "1.0.0-a1" - assert pypi_version_to_semver("1.0.0b1") == "1.0.0-b1" - assert pypi_version_to_semver("1.0.0rc1") == "1.0.0-rc1" - - -def test_pypi_version_to_semver_invalid(): - # Test cases for invalid PyPI version strings that should raise ValueError - with pytest.raises(ValueError, match="Can't convert an epoch to semver"): - pypi_version_to_semver("1!1.0.0") - - with pytest.raises(ValueError, match="Can't convert a post part to semver"): - pypi_version_to_semver("1.0.0.post")