summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openstack/common/setup.py31
-rw-r--r--openstack/common/version.py20
-rw-r--r--setup.py2
3 files changed, 41 insertions, 12 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"
diff --git a/openstack/common/version.py b/openstack/common/version.py
index 8f7e1a9..3653ad0 100644
--- a/openstack/common/version.py
+++ b/openstack/common/version.py
@@ -29,6 +29,7 @@ class VersionInfo(object):
python-glanceclient
"""
self.package = package
+ self.release = None
self.version = None
self._cached_version = None
@@ -39,18 +40,31 @@ class VersionInfo(object):
provider = pkg_resources.get_provider(requirement)
return provider.version
- def version_string(self):
+ def release_string(self):
"""Return the full version of the package including suffixes indicating
VCS status.
"""
+ if self.release is None:
+ self.release = self._get_version_from_pkg_resources()
+
+ return self.release
+
+ def version_string(self):
+ """Return the short version minus any alpha/beta tags."""
if self.version is None:
- self.version = self._get_version_from_pkg_resources()
+ parts = []
+ for part in self.release_string().split('.'):
+ if part[0].isdigit():
+ parts.append(part)
+ else:
+ break
+ self.version = ".".join(parts)
return self.version
# Compatibility functions
canonical_version_string = version_string
- version_string_with_vcs = version_string
+ version_string_with_vcs = release_string
def cached_version_string(self, prefix=""):
"""Generate an object which will expand in a string context to
diff --git a/setup.py b/setup.py
index 0a590a1..9262a09 100644
--- a/setup.py
+++ b/setup.py
@@ -42,7 +42,7 @@ weights = [
setuptools.setup(
name=package,
- version=setup.get_version(package),
+ version=setup.get_version(package, '2013.1'),
description="Common components for Openstack",
long_description="Common components for Openstack "
"including paster templates.",