From e1f88446030dfb8b4b4cb4e6c6cb12a14d03787f Mon Sep 17 00:00:00 2001 From: Alexander Streed Date: Sun, 13 Oct 2024 21:43:59 -0500 Subject: [PATCH] Update `versioneer.py` to ignore uncommited changes (#15672) --- setup.cfg | 2 +- src/prefect/_version.py | 2 +- src/prefect/utilities/dockerutils.py | 2 +- tests/test_versioneer.py | 45 ++++++++++++++++++++++++++++ tests/utilities/test_dockerutils.py | 2 +- versioneer.py | 6 +--- 6 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 tests/test_versioneer.py diff --git a/setup.cfg b/setup.cfg index da3ce4accb64..be0b6511b648 100644 --- a/setup.cfg +++ b/setup.cfg @@ -84,7 +84,7 @@ ignore_missing_imports = True [versioneer] VCS = git -style = pep440-pre +style = pep440 versionfile_source = src/prefect/_version.py versionfile_build = prefect/_version.py version_regex = ^(\d+\.\d+\.\d+(?:[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*)?)$ diff --git a/src/prefect/_version.py b/src/prefect/_version.py index 74560778d3d6..ec20917e8f2b 100644 --- a/src/prefect/_version.py +++ b/src/prefect/_version.py @@ -49,7 +49,7 @@ def get_config() -> VersioneerConfig: # _version.py cfg = VersioneerConfig() cfg.VCS = "git" - cfg.style = "pep440-pre" + cfg.style = "pep440" cfg.tag_prefix = "" cfg.parentdir_prefix = "" cfg.versionfile_source = "src/prefect/_version.py" diff --git a/src/prefect/utilities/dockerutils.py b/src/prefect/utilities/dockerutils.py index 8089899982ed..72575d81d3a0 100644 --- a/src/prefect/utilities/dockerutils.py +++ b/src/prefect/utilities/dockerutils.py @@ -57,7 +57,7 @@ def get_prefect_image_name( flavor: An optional alternative image flavor to build, like 'conda' """ parsed_version = Version(prefect_version or prefect.__version__) - is_prod_build = parsed_version.post is None + is_prod_build = parsed_version.local is None prefect_version = ( parsed_version.base_version if is_prod_build diff --git a/tests/test_versioneer.py b/tests/test_versioneer.py new file mode 100644 index 000000000000..b6257f25573c --- /dev/null +++ b/tests/test_versioneer.py @@ -0,0 +1,45 @@ +"""Tests custom changes to versioneer.py""" + +from versioneer import render_pep440 + + +def test_render_pep440_ignores_dirty(): + """ + Tests that versioneer.py's render_pep440 ignores dirty. + """ + assert ( + render_pep440( + { + "long": "3452196e283815332768b084467cba17d6d40ffa", + "short": "3452196e28", + "error": None, + "branch": "test", + "dirty": True, + "closest-tag": "0.0.1", + "distance": 0, + "date": "2024-10-12T23:30:05-0500", + } + ) + == "0.0.1" + ) + + +def test_render_pep440_ignores_respects_distance(): + """ + Tests that versioneer.py's render_pep440 still respects distance. + """ + assert ( + render_pep440( + { + "long": "3452196e283815332768b084467cba17d6d40ffa", + "short": "3452196e28", + "error": None, + "branch": "test", + "dirty": False, + "closest-tag": "0.0.1", + "distance": 1, + "date": "2024-10-12T23:30:05-0500", + } + ) + == "0.0.1+1.g3452196e28" + ) diff --git a/tests/utilities/test_dockerutils.py b/tests/utilities/test_dockerutils.py index 12c960afdc9c..69906e8de86e 100644 --- a/tests/utilities/test_dockerutils.py +++ b/tests/utilities/test_dockerutils.py @@ -31,7 +31,7 @@ ), ("3.0.0", None, None, f"prefecthq/prefect:3.0.0-python{PYTHON_VERSION}"), ( - "3.0.0.post0.dev1", + f"3.0.0+1.g{COMMIT_SHA}", None, None, f"prefecthq/prefect-dev:sha-{COMMIT_SHA}-python{PYTHON_VERSION}", diff --git a/versioneer.py b/versioneer.py index 4a427cd2e12e..3d59af5e673d 100644 --- a/versioneer.py +++ b/versioneer.py @@ -923,8 +923,6 @@ def render_pep440(pieces: Dict[str, Any]) -> str: if pieces["distance"] or pieces["dirty"]: rendered += plus_or_dot(pieces) rendered += "%%d.g%%s" %% (pieces["distance"], pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" else: # exception #1 rendered = "0+untagged.%%d.g%%s" %% (pieces["distance"], @@ -1581,11 +1579,9 @@ def render_pep440(pieces: Dict[str, Any]) -> str: """ if pieces["closest-tag"]: rendered = pieces["closest-tag"] - if pieces["distance"] or pieces["dirty"]: + if pieces["distance"]: rendered += plus_or_dot(pieces) rendered += "%d.g%s" % (pieces["distance"], pieces["short"]) - if pieces["dirty"]: - rendered += ".dirty" else: # exception #1 rendered = "0+untagged.%d.g%s" % (pieces["distance"], pieces["short"])