Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Branch based render (Continued) #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def get_vcs_list():
return [filename
for filename
in os.listdir(project_path)
if path.isdir(path.join(project_path, filename))]
if path.isdir(path.join(project_path, filename))
and filename != '__pycache__']

def generate_long_version_py(VCS):
s = io.StringIO()
Expand All @@ -71,7 +72,7 @@ def generate_versioneer_py():
s.write(get("src/subprocess_helper.py", do_strip=True))

for VCS in get_vcs_list():
s.write(u("LONG_VERSION_PY['%s'] = '''\n" % VCS))
s.write(u("LONG_VERSION_PY['%s'] = r'''\n" % VCS))
s.write(generate_long_version_py(VCS))
s.write(u("'''\n"))
s.write(u("\n\n"))
Expand Down
1 change: 0 additions & 1 deletion src/from_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ def write_to_version_file(filename, versions):
f.write(SHORT_VERSION_PY % contents)

print("set %s to '%s'" % (filename, versions["version"]))

1 change: 1 addition & 0 deletions src/get_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def render(): pass # --STRIP DURING BUILD
HANDLERS = {} # --STRIP DURING BUILD
class NotThisMethod(Exception): pass # --STRIP DURING BUILD


class VersioneerBadRootError(Exception):
"""The project root directory is unknown or missing key files."""

Expand Down
7 changes: 3 additions & 4 deletions src/git/from_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
return {"version": r,
"full-revisionid": keywords["full"].strip(),
"dirty": False, "error": None,
"date": date}
"date": date, "branch": None}
# 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", "date": None}


"dirty": False, "error": "no suitable tags", "date": None,
"branch": None}
24 changes: 24 additions & 0 deletions src/git/from_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,30 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
cwd=root)
pieces["distance"] = int(count_out) # total number of commits

# abbrev-ref available with git >= 1.7
branch_name_out, rc = run_command(GITS, ["rev-parse", "--abbrev-ref", "HEAD"],
cwd=root)
branch_name = branch_name_out.strip()
if branch_name == 'HEAD':
# If we aren't exactly on a branch, pick a branch which represents
# the current commit. If all else fails, we are on a branchless
# commit.
branches_out, rc = run_command(GITS, ["branch", "--contains"],
cwd=root)
branches = branches_out.split('\n')
# Strip off the leading "* " from the list of branches.
branches = [branch[2:] for branch in branches
if branch and branch[4:5] != '(']
if 'master' in branches:
branch_name = 'master'
elif not branches:
branch_name = None
else:
# Pick the first branch that is returned. Good or bad.
branch_name = branches[0]

pieces['branch'] = branch_name

# commit date: see ISO-8601 comment in git_versions_from_keywords()
date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"],
cwd=root)[0].strip()
Expand Down
1 change: 1 addition & 0 deletions src/git/long_get_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def versions_from_parentdir(): pass # --STRIP DURING BUILD
class NotThisMethod(Exception): pass # --STRIP DURING BUILD
def render(): pass # --STRIP DURING BUILD


def get_versions():
"""Get version information or return default if unable to do so."""
# I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
Expand Down
45 changes: 44 additions & 1 deletion src/render.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re # --STRIP DURING BUILD


def plus_or_dot(pieces):
"""Return a + if we don't already have one, else return a ."""
Expand Down Expand Up @@ -136,6 +138,46 @@ def render_git_describe_long(pieces):
return rendered


def render_pep440_branch_based(pieces):
"""Build up version string, with post-release "local version identifier".

Our goal: TAG[+DISTANCE.BRANCH_gHEX[.dirty]] . Note that if you
get a tagged build and then dirty it, you'll get TAG+0.BRANCH_gHEX.dirty

Exceptions:
1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.BRANCH_gHEX[.dirty]
"""
replacements = ([' ', '.'], ['(', ''], [')', ''], ['\\', '.'], ['/', '.'])
branch_name = pieces.get('branch') or ''
if branch_name:
for old, new in replacements:
branch_name = branch_name.replace(old, new)
else:
branch_name = 'unknown_branch'

if pieces["closest-tag"]:
rendered = pieces["closest-tag"]
if pieces["distance"] or pieces["dirty"]:
rendered += '.dev0' + plus_or_dot(pieces)
rendered += "%d.%s.g%s" % (
pieces["distance"],
branch_name,
pieces['short']
)
if pieces["dirty"]:
rendered += ".dirty"
else:
# exception #1
rendered = "0+untagged.%d.%s.g%s" % (
pieces["distance"],
branch_name,
pieces['short']
)
if pieces["dirty"]:
rendered += ".dirty"
return rendered


def render(pieces, style):
"""Render the given version pieces into the requested style."""
if pieces["error"]:
Expand All @@ -156,6 +198,8 @@ def render(pieces, style):
rendered = render_pep440_post(pieces)
elif style == "pep440-old":
rendered = render_pep440_old(pieces)
elif style == "pep440-branch-based":
rendered = render_pep440_branch_based(pieces)
elif style == "git-describe":
rendered = render_git_describe(pieces)
elif style == "git-describe-long":
Expand All @@ -166,4 +210,3 @@ def render(pieces, style):
return {"version": rendered, "full-revisionid": pieces["long"],
"dirty": pieces["dirty"], "error": None,
"date": pieces.get("date")}

13 changes: 10 additions & 3 deletions src/setupfunc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

from __future__ import print_function # --STRIP DURING BUILD
import os, sys # --STRIP DURING BUILD
import os, re, sys # --STRIP DURING BUILD
def get_root(): pass # --STRIP DURING BUILD
def get_config_from_root(): pass # --STRIP DURING BUILD
LONG_VERSION_PY = {} # --STRIP DURING BUILD
Expand Down Expand Up @@ -50,6 +50,13 @@ def do_vcs_install(): pass # --STRIP DURING BUILD
del get_versions
"""

INIT_PY_SNIPPET_RE = re.compile(INIT_PY_SNIPPET.replace(
'(', r'\(').replace(
')', r'\)').replace(
'[', r'\[').replace(
']', r'\]').replace(
' ._version', r' ([\w\._]+)?._version'), re.MULTILINE)


def do_setup():
"""Do main VCS-independent setup function for installing Versioneer."""
Expand Down Expand Up @@ -84,7 +91,7 @@ def do_setup():
old = f.read()
except EnvironmentError:
old = ""
if INIT_PY_SNIPPET not in old:
if INIT_PY_SNIPPET_RE.search(old) is None:
print(" appending to %s" % ipy)
with open(ipy, "a") as f:
f.write(INIT_PY_SNIPPET)
Expand Down Expand Up @@ -142,7 +149,7 @@ def scan_setup_py():
for line in f.readlines():
if "import versioneer" in line:
found.add("import")
if "versioneer.get_cmdclass()" in line:
if "versioneer.get_cmdclass(" in line:
found.add("cmdclass")
if "versioneer.get_version()" in line:
found.add("get_version")
Expand Down
Loading