1 parent
f05f850175
commit
e875d042a7
2 files changed
+208
-88
No files matched your search
+66
-29
@@ -172,7 +172,8 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
|
||||
if verbose:
|
||||
print("discarding '%s', no digits" % ",".join(refs-tags))
|
||||
|
||||
branches = [r for r in refs if not r.startswith(TAG) and r != "HEAD" and not r.startswith("refs/")]
|
||||
branches = [r for r in refs if not r.startswith(TAG)
|
||||
and r != "HEAD" and not r.startswith("refs/")]
|
||||
if verbose:
|
||||
print("likely branches: %s" % ",".join(sorted(branches)))
|
||||
branch = None
|
||||
@@ -189,9 +190,8 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
|
||||
print("picking %s" % r)
|
||||
|
||||
result = {"version": r,
|
||||
"full-revisionid": keywords["full"].strip(),
|
||||
"dirty": False, "error": None
|
||||
}
|
||||
"full-revisionid": keywords["full"].strip(),
|
||||
"dirty": False, "error": None}
|
||||
if branch is not None:
|
||||
result["branch"] = branch
|
||||
return result
|
||||
@@ -250,7 +250,9 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
|
||||
git_describe = git_describe[:git_describe.rindex("-dirty")]
|
||||
|
||||
# figure out our branch
|
||||
abbrev_ref_out = run_command(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], cwd=root)
|
||||
abbrev_ref_out = run_command(GITS,
|
||||
["rev-parse", "--abbrev-ref", "HEAD"],
|
||||
cwd=root)
|
||||
if abbrev_ref_out is not None:
|
||||
pieces["branch"] = abbrev_ref_out.strip()
|
||||
|
||||
@@ -294,6 +296,11 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
|
||||
|
||||
@register_vcs_handler("git", "parse_lookup_file")
|
||||
def git_parse_lookup_file(path):
|
||||
"""Parse a versioneer lookup file.
|
||||
|
||||
This file allows definition of branch specific data like virtual tags or
|
||||
custom styles to use for version rendering.
|
||||
"""
|
||||
if not os.path.exists(path):
|
||||
return []
|
||||
|
||||
@@ -304,22 +311,39 @@ def git_parse_lookup_file(path):
|
||||
if '#' in line:
|
||||
line = line[:line.rindex("#")]
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
|
||||
try:
|
||||
split_line = line.split()
|
||||
if len(split_line) == 3:
|
||||
pattern, tag, ref_commit = split_line
|
||||
lookup.append([re.compile(pattern), tag, ref_commit, None])
|
||||
split_line = map(lambda x: x.strip(), line.split())
|
||||
if not len(split_line):
|
||||
continue
|
||||
|
||||
matcher = re.compile(split_line[0])
|
||||
|
||||
if len(split_line) == 1:
|
||||
entry = [matcher, None, None, None]
|
||||
elif len(split_line) == 2:
|
||||
render = split_line[1]
|
||||
entry = [matcher, render, None, None]
|
||||
elif len(split_line) == 3:
|
||||
tag, ref_commit = split_line[1:]
|
||||
entry = [matcher, None, tag, ref_commit]
|
||||
elif len(split_line) == 4:
|
||||
pattern, tag, ref_commit, render = split_line
|
||||
lookup.append([re.compile(pattern), tag, ref_commit, render])
|
||||
elif len(split_line) >= 1:
|
||||
lookup.append([re.compile(split_line[0]), None, None, None])
|
||||
tag, ref_commit, render = split_line[1:]
|
||||
entry = [matcher, render, tag, ref_commit]
|
||||
else:
|
||||
continue
|
||||
|
||||
lookup.append(entry)
|
||||
except:
|
||||
break
|
||||
return lookup
|
||||
|
||||
|
||||
@register_vcs_handler("git", "pieces_from_lookup")
|
||||
def git_pieces_from_lookup(lookup, root, verbose, run_command=run_command):
|
||||
"""Extract version information based on provided lookup data."""
|
||||
GITS = ["git"]
|
||||
if sys.platform == "win32":
|
||||
GITS = ["git.cmd", "git.exe"]
|
||||
@@ -330,27 +354,40 @@ def git_pieces_from_lookup(lookup, root, verbose, run_command=run_command):
|
||||
raise NotThisMethod("git rev-parse --abbrev-ref HEAD failed")
|
||||
|
||||
current_branch = stdout.strip()
|
||||
for matcher, tag, ref_commit, render in lookup:
|
||||
for matcher, render, tag, ref_commit in lookup:
|
||||
if matcher.match(current_branch):
|
||||
if tag is None or ref_commit is None:
|
||||
raise NotThisMethod("tag or ref_commit is unset for this branch")
|
||||
raise NotThisMethod("tag or ref_commit is unset for "
|
||||
"this branch")
|
||||
|
||||
stdout = run_command(GITS, ["rev-list", "%s..HEAD" % ref_commit, "--count"], cwd=root)
|
||||
stdout = run_command(GITS,
|
||||
["rev-list", "%s..HEAD" % ref_commit,
|
||||
"--count"],
|
||||
cwd=root)
|
||||
if stdout is None:
|
||||
raise NotThisMethod("git rev-list %s..HEAD --count failed" % ref_commit)
|
||||
raise NotThisMethod("git rev-list %s..HEAD "
|
||||
"--count failed" % ref_commit)
|
||||
try:
|
||||
num_commits = int(stdout.strip())
|
||||
except ValueError:
|
||||
raise NotThisMethod("git rev-list %s..HEAD --count didn't return a valid number" % ref_commit)
|
||||
raise NotThisMethod("git rev-list %s..HEAD --count didn't "
|
||||
"return a valid number" % ref_commit)
|
||||
|
||||
stdout =run_command(GITS, ["rev-parse", "--short", "HEAD"], cwd=root)
|
||||
stdout = run_command(GITS,
|
||||
["rev-parse", "--short", "HEAD"],
|
||||
cwd=root)
|
||||
if stdout is None:
|
||||
raise NotThisMethod("git describe rev-parse --short HEAD failed")
|
||||
raise NotThisMethod("git describe rev-parse "
|
||||
"--short HEAD failed")
|
||||
short_hash = stdout.strip()
|
||||
|
||||
stdout = run_command(GITS, ["describe", "--tags", "--dirty", "--always"], cwd=root)
|
||||
stdout = run_command(GITS,
|
||||
["describe", "--tags",
|
||||
"--dirty", "--always"],
|
||||
cwd=root)
|
||||
if stdout is None:
|
||||
raise NotThisMethod("git describe --tags --dirty --always failed")
|
||||
raise NotThisMethod("git describe --tags --dirty "
|
||||
"--always failed")
|
||||
dirty = stdout.strip().endswith("-dirty")
|
||||
|
||||
stdout = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
|
||||
@@ -448,7 +485,7 @@ def render_pep440_post(pieces):
|
||||
|
||||
|
||||
def render_pep440_dev(pieces):
|
||||
""" TAG.dev[DISTANCE]+gHEX[.dirty]
|
||||
"""TAG[.devDISTANCE]+gHEX[.dirty] .
|
||||
|
||||
Exceptions:
|
||||
1: no tags. 0.devDISTANCE+gHEX[.dirty]
|
||||
@@ -457,8 +494,6 @@ def render_pep440_dev(pieces):
|
||||
rendered = pieces["closest-tag"]
|
||||
if pieces["distance"]:
|
||||
rendered += ".dev%d" % pieces["distance"]
|
||||
else:
|
||||
rendered += ".dev"
|
||||
rendered += plus_or_dot(pieces)
|
||||
else:
|
||||
# exception #1
|
||||
@@ -469,6 +504,7 @@ def render_pep440_dev(pieces):
|
||||
rendered += ".dirty"
|
||||
return rendered
|
||||
|
||||
|
||||
def render_pep440_old(pieces):
|
||||
"""TAG[.postDISTANCE[.dev0]] .
|
||||
|
||||
@@ -563,7 +599,7 @@ def render(pieces, style):
|
||||
raise ValueError("unknown style '%s'" % style)
|
||||
|
||||
result = {"version": rendered, "full-revisionid": pieces["long"],
|
||||
"dirty": pieces["dirty"], "error": None}
|
||||
"dirty": pieces["dirty"], "error": None}
|
||||
if "branch" in pieces and pieces["branch"] is not None:
|
||||
result["branch"] = pieces["branch"]
|
||||
return result
|
||||
@@ -597,10 +633,11 @@ def get_versions():
|
||||
"dirty": None,
|
||||
"error": "unable to find root of source tree"}
|
||||
|
||||
lookupfile = os.path.join(root, cfg.lookupfile if cfg.lookupfile is not None else ".versioneer-lookup")
|
||||
if os.path.exists(lookupfile):
|
||||
lookupfile = cfg.lookupfile if cfg.lookupfile is not None else ".versioneer-lookup"
|
||||
lookuppath = os.path.join(root, lookupfile)
|
||||
if os.path.exists(lookuppath):
|
||||
try:
|
||||
lookup_data = git_parse_lookup_file(lookupfile)
|
||||
lookup_data = git_parse_lookup_file(lookuppath)
|
||||
pieces = git_pieces_from_lookup(lookup_data, root, verbose)
|
||||
return render(pieces, cfg.style)
|
||||
except NotThisMethod:
|
||||
|
||||
Reference in new issue
Block a user