From 9c8685a748714d9ff626694a4838d43edf33ef34 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Thu, 17 Jan 2013 12:56:31 -0500 Subject: Use revno and git sha for pre-release versioning. In discussions with ttx and zul, it became clear that the git describe info for our intra-release case wasn't providing any value and was providing confusion. Additionally, plain git sha's are not providing enough info. So, the scheme settled on that breaks the least amount of things and yet still reduces complexity is: if pre-version: # server projects try: use current tag except: use pre-version+revcount+gitsha else: use git describe | s/-/./ Additionally, we'll use a as a prefix for the revcount, b as the prefix for the milestone portion of a milestone tag, and rc as the prefix for rc's, so that for our releases, python version sorting works as expected. Change-Id: I6f0fe029d225afa8f435bc83216fc144c2402ae0 --- openstack/common/setup.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'openstack/common/setup.py') diff --git a/openstack/common/setup.py b/openstack/common/setup.py index c1db232..81a3d20 100644 --- a/openstack/common/setup.py +++ b/openstack/common/setup.py @@ -108,13 +108,17 @@ def parse_dependency_links(requirements_files=['requirements.txt', return dependency_links -def _run_shell_command(cmd): +def _run_shell_command(cmd, throw_on_error=False): if os.name == 'nt': output = subprocess.Popen(["cmd.exe", "/C", cmd], - stdout=subprocess.PIPE) + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) else: output = subprocess.Popen(["/bin/sh", "-c", cmd], - stdout=subprocess.PIPE) + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + if output.returncode and throw_on_error: + raise Exception("%s returned %d" % cmd, output.returncode) out = output.communicate() if len(out) == 0: return None @@ -254,14 +258,25 @@ def get_cmdclass(): return cmdclass -def get_version_from_git(): +def get_version_from_git(pre_version): """Return a version which is equal to the tag that's on the current revision if there is one, or tag plus number of additional revisions if the current revision has no tag.""" if os.path.isdir('.git'): - return _run_shell_command( - "git describe --always").replace('-', '.') + if pre_version: + try: + return _run_shell_command( + "git describe --exact-match", + throw_on_error=True).replace('-', '.') + except Exception: + sha = _run_shell_command("git log -n1 --pretty=format:%h") + describe = _run_shell_command("git describe --always") + revno = describe.rsplit("-", 2)[-2] + return "%s.a%s.g%s" % (pre_version, revno, sha) + else: + return _run_shell_command( + "git describe --always").replace('-', '.') return None @@ -281,7 +296,7 @@ def get_version_from_pkg_info(package_name): return pkg_info.get('Version', None) -def get_version(package_name): +def get_version(package_name, pre_version=None): """Get the version of the project. First, try getting it from PKG-INFO, if it exists. If it does, that means we're in a distribution tarball or that install has happened. Otherwise, if there is no PKG-INFO file, pull the @@ -299,7 +314,7 @@ def get_version(package_name): version = get_version_from_pkg_info(package_name) if version: return version - version = get_version_from_git() + version = get_version_from_git(pre_version) if version: return version raise Exception("Versioning for this project requires either an sdist" -- cgit