summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/leap/soledad/__init__.py2
-rw-r--r--src/leap/soledad/_version.py114
2 files changed, 75 insertions, 41 deletions
diff --git a/src/leap/soledad/__init__.py b/src/leap/soledad/__init__.py
index 548099ed..67a2a286 100644
--- a/src/leap/soledad/__init__.py
+++ b/src/leap/soledad/__init__.py
@@ -19,5 +19,3 @@ from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
-
-__all__ = ['__version__']
diff --git a/src/leap/soledad/_version.py b/src/leap/soledad/_version.py
index 4d465c10..e0724e0b 100644
--- a/src/leap/soledad/_version.py
+++ b/src/leap/soledad/_version.py
@@ -6,7 +6,7 @@
# that just contains the computed version number.
# This file is released into the public domain. Generated by
-# versioneer-0.16 (https://github.com/warner/python-versioneer)
+# versioneer-0.18 (https://github.com/warner/python-versioneer)
"""Git implementation of _version.py."""
@@ -25,7 +25,8 @@ def get_keywords():
# get_keywords().
git_refnames = "$Format:%d$"
git_full = "$Format:%H$"
- keywords = {"refnames": git_refnames, "full": git_full}
+ git_date = "$Format:%ci$"
+ keywords = {"refnames": git_refnames, "full": git_full, "date": git_date}
return keywords
@@ -66,7 +67,8 @@ def register_vcs_handler(vcs, method): # decorator
return decorate
-def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
+def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
+ env=None):
"""Call the given command(s)."""
assert isinstance(commands, list)
p = None
@@ -74,7 +76,8 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
try:
dispcmd = str([c] + args)
# remember shell=False, so use git.cmd on windows, not just git
- p = subprocess.Popen([c] + args, cwd=cwd, stdout=subprocess.PIPE,
+ p = subprocess.Popen([c] + args, cwd=cwd, env=env,
+ stdout=subprocess.PIPE,
stderr=(subprocess.PIPE if hide_stderr
else None))
break
@@ -85,36 +88,45 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
if verbose:
print("unable to run %s" % dispcmd)
print(e)
- return None
+ return None, None
else:
if verbose:
print("unable to find command, tried %s" % (commands,))
- return None
+ return None, None
stdout = p.communicate()[0].strip()
if sys.version_info[0] >= 3:
stdout = stdout.decode()
if p.returncode != 0:
if verbose:
print("unable to run %s (error)" % dispcmd)
- return None
- return stdout
+ print("stdout was %s" % stdout)
+ return None, p.returncode
+ return stdout, p.returncode
def versions_from_parentdir(parentdir_prefix, root, verbose):
"""Try to determine the version from the parent directory name.
- Source tarballs conventionally unpack into a directory that includes
- both the project name and a version string.
+ Source tarballs conventionally unpack into a directory that includes both
+ the project name and a version string. We will also support searching up
+ two directory levels for an appropriately named parent directory
"""
- dirname = os.path.basename(root)
- if not dirname.startswith(parentdir_prefix):
- if verbose:
- print("guessing rootdir is '%s', but '%s' doesn't start with "
- "prefix '%s'" % (root, dirname, parentdir_prefix))
- raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
- return {"version": dirname[len(parentdir_prefix):],
- "full-revisionid": None,
- "dirty": False, "error": None}
+ rootdirs = []
+
+ for i in range(3):
+ dirname = os.path.basename(root)
+ if dirname.startswith(parentdir_prefix):
+ return {"version": dirname[len(parentdir_prefix):],
+ "full-revisionid": None,
+ "dirty": False, "error": None, "date": None}
+ else:
+ rootdirs.append(root)
+ root = os.path.dirname(root) # up a level
+
+ if verbose:
+ print("Tried directories %s but none started with prefix %s" %
+ (str(rootdirs), parentdir_prefix))
+ raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
@register_vcs_handler("git", "get_keywords")
@@ -136,6 +148,10 @@ def git_get_keywords(versionfile_abs):
mo = re.search(r'=\s*"(.*)"', line)
if mo:
keywords["full"] = mo.group(1)
+ if line.strip().startswith("git_date ="):
+ mo = re.search(r'=\s*"(.*)"', line)
+ if mo:
+ keywords["date"] = mo.group(1)
f.close()
except EnvironmentError:
pass
@@ -147,6 +163,15 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
"""Get version information from git keywords."""
if not keywords:
raise NotThisMethod("no keywords at all, weird")
+ date = keywords.get("date")
+ if date is not None:
+ # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant
+ # datestamp. However we prefer "%ci" (which expands to an "ISO-8601
+ # -like" string, which we must then edit to make compliant), because
+ # it's been around since git-1.5.3, and it's too difficult to
+ # discover which version we're using, or to work around using an
+ # older one.
+ date = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
refnames = keywords["refnames"].strip()
if refnames.startswith("$Format"):
if verbose:
@@ -167,7 +192,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
# "stabilization", as well as "HEAD" and "master".
tags = set([r for r in refs if re.search(r'\d', r)])
if verbose:
- print("discarding '%s', no digits" % ",".join(refs-tags))
+ print("discarding '%s', no digits" % ",".join(refs - tags))
if verbose:
print("likely tags: %s" % ",".join(sorted(tags)))
for ref in sorted(tags):
@@ -178,14 +203,14 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
print("picking %s" % r)
return {"version": r,
"full-revisionid": keywords["full"].strip(),
- "dirty": False, "error": None
- }
+ "dirty": False, "error": None,
+ "date": date}
# no suitable tags, so version is "0+unknown", but full hex is still there
if verbose:
print("no suitable tags, using unknown + full revision id")
return {"version": "0+unknown",
"full-revisionid": keywords["full"].strip(),
- "dirty": False, "error": "no suitable tags"}
+ "dirty": False, "error": "no suitable tags", "date": None}
@register_vcs_handler("git", "pieces_from_vcs")
@@ -196,25 +221,28 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
expanded, and _version.py hasn't already been rewritten with a short
version string, meaning we're inside a checked out source tree.
"""
- if not os.path.exists(os.path.join(root, ".git")):
- if verbose:
- print("no .git in %s" % root)
- raise NotThisMethod("no .git directory")
-
GITS = ["git"]
if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"]
+
+ out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root,
+ hide_stderr=True)
+ if rc != 0:
+ if verbose:
+ print("Directory %s not under git control" % root)
+ raise NotThisMethod("'git rev-parse --git-dir' returned error")
+
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
# if there isn't one, this yields HEX[-dirty] (no NUM)
- describe_out = run_command(GITS, ["describe", "--tags", "--dirty",
- "--always", "--long",
- "--match", "%s*" % tag_prefix],
- cwd=root)
+ describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty",
+ "--always", "--long",
+ "--match", "%s*" % tag_prefix],
+ cwd=root)
# --long was added in git-1.5.5
if describe_out is None:
raise NotThisMethod("'git describe' failed")
describe_out = describe_out.strip()
- full_out = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
+ full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
if full_out is None:
raise NotThisMethod("'git rev-parse' failed")
full_out = full_out.strip()
@@ -265,10 +293,15 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
else:
# HEX: no tags
pieces["closest-tag"] = None
- count_out = run_command(GITS, ["rev-list", "HEAD", "--count"],
- cwd=root)
+ count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"],
+ cwd=root)
pieces["distance"] = int(count_out) # total number of commits
+ # commit date: see ISO-8601 comment in git_versions_from_keywords()
+ date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"],
+ cwd=root)[0].strip()
+ pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
+
return pieces
@@ -415,7 +448,8 @@ def render(pieces, style):
return {"version": "unknown",
"full-revisionid": pieces.get("long"),
"dirty": None,
- "error": pieces["error"]}
+ "error": pieces["error"],
+ "date": None}
if not style or style == "default":
style = "pep440" # the default
@@ -436,7 +470,8 @@ def render(pieces, style):
raise ValueError("unknown style '%s'" % style)
return {"version": rendered, "full-revisionid": pieces["long"],
- "dirty": pieces["dirty"], "error": None}
+ "dirty": pieces["dirty"], "error": None,
+ "date": pieces.get("date")}
def get_versions():
@@ -465,7 +500,8 @@ def get_versions():
except NameError:
return {"version": "0+unknown", "full-revisionid": None,
"dirty": None,
- "error": "unable to find root of source tree"}
+ "error": "unable to find root of source tree",
+ "date": None}
try:
pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)
@@ -481,4 +517,4 @@ def get_versions():
return {"version": "0+unknown", "full-revisionid": None,
"dirty": None,
- "error": "unable to compute version"}
+ "error": "unable to compute version", "date": None}