Update version code from oslo

Pull in a versioning fix from openstack-common, fixes
python setup.py sdist versioning.

Change-Id: I9ffab5c2b37190b4c7daad5e92da40d773c99b4f
Signed-off-by: Chuck Short <chuck.short@canonical.com>
This commit is contained in:
Chuck Short 2013-01-21 19:37:38 -06:00
parent acae86293f
commit 21cf2cf395
3 changed files with 50 additions and 27 deletions

View File

@ -34,11 +34,12 @@ def parse_mailmap(mailmap='.mailmap'):
if os.path.exists(mailmap):
with open(mailmap, 'r') as fp:
for l in fp:
l = l.strip()
if not l.startswith('#') and ' ' in l:
canonical_email, alias = [x for x in l.split(' ')
if x.startswith('<')]
mapping[alias] = canonical_email
try:
canonical_email, alias = re.match(
r'[^#]*?(<.+>).*(<.+>).*', l).groups()
except AttributeError:
continue
mapping[alias] = canonical_email
return mapping
@ -107,23 +108,17 @@ def parse_dependency_links(requirements_files=['requirements.txt',
return dependency_links
def write_requirements():
venv = os.environ.get('VIRTUAL_ENV', None)
if venv is not None:
with open("requirements.txt", "w") as req_file:
output = subprocess.Popen(["pip", "-E", venv, "freeze", "-l"],
stdout=subprocess.PIPE)
requirements = output.communicate()[0].strip()
req_file.write(requirements)
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
@ -263,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
@ -290,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
@ -302,10 +308,13 @@ def get_version(package_name):
to make a source tarball from a fork of our repo with additional tags in it
that they understand and desire the results of doing that.
"""
version = os.environ.get("OSLO_PACKAGE_VERSION", None)
if version:
return version
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"

View File

@ -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

View File

@ -24,7 +24,7 @@ project = 'glance'
setuptools.setup(
name=project,
version=setup.get_version(project),
version=setup.get_version(project, '2013.1'),
description='The Glance project provides services for discovering, '
'registering, and retrieving virtual machine images',
license='Apache License (2.0)',