Skip to content

Commit

Permalink
Update versioneer.py to ignore uncommited changes (PrefectHQ#15672)
Browse files Browse the repository at this point in the history
  • Loading branch information
desertaxle authored Oct 14, 2024
1 parent 17b5f7e commit e1f8844
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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]+)*)?)$
Expand Down
2 changes: 1 addition & 1 deletion src/prefect/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/prefect/utilities/dockerutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions tests/test_versioneer.py
Original file line number Diff line number Diff line change
@@ -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"
)
2 changes: 1 addition & 1 deletion tests/utilities/test_dockerutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
6 changes: 1 addition & 5 deletions versioneer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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"])
Expand Down

0 comments on commit e1f8844

Please sign in to comment.