Skip to content

Commit

Permalink
Fix version issue during nosetests run
Browse files Browse the repository at this point in the history
Pick up the latest files from oslo

Fixes LP# 1118845

Change-Id: I1c9a19508fc18f18936624fa233d3fdc6d31e43f
  • Loading branch information
Davanum Srinivas committed Feb 11, 2013
1 parent c9f493e commit 6b706f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
27 changes: 20 additions & 7 deletions glance/openstack/common/setup.py
Expand Up @@ -258,7 +258,22 @@ class LocalBuildLatex(LocalBuildDoc):
return cmdclass


def get_version_from_git(pre_version):
def _get_revno():
"""Return the number of commits since the most recent tag.
We use git-describe to find this out, but if there are no
tags then we fall back to counting commits since the beginning
of time.
"""
describe = _run_shell_command("git describe --always")
if "-" in describe:
return describe.rsplit("-", 2)[-2]

# no tags found
revlist = _run_shell_command("git rev-list --abbrev-commit HEAD")
return len(revlist.splitlines())

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."""
Expand All @@ -271,16 +286,14 @@ def get_version_from_git(pre_version):
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)
return "%s.a%s.g%s" % (pre_version, _get_revno(), sha)
else:
return _run_shell_command(
"git describe --always").replace('-', '.')
return None


def get_version_from_pkg_info(package_name):
def _get_version_from_pkg_info(package_name):
"""Get the version from PKG-INFO file if we can."""
try:
pkg_info_file = open('PKG-INFO', 'r')
Expand Down Expand Up @@ -311,10 +324,10 @@ def get_version(package_name, pre_version=None):
version = os.environ.get("OSLO_PACKAGE_VERSION", None)
if version:
return version
version = get_version_from_pkg_info(package_name)
version = _get_version_from_pkg_info(package_name)
if version:
return version
version = get_version_from_git(pre_version)
version = _get_version_from_git(pre_version)
if version:
return version
raise Exception("Versioning for this project requires either an sdist"
Expand Down
14 changes: 11 additions & 3 deletions glance/openstack/common/version.py
Expand Up @@ -33,6 +33,14 @@ def __init__(self, package):
self.version = None
self._cached_version = None

def __str__(self):
"""Make the VersionInfo object behave like a string."""
return self.version_string()

def __repr__(self):
"""Include the name."""
return "VersionInfo(%s:%s)" % (self.package, self.version_string())

def _get_version_from_pkg_resources(self):
"""Get the version of the package from the pkg_resources record
associated with the package."""
Expand All @@ -41,11 +49,11 @@ def _get_version_from_pkg_resources(self):
provider = pkg_resources.get_provider(requirement)
return provider.version
except pkg_resources.DistributionNotFound:
# The most likely cause for this is running tests in a tree with
# The most likely cause for this is running tests in a tree
# produced from a tarball where the package itself has not been
# installed into anything. Check for a PKG-INFO file.
# installed into anything. Revert to setup-time logic.
from glance.openstack.common import setup
return setup.get_version_from_pkg_info(self.package)
return setup.get_version(self.package)

def release_string(self):
"""Return the full version of the package including suffixes indicating
Expand Down

0 comments on commit 6b706f1

Please sign in to comment.