From 5b2a9664cfec558ec9f72a24d5181e4ae708b219 Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Tue, 30 Jul 2024 09:07:21 +0200 Subject: [PATCH 1/3] Fix setuptools_scm version retrieval for detached HEAD --- setup.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/setup.py b/setup.py index 473fec7..a8231e5 100644 --- a/setup.py +++ b/setup.py @@ -11,14 +11,13 @@ def version_scheme(version) -> str: Used by setuptools_scm. """ - if version.branch == RELEASE_BRANCH: - if version.distance == 0: - # If the current commit is on the release branch and has a GIT tag, - # use the tag as version: - return f"{version.tag}" - else: - # For untagged commits always add a distance like ".post3" - return f"{version.tag}.post{version.distance}" + if version.tag and version.distance == 0: + # If the current commit has a tag, use the tag as version, regardless of branch. + # Note: Github CI creates releases from detached HEAD, not from a particular branch. + return f"{version.tag}" + elif version.branch == RELEASE_BRANCH and version.tag and version.distance > 0: + # For untagged commits on the release branch always add a distance like ".post3" + return f"{version.tag}.post{version.distance}" else: # For non-release branches, make the version as dev and distance: return f"{version.tag}.dev{version.distance}" @@ -29,16 +28,14 @@ def local_scheme(version) -> str: Used by setuptools_scm. """ - # If current version is dirty, always add dirty tag, regardless of branch. + # If current version is dirty, always add dirty suffix, regardless of branch. dirty_tag = get_local_dirty_tag(version) if version.dirty else "" if dirty_tag: return f"{dirty_tag}.{version.node}" - if version.branch == RELEASE_BRANCH: - if version.distance == 0: - # no local component for versions on the main release branch: - # will create simple versions like 4.1.0 - return "" + if version.distance == 0: + # If the current commit has a tag, do not add a local component, regardless of branch. + return "" # For all other cases, always add the git reference (like "g7839952") return f"+{version.node}" From d9cd1f51ed0a239c85808147d30907e91e44a28e Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Tue, 30 Jul 2024 09:13:40 +0200 Subject: [PATCH 2/3] minor fix --- setup.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup.py b/setup.py index a8231e5..b076ea9 100644 --- a/setup.py +++ b/setup.py @@ -3,8 +3,6 @@ from setuptools import setup from setuptools_scm.version import get_local_dirty_tag -RELEASE_BRANCH = "main" - def version_scheme(version) -> str: """Get version component for the current commit. @@ -15,7 +13,7 @@ def version_scheme(version) -> str: # If the current commit has a tag, use the tag as version, regardless of branch. # Note: Github CI creates releases from detached HEAD, not from a particular branch. return f"{version.tag}" - elif version.branch == RELEASE_BRANCH and version.tag and version.distance > 0: + elif version.branch == "main" and version.tag and version.distance > 0: # For untagged commits on the release branch always add a distance like ".post3" return f"{version.tag}.post{version.distance}" else: From afc17b4ce444117634372867dbfb1a54152bcdd4 Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Tue, 30 Jul 2024 09:14:23 +0200 Subject: [PATCH 3/3] minor fix --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b076ea9..e9bc3bd 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ def version_scheme(version) -> str: # For untagged commits on the release branch always add a distance like ".post3" return f"{version.tag}.post{version.distance}" else: - # For non-release branches, make the version as dev and distance: + # For non-release branches, mark the version as dev and distance: return f"{version.tag}.dev{version.distance}"