MCPcopy
hub / github.com/quantopian/zipline / git_pieces_from_vcs

Function git_pieces_from_vcs

versioneer.py:1000–1078  ·  view source on GitHub ↗
(tag_prefix, root, verbose, run_command=run_command)

Source from the content-addressed store, hash-verified

998
999@register_vcs_handler("git", "pieces_from_vcs")
1000def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
1001 # this runs 'git' from the root of the source tree. This only gets called
1002 # if the git-archive 'subst' keywords were *not* expanded, and
1003 # _version.py hasn't already been rewritten with a short version string,
1004 # meaning we're inside a checked out source tree.
1005
1006 if not os.path.exists(os.path.join(root, ".git")):
1007 if verbose:
1008 print("no .git in %s" % root)
1009 raise NotThisMethod("no .git directory")
1010
1011 GITS = ["git"]
1012 if sys.platform == "win32":
1013 GITS = ["git.cmd", "git.exe"]
1014 # if there is a tag, this yields TAG-NUM-gHEX[-dirty]
1015 # if there are no tags, this yields HEX[-dirty] (no NUM)
1016 describe_out = run_command(GITS, ["describe", "--tags", "--dirty",
1017 "--always", "--long"],
1018 cwd=root)
1019 # --long was added in git-1.5.5
1020 if describe_out is None:
1021 raise NotThisMethod("'git describe' failed")
1022 describe_out = describe_out.strip()
1023 full_out = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
1024 if full_out is None:
1025 raise NotThisMethod("'git rev-parse' failed")
1026 full_out = full_out.strip()
1027
1028 pieces = {}
1029 pieces["long"] = full_out
1030 pieces["short"] = full_out[:7] # maybe improved later
1031 pieces["error"] = None
1032
1033 # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty]
1034 # TAG might have hyphens.
1035 git_describe = describe_out
1036
1037 # look for -dirty suffix
1038 dirty = git_describe.endswith("-dirty")
1039 pieces["dirty"] = dirty
1040 if dirty:
1041 git_describe = git_describe[:git_describe.rindex("-dirty")]
1042
1043 # now we have TAG-NUM-gHEX or HEX
1044
1045 if "-" in git_describe:
1046 # TAG-NUM-gHEX
1047 mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
1048 if not mo:
1049 # unparseable. Maybe git-describe is misbehaving?
1050 pieces["error"] = ("unable to parse git-describe output: '%s'"
1051 % describe_out)
1052 return pieces
1053
1054 # tag
1055 full_tag = mo.group(1)
1056 if not full_tag.startswith(tag_prefix):
1057 if verbose:

Callers

nothing calls this directly

Calls 6

existsMethod · 0.80
joinMethod · 0.80
NotThisMethodClass · 0.70
run_commandFunction · 0.70
endswithMethod · 0.45
startswithMethod · 0.45

Tested by

no test coverage detected