Also make sure strings in _version.py are correctly escaped, and repair a test.
Signed-off-by: Daira Hopwood <david-sarah@jacaranda.org>
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
'''
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 {}
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
{ "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)
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"
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)) )
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)
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