diff --git a/setup.py b/setup.py index 473fec7..e9bc3bd 100644 --- a/setup.py +++ b/setup.py @@ -3,24 +3,21 @@ 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. 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 == "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: - # 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}" @@ -29,16 +26,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}"