Merge "Fix version issue during nosetests run"
This commit is contained in:
commit
115a0ca0fd
@ -258,7 +258,22 @@ def get_cmdclass():
|
||||
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."""
|
||||
@ -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')
|
||||
@ -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"
|
||||
|
@ -33,6 +33,14 @@ class VersionInfo(object):
|
||||
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."""
|
||||
@ -41,11 +49,11 @@ class VersionInfo(object):
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user