Show git branch in version output. fixes #1953

Also make sure strings in _version.py are correctly escaped, and repair a test.

Signed-off-by: Daira Hopwood <david-sarah@jacaranda.org>
This commit is contained in:
Daira Hopwood 2013-04-25 02:14:50 +01:00
parent f9af0633d8
commit 8a1b2c7aa6
3 changed files with 36 additions and 11 deletions

View File

@ -243,10 +243,11 @@ class MakeExecutable(Command):
GIT_VERSION_BODY = '''
# This _version.py is generated from git metadata by the tahoe setup.py.
__pkgname__ = "%(pkgname)s"
real_version = "%(version)s"
full_version = "%(full)s"
verstr = "%(normalized)s"
__pkgname__ = %(pkgname)r
real_version = %(version)r
full_version = %(full)r
branch = %(branch)r
verstr = %(normalized)r
__version__ = verstr
'''
@ -309,6 +310,7 @@ def versions_from_git(tag_prefix, verbose=False):
normalized_version = pieces[0]
else:
normalized_version = "%s.post%s" % (pieces[0], pieces[1])
stdout = run_command([GIT, "rev-parse", "HEAD"], cwd=source_dir)
if stdout is None:
return {}
@ -316,7 +318,12 @@ def versions_from_git(tag_prefix, verbose=False):
if version.endswith("-dirty"):
full += "-dirty"
normalized_version += ".dev0"
return {"version": version, "normalized": normalized_version, "full": full}
# Thanks to Jistanidiot at <http://stackoverflow.com/questions/6245570/get-current-branch-name>.
stdout = run_command([GIT, "rev-parse", "--abbrev-ref", "HEAD"], cwd=source_dir)
branch = (stdout or "unknown").strip()
return {"version": version, "normalized": normalized_version, "full": full, "branch": branch}
# setup.cfg has an [aliases] section which runs "update_version" before many
# commands (like "build" and "sdist") that need to know our package version
@ -350,7 +357,9 @@ class UpdateVersion(Command):
{ "pkgname": self.distribution.get_name(),
"version": versions["version"],
"normalized": versions["normalized"],
"full": versions["full"] })
"full": versions["full"],
"branch": versions["branch"],
})
f.close()
print("git-version: wrote '%s' into '%s'" % (versions["version"], fn))
return versions.get("normalized", None)

View File

@ -15,9 +15,19 @@ __version__ = "unknown"
try:
from allmydata._version import __version__
except ImportError:
# We're running in a tree that hasn't run "./setup.py darcsver", and didn't
# come with a _version.py, so we don't know what our version is. This should
# not happen very often.
# We're running in a tree that hasn't run update_version, and didn't
# come with a _version.py, so we don't know what our version is.
# This should not happen very often.
pass
full_version = "unknown"
branch = "unknown"
try:
from allmydata._version import full_version, branch
except ImportError:
# We're running in a tree that hasn't run update_version, and didn't
# come with a _version.py, so we don't know what our full version or
# branch is. This should not happen very often.
pass
__appname__ = "unknown"
@ -191,7 +201,9 @@ def get_package_versions_and_locations():
packages.append( (pkgname, (None, None, trace_info)) )
else:
comment = None
if pkgname == 'setuptools' and hasattr(module, '_distribute'):
if pkgname == __appname__:
comment = "%s: %s" % (branch, full_version)
elif pkgname == 'setuptools' and hasattr(module, '_distribute'):
# distribute does not report its version in any module variables
comment = 'distribute'
packages.append( (pkgname, (get_version(module, '__version__'), package_dir(module.__file__), comment)) )

View File

@ -160,7 +160,9 @@ class BinTahoe(common_util.SignalMixin, unittest.TestCase, RunBinTahoeMixin):
info = repr((res, allmydata.__appname__, required_verstr, srcdir))
appverpath = out.split(')')[0]
(appver, path) = appverpath.split(' (')
(appverfull, path) = appverpath.split('] (')
(appver, comment) = appverfull.split(' [')
(branch, full_version) = comment.split(': ')
(app, ver) = appver.split(': ')
self.failUnlessEqual(app, allmydata.__appname__, info)
@ -168,6 +170,8 @@ class BinTahoe(common_util.SignalMixin, unittest.TestCase, RunBinTahoeMixin):
norm_required = normalized_version(required_verstr)
self.failUnlessEqual(norm_ver, norm_required, info)
self.failUnlessEqual(path, srcdir, info)
self.failUnlessEqual(branch, allmydata.branch)
self.failUnlessEqual(full_version, allmydata.full_version)
d.addCallback(_cb)
return d