summaryrefslogtreecommitdiffstats
path: root/openstack/common/setup.py
diff options
context:
space:
mode:
Diffstat (limited to 'openstack/common/setup.py')
-rw-r--r--openstack/common/setup.py31
1 files changed, 23 insertions, 8 deletions
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"