Refreshed versioneer again

This commit is contained in:
Gina Häußge 2015-06-30 15:15:49 +02:00
parent 44561dae15
commit 7cd0adb922
2 changed files with 208 additions and 88 deletions

View file

@ -172,7 +172,8 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
if verbose: if verbose:
print("discarding '%s', no digits" % ",".join(refs-tags)) 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: if verbose:
print("likely branches: %s" % ",".join(sorted(branches))) print("likely branches: %s" % ",".join(sorted(branches)))
branch = None branch = None
@ -189,9 +190,8 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
print("picking %s" % r) print("picking %s" % r)
result = {"version": r, result = {"version": r,
"full-revisionid": keywords["full"].strip(), "full-revisionid": keywords["full"].strip(),
"dirty": False, "error": None "dirty": False, "error": None}
}
if branch is not None: if branch is not None:
result["branch"] = branch result["branch"] = branch
return result 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")] git_describe = git_describe[:git_describe.rindex("-dirty")]
# figure out our branch # 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: if abbrev_ref_out is not None:
pieces["branch"] = abbrev_ref_out.strip() 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") @register_vcs_handler("git", "parse_lookup_file")
def git_parse_lookup_file(path): 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): if not os.path.exists(path):
return [] return []
@ -304,22 +311,39 @@ def git_parse_lookup_file(path):
if '#' in line: if '#' in line:
line = line[:line.rindex("#")] line = line[:line.rindex("#")]
line = line.strip() line = line.strip()
if not line:
continue
try: try:
split_line = line.split() split_line = map(lambda x: x.strip(), line.split())
if len(split_line) == 3: if not len(split_line):
pattern, tag, ref_commit = split_line continue
lookup.append([re.compile(pattern), tag, ref_commit, None])
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: elif len(split_line) == 4:
pattern, tag, ref_commit, render = split_line tag, ref_commit, render = split_line[1:]
lookup.append([re.compile(pattern), tag, ref_commit, render]) entry = [matcher, render, tag, ref_commit]
elif len(split_line) >= 1: else:
lookup.append([re.compile(split_line[0]), None, None, None]) continue
lookup.append(entry)
except: except:
break break
return lookup return lookup
@register_vcs_handler("git", "pieces_from_lookup") @register_vcs_handler("git", "pieces_from_lookup")
def git_pieces_from_lookup(lookup, root, verbose, run_command=run_command): def git_pieces_from_lookup(lookup, root, verbose, run_command=run_command):
"""Extract version information based on provided lookup data."""
GITS = ["git"] GITS = ["git"]
if sys.platform == "win32": if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"] 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") raise NotThisMethod("git rev-parse --abbrev-ref HEAD failed")
current_branch = stdout.strip() 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 matcher.match(current_branch):
if tag is None or ref_commit is None: 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: 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: try:
num_commits = int(stdout.strip()) num_commits = int(stdout.strip())
except ValueError: 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: 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() 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: 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") dirty = stdout.strip().endswith("-dirty")
stdout = run_command(GITS, ["rev-parse", "HEAD"], cwd=root) stdout = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
@ -448,7 +485,7 @@ def render_pep440_post(pieces):
def render_pep440_dev(pieces): def render_pep440_dev(pieces):
""" TAG.dev[DISTANCE]+gHEX[.dirty] """TAG[.devDISTANCE]+gHEX[.dirty] .
Exceptions: Exceptions:
1: no tags. 0.devDISTANCE+gHEX[.dirty] 1: no tags. 0.devDISTANCE+gHEX[.dirty]
@ -457,8 +494,6 @@ def render_pep440_dev(pieces):
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"]: if pieces["distance"]:
rendered += ".dev%d" % pieces["distance"] rendered += ".dev%d" % pieces["distance"]
else:
rendered += ".dev"
rendered += plus_or_dot(pieces) rendered += plus_or_dot(pieces)
else: else:
# exception #1 # exception #1
@ -469,6 +504,7 @@ def render_pep440_dev(pieces):
rendered += ".dirty" rendered += ".dirty"
return rendered return rendered
def render_pep440_old(pieces): def render_pep440_old(pieces):
"""TAG[.postDISTANCE[.dev0]] . """TAG[.postDISTANCE[.dev0]] .
@ -563,7 +599,7 @@ def render(pieces, style):
raise ValueError("unknown style '%s'" % style) raise ValueError("unknown style '%s'" % style)
result = {"version": rendered, "full-revisionid": pieces["long"], 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: if "branch" in pieces and pieces["branch"] is not None:
result["branch"] = pieces["branch"] result["branch"] = pieces["branch"]
return result return result
@ -597,10 +633,11 @@ def get_versions():
"dirty": None, "dirty": None,
"error": "unable to find root of source tree"} "error": "unable to find root of source tree"}
lookupfile = os.path.join(root, cfg.lookupfile if cfg.lookupfile is not None else ".versioneer-lookup") lookupfile = cfg.lookupfile if cfg.lookupfile is not None else ".versioneer-lookup"
if os.path.exists(lookupfile): lookuppath = os.path.join(root, lookupfile)
if os.path.exists(lookuppath):
try: try:
lookup_data = git_parse_lookup_file(lookupfile) lookup_data = git_parse_lookup_file(lookuppath)
pieces = git_pieces_from_lookup(lookup_data, root, verbose) pieces = git_pieces_from_lookup(lookup_data, root, verbose)
return render(pieces, cfg.style) return render(pieces, cfg.style)
except NotThisMethod: except NotThisMethod:

View file

@ -235,12 +235,19 @@ information:
useful to throw an exception in setup.py if this is set, to avoid e.g. useful to throw an exception in setup.py if this is set, to avoid e.g.
creating tarballs with a version string of "unknown". creating tarballs with a version string of "unknown".
If the underlying VCS supports it and that information is available, this will
also be included:
* `['branch']`: A string with the VCS branch name the version was built on.
Some variants are more useful than others. Including `full-revisionid` in a Some variants are more useful than others. Including `full-revisionid` in a
bug report should allow developers to reconstruct the exact code being tested bug report should allow developers to reconstruct the exact code being tested
(or indicate the presence of local changes that should be shared with the (or indicate the presence of local changes that should be shared with the
developers). `version` is suitable for display in an "about" box or a CLI developers). `version` is suitable for display in an "about" box or a CLI
`--version` output: it can be easily compared against release notes and lists `--version` output: it can be easily compared against release notes and lists
of bugs fixed in various releases. of bugs fixed in various releases. Augmenting that with the `branch`
information if it is available will give additional hints during bug reporting
what kind of setup a user was running.
The installer adds the following text to your `__init__.py` to place a basic The installer adds the following text to your `__init__.py` to place a basic
version in `YOURPROJECT.__version__`: version in `YOURPROJECT.__version__`:
@ -644,7 +651,8 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
if verbose: if verbose:
print("discarding '%%s', no digits" %% ",".join(refs-tags)) 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: if verbose:
print("likely branches: %%s" %% ",".join(sorted(branches))) print("likely branches: %%s" %% ",".join(sorted(branches)))
branch = None branch = None
@ -661,9 +669,8 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
print("picking %%s" %% r) print("picking %%s" %% r)
result = {"version": r, result = {"version": r,
"full-revisionid": keywords["full"].strip(), "full-revisionid": keywords["full"].strip(),
"dirty": False, "error": None "dirty": False, "error": None}
}
if branch is not None: if branch is not None:
result["branch"] = branch result["branch"] = branch
return result return result
@ -722,7 +729,9 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
git_describe = git_describe[:git_describe.rindex("-dirty")] git_describe = git_describe[:git_describe.rindex("-dirty")]
# figure out our branch # 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: if abbrev_ref_out is not None:
pieces["branch"] = abbrev_ref_out.strip() pieces["branch"] = abbrev_ref_out.strip()
@ -766,6 +775,11 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
@register_vcs_handler("git", "parse_lookup_file") @register_vcs_handler("git", "parse_lookup_file")
def git_parse_lookup_file(path): 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): if not os.path.exists(path):
return [] return []
@ -776,22 +790,39 @@ def git_parse_lookup_file(path):
if '#' in line: if '#' in line:
line = line[:line.rindex("#")] line = line[:line.rindex("#")]
line = line.strip() line = line.strip()
if not line:
continue
try: try:
split_line = line.split() split_line = map(lambda x: x.strip(), line.split())
if len(split_line) == 3: if not len(split_line):
pattern, tag, ref_commit = split_line continue
lookup.append([re.compile(pattern), tag, ref_commit, None])
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: elif len(split_line) == 4:
pattern, tag, ref_commit, render = split_line tag, ref_commit, render = split_line[1:]
lookup.append([re.compile(pattern), tag, ref_commit, render]) entry = [matcher, render, tag, ref_commit]
elif len(split_line) >= 1: else:
lookup.append([re.compile(split_line[0]), None, None, None]) continue
lookup.append(entry)
except: except:
break break
return lookup return lookup
@register_vcs_handler("git", "pieces_from_lookup") @register_vcs_handler("git", "pieces_from_lookup")
def git_pieces_from_lookup(lookup, root, verbose, run_command=run_command): def git_pieces_from_lookup(lookup, root, verbose, run_command=run_command):
"""Extract version information based on provided lookup data."""
GITS = ["git"] GITS = ["git"]
if sys.platform == "win32": if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"] GITS = ["git.cmd", "git.exe"]
@ -802,27 +833,40 @@ def git_pieces_from_lookup(lookup, root, verbose, run_command=run_command):
raise NotThisMethod("git rev-parse --abbrev-ref HEAD failed") raise NotThisMethod("git rev-parse --abbrev-ref HEAD failed")
current_branch = stdout.strip() 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 matcher.match(current_branch):
if tag is None or ref_commit is None: 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: 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: try:
num_commits = int(stdout.strip()) num_commits = int(stdout.strip())
except ValueError: 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: 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() 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: 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") dirty = stdout.strip().endswith("-dirty")
stdout = run_command(GITS, ["rev-parse", "HEAD"], cwd=root) stdout = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
@ -920,7 +964,7 @@ def render_pep440_post(pieces):
def render_pep440_dev(pieces): def render_pep440_dev(pieces):
""" TAG.dev[DISTANCE]+gHEX[.dirty] """TAG[.devDISTANCE]+gHEX[.dirty] .
Exceptions: Exceptions:
1: no tags. 0.devDISTANCE+gHEX[.dirty] 1: no tags. 0.devDISTANCE+gHEX[.dirty]
@ -929,8 +973,6 @@ def render_pep440_dev(pieces):
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"]: if pieces["distance"]:
rendered += ".dev%%d" %% pieces["distance"] rendered += ".dev%%d" %% pieces["distance"]
else:
rendered += ".dev"
rendered += plus_or_dot(pieces) rendered += plus_or_dot(pieces)
else: else:
# exception #1 # exception #1
@ -941,6 +983,7 @@ def render_pep440_dev(pieces):
rendered += ".dirty" rendered += ".dirty"
return rendered return rendered
def render_pep440_old(pieces): def render_pep440_old(pieces):
"""TAG[.postDISTANCE[.dev0]] . """TAG[.postDISTANCE[.dev0]] .
@ -1035,7 +1078,7 @@ def render(pieces, style):
raise ValueError("unknown style '%%s'" %% style) raise ValueError("unknown style '%%s'" %% style)
result = {"version": rendered, "full-revisionid": pieces["long"], 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: if "branch" in pieces and pieces["branch"] is not None:
result["branch"] = pieces["branch"] result["branch"] = pieces["branch"]
return result return result
@ -1069,10 +1112,12 @@ def get_versions():
"dirty": None, "dirty": None,
"error": "unable to find root of source tree"} "error": "unable to find root of source tree"}
lookupfile = os.path.join(root, cfg.lookupfile if cfg.lookupfile is not None else ".versioneer-lookup") lookupfile = cfg.lookupfile if cfg.lookupfile is not None \
if os.path.exists(lookupfile): else ".versioneer-lookup"
lookuppath = os.path.join(root, lookupfile)
if os.path.exists(lookuppath):
try: try:
lookup_data = git_parse_lookup_file(lookupfile) lookup_data = git_parse_lookup_file(lookuppath)
pieces = git_pieces_from_lookup(lookup_data, root, verbose) pieces = git_pieces_from_lookup(lookup_data, root, verbose)
return render(pieces, cfg.style) return render(pieces, cfg.style)
except NotThisMethod: except NotThisMethod:
@ -1148,7 +1193,8 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
if verbose: if verbose:
print("discarding '%s', no digits" % ",".join(refs-tags)) 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: if verbose:
print("likely branches: %s" % ",".join(sorted(branches))) print("likely branches: %s" % ",".join(sorted(branches)))
branch = None branch = None
@ -1165,9 +1211,8 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
print("picking %s" % r) print("picking %s" % r)
result = {"version": r, result = {"version": r,
"full-revisionid": keywords["full"].strip(), "full-revisionid": keywords["full"].strip(),
"dirty": False, "error": None "dirty": False, "error": None}
}
if branch is not None: if branch is not None:
result["branch"] = branch result["branch"] = branch
return result return result
@ -1226,7 +1271,9 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
git_describe = git_describe[:git_describe.rindex("-dirty")] git_describe = git_describe[:git_describe.rindex("-dirty")]
# figure out our branch # 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: if abbrev_ref_out is not None:
pieces["branch"] = abbrev_ref_out.strip() pieces["branch"] = abbrev_ref_out.strip()
@ -1270,6 +1317,11 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
@register_vcs_handler("git", "parse_lookup_file") @register_vcs_handler("git", "parse_lookup_file")
def git_parse_lookup_file(path): 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): if not os.path.exists(path):
return [] return []
@ -1280,22 +1332,39 @@ def git_parse_lookup_file(path):
if '#' in line: if '#' in line:
line = line[:line.rindex("#")] line = line[:line.rindex("#")]
line = line.strip() line = line.strip()
if not line:
continue
try: try:
split_line = line.split() split_line = map(lambda x: x.strip(), line.split())
if len(split_line) == 3: if not len(split_line):
pattern, tag, ref_commit = split_line continue
lookup.append([re.compile(pattern), tag, ref_commit, None])
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: elif len(split_line) == 4:
pattern, tag, ref_commit, render = split_line tag, ref_commit, render = split_line[1:]
lookup.append([re.compile(pattern), tag, ref_commit, render]) entry = [matcher, render, tag, ref_commit]
elif len(split_line) >= 1: else:
lookup.append([re.compile(split_line[0]), None, None, None]) continue
lookup.append(entry)
except: except:
break break
return lookup return lookup
@register_vcs_handler("git", "pieces_from_lookup") @register_vcs_handler("git", "pieces_from_lookup")
def git_pieces_from_lookup(lookup, root, verbose, run_command=run_command): def git_pieces_from_lookup(lookup, root, verbose, run_command=run_command):
"""Extract version information based on provided lookup data."""
GITS = ["git"] GITS = ["git"]
if sys.platform == "win32": if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"] GITS = ["git.cmd", "git.exe"]
@ -1306,27 +1375,40 @@ def git_pieces_from_lookup(lookup, root, verbose, run_command=run_command):
raise NotThisMethod("git rev-parse --abbrev-ref HEAD failed") raise NotThisMethod("git rev-parse --abbrev-ref HEAD failed")
current_branch = stdout.strip() 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 matcher.match(current_branch):
if tag is None or ref_commit is None: 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: 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: try:
num_commits = int(stdout.strip()) num_commits = int(stdout.strip())
except ValueError: 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: 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() 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: 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") dirty = stdout.strip().endswith("-dirty")
stdout = run_command(GITS, ["rev-parse", "HEAD"], cwd=root) stdout = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
@ -1515,7 +1597,7 @@ def render_pep440_post(pieces):
def render_pep440_dev(pieces): def render_pep440_dev(pieces):
""" TAG.dev[DISTANCE]+gHEX[.dirty] """TAG[.devDISTANCE]+gHEX[.dirty] .
Exceptions: Exceptions:
1: no tags. 0.devDISTANCE+gHEX[.dirty] 1: no tags. 0.devDISTANCE+gHEX[.dirty]
@ -1524,8 +1606,6 @@ def render_pep440_dev(pieces):
rendered = pieces["closest-tag"] rendered = pieces["closest-tag"]
if pieces["distance"]: if pieces["distance"]:
rendered += ".dev%d" % pieces["distance"] rendered += ".dev%d" % pieces["distance"]
else:
rendered += ".dev"
rendered += plus_or_dot(pieces) rendered += plus_or_dot(pieces)
else: else:
# exception #1 # exception #1
@ -1536,6 +1616,7 @@ def render_pep440_dev(pieces):
rendered += ".dirty" rendered += ".dirty"
return rendered return rendered
def render_pep440_old(pieces): def render_pep440_old(pieces):
"""TAG[.postDISTANCE[.dev0]] . """TAG[.postDISTANCE[.dev0]] .
@ -1630,7 +1711,7 @@ def render(pieces, style):
raise ValueError("unknown style '%s'" % style) raise ValueError("unknown style '%s'" % style)
result = {"version": rendered, "full-revisionid": pieces["long"], 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: if "branch" in pieces and pieces["branch"] is not None:
result["branch"] = pieces["branch"] result["branch"] = pieces["branch"]
return result return result
@ -1686,13 +1767,15 @@ def get_versions(verbose=False):
except NotThisMethod: except NotThisMethod:
pass pass
lookupfile = os.path.join(root, cfg.lookupfile if cfg.lookupfile is not None else ".versioneer-lookup") lookupfile = cfg.lookupfile if cfg.lookupfile is not None \
if os.path.exists(lookupfile): else ".versioneer-lookup"
lookuppath = os.path.join(root, lookupfile)
if os.path.exists(lookuppath):
parse_lookup_file_f = handlers.get("parse_lookup_file") parse_lookup_file_f = handlers.get("parse_lookup_file")
versions_from_lookup_f = handlers.get("pieces_from_lookup") versions_from_lookup_f = handlers.get("pieces_from_lookup")
if parse_lookup_file_f and versions_from_lookup_f: if parse_lookup_file_f and versions_from_lookup_f:
try: try:
lookup_data = parse_lookup_file_f(lookupfile) lookup_data = parse_lookup_file_f(lookuppath)
pieces = versions_from_lookup_f(lookup_data, root, verbose) pieces = versions_from_lookup_f(lookup_data, root, verbose)
ver = render(pieces, cfg.style) ver = render(pieces, cfg.style)
if verbose: if verbose: