summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2013-01-17 12:56:31 -0500
committerMonty Taylor <mordred@inaugust.com>2013-01-18 16:49:50 -0500
commit9c8685a748714d9ff626694a4838d43edf33ef34 (patch)
tree166ecb98004a52bf9a796a58d00740b97b92231c
parent5f5ef7deb22b86310aa128dcb71534f6fc9deb08 (diff)
downloadoslo-9c8685a748714d9ff626694a4838d43edf33ef34.tar.gz
oslo-9c8685a748714d9ff626694a4838d43edf33ef34.tar.xz
oslo-9c8685a748714d9ff626694a4838d43edf33ef34.zip
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
-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.",