From b7e944acdeaa3233dcac045d059d93fe46a71989 Mon Sep 17 00:00:00 2001 From: Michael Kleehammer Date: Thu, 14 Jul 2022 15:28:20 -0500 Subject: [PATCH] Fix version of CI generated wheels The CI system is checking out exact tags like "git checkout 4.0.33", which results in a detached HEAD. The version calculation was adding the commit hash. --- setup.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 2e75f6e2..260ce7d3 100755 --- a/setup.py +++ b/setup.py @@ -301,11 +301,16 @@ def _get_version_pkginfo(): def _get_version_git(): + """ + If this is a git repo, returns the version as text and the version as a list of 4 subparts: + ("4.0.33", [4, 0, 33, 9999]). + + If this is not a git repo, (None, None) is returned. + """ n, result = getoutput("git describe --tags --match [0-9]*") if n: _print('WARNING: git describe failed with: %s %s' % (n, result)) return None, None - match = re.match(r'(\d+).(\d+).(\d+) (?: -(\d+)-g[0-9a-z]+)?', result, re.VERBOSE) if not match: return None, None @@ -321,9 +326,15 @@ def _get_version_git(): n, result = getoutput('git rev-parse --abbrev-ref HEAD') if result == 'HEAD': - # We are not on a branch, so use the last revision instead - n, result = getoutput('git rev-parse --short HEAD') - name = name + '+commit' + result + # We are not on a branch. In the past we would add "+commitHHHH" to it, but this + # interferes with the CI system which checks out by tag name. The goal of the version + # numbers is to be reproducible, so we may want to put this back if we detect the + # current commit is not on the master branch. + + # n, result = getoutput('git rev-parse --short HEAD') + # name = name + '+commit' + result + + pass else: if result != 'master' and not re.match(r'^v\d+$', result): name = name + '+' + result.replace('-', '') @@ -331,7 +342,6 @@ def _get_version_git(): return name, numbers - def getoutput(cmd): pipe = os.popen(cmd, 'r') text = pipe.read().rstrip('\n')