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

Function git_pieces_from_vcs

zipline/_version.py:180–258  ·  view source on GitHub ↗
(tag_prefix, root, verbose, run_command=run_command)

Source from the content-addressed store, hash-verified

178
179@register_vcs_handler("git", "pieces_from_vcs")
180def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
181 # this runs 'git' from the root of the source tree. This only gets called
182 # if the git-archive 'subst' keywords were *not* expanded, and
183 # _version.py hasn't already been rewritten with a short version string,
184 # meaning we're inside a checked out source tree.
185
186 if not os.path.exists(os.path.join(root, ".git")):
187 if verbose:
188 print("no .git in %s" % root)
189 raise NotThisMethod("no .git directory")
190
191 GITS = ["git"]
192 if sys.platform == "win32":
193 GITS = ["git.cmd", "git.exe"]
194 # if there is a tag, this yields TAG-NUM-gHEX[-dirty]
195 # if there are no tags, this yields HEX[-dirty] (no NUM)
196 describe_out = run_command(GITS, ["describe", "--tags", "--dirty",
197 "--always", "--long"],
198 cwd=root)
199 # --long was added in git-1.5.5
200 if describe_out is None:
201 raise NotThisMethod("'git describe' failed")
202 describe_out = describe_out.strip()
203 full_out = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
204 if full_out is None:
205 raise NotThisMethod("'git rev-parse' failed")
206 full_out = full_out.strip()
207
208 pieces = {}
209 pieces["long"] = full_out
210 pieces["short"] = full_out[:7] # maybe improved later
211 pieces["error"] = None
212
213 # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty]
214 # TAG might have hyphens.
215 git_describe = describe_out
216
217 # look for -dirty suffix
218 dirty = git_describe.endswith("-dirty")
219 pieces["dirty"] = dirty
220 if dirty:
221 git_describe = git_describe[:git_describe.rindex("-dirty")]
222
223 # now we have TAG-NUM-gHEX or HEX
224
225 if "-" in git_describe:
226 # TAG-NUM-gHEX
227 mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
228 if not mo:
229 # unparseable. Maybe git-describe is misbehaving?
230 pieces["error"] = ("unable to parse git-describe output: '%s'"
231 % describe_out)
232 return pieces
233
234 # tag
235 full_tag = mo.group(1)
236 if not full_tag.startswith(tag_prefix):
237 if verbose:

Callers 1

get_versionsFunction · 0.70

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