MCPcopy
hub / github.com/pandas-dev/pandas / git_pieces_from_vcs

Function git_pieces_from_vcs

pandas/_version.py:250–386  ·  view source on GitHub ↗

Get version from 'git describe' in the root of the source tree. This only gets called if the git-archive 'subst' keywords were *not* expanded, and _version.py hasn't already been rewritten with a short version string, meaning we're inside a checked out source tree.

(tag_prefix, root, verbose, runner=run_command)

Source from the content-addressed store, hash-verified

248
249@register_vcs_handler("git", "pieces_from_vcs")
250def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
251 """Get version from 'git describe' in the root of the source tree.
252
253 This only gets called if the git-archive 'subst' keywords were *not*
254 expanded, and _version.py hasn't already been rewritten with a short
255 version string, meaning we're inside a checked out source tree.
256 """
257 GITS = ["git"]
258 if sys.platform == "win32":
259 GITS = ["git.cmd", "git.exe"]
260
261 # GIT_DIR can interfere with correct operation of Versioneer.
262 # It may be intended to be passed to the Versioneer-versioned project,
263 # but that should not change where we get our version from.
264 env = os.environ.copy()
265 env.pop("GIT_DIR", None)
266 runner = functools.partial(runner, env=env)
267
268 _, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=not verbose)
269 if rc != 0:
270 if verbose:
271 print(f"Directory {root} not under git control")
272 raise NotThisMethod("'git rev-parse --git-dir' returned error")
273
274 # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
275 # if there isn't one, this yields HEX[-dirty] (no NUM)
276 describe_out, rc = runner(
277 GITS,
278 [
279 "describe",
280 "--tags",
281 "--dirty",
282 "--always",
283 "--long",
284 "--match",
285 f"{tag_prefix}[[:digit:]]*",
286 ],
287 cwd=root,
288 )
289 # --long was added in git-1.5.5
290 if describe_out is None:
291 raise NotThisMethod("'git describe' failed")
292 describe_out = describe_out.strip()
293 full_out, rc = runner(GITS, ["rev-parse", "HEAD"], cwd=root)
294 if full_out is None:
295 raise NotThisMethod("'git rev-parse' failed")
296 full_out = full_out.strip()
297
298 pieces = {}
299 pieces["long"] = full_out
300 pieces["short"] = full_out[:7] # maybe improved later
301 pieces["error"] = None
302
303 branch_name, rc = runner(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], cwd=root)
304 # --abbrev-ref was added in git-1.6.3
305 if rc != 0 or branch_name is None:
306 raise NotThisMethod("'git rev-parse --abbrev-ref' returned error")
307 branch_name = branch_name.strip()

Callers 1

get_versionsFunction · 0.85

Calls 9

NotThisMethodClass · 0.85
stripMethod · 0.80
splitMethod · 0.80
endswithMethod · 0.80
rindexMethod · 0.80
startswithMethod · 0.80
copyMethod · 0.45
popMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected