MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / git_pieces_from_vcs

Function git_pieces_from_vcs

monai/_version.py:232–361  ·  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

230
231@register_vcs_handler("git", "pieces_from_vcs")
232def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
233 """Get version from 'git describe' in the root of the source tree.
234
235 This only gets called if the git-archive 'subst' keywords were *not*
236 expanded, and _version.py hasn't already been rewritten with a short
237 version string, meaning we're inside a checked out source tree.
238 """
239 GITS = ["git"]
240 if sys.platform == "win32":
241 GITS = ["git.cmd", "git.exe"]
242
243 # GIT_DIR can interfere with correct operation of Versioneer.
244 # It may be intended to be passed to the Versioneer-versioned project,
245 # but that should not change where we get our version from.
246 env = os.environ.copy()
247 env.pop("GIT_DIR", None)
248 runner = functools.partial(runner, env=env)
249
250 _, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root,
251 hide_stderr=True)
252 if rc != 0:
253 if verbose:
254 print("Directory %s not under git control" % root)
255 raise NotThisMethod("'git rev-parse --git-dir' returned error")
256
257 # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
258 # if there isn't one, this yields HEX[-dirty] (no NUM)
259 describe_out, rc = runner(GITS, [
260 "describe", "--tags", "--dirty", "--always", "--long",
261 "--match", f"{tag_prefix}[[:digit:]]*"
262 ], cwd=root)
263 # --long was added in git-1.5.5
264 if describe_out is None:
265 raise NotThisMethod("'git describe' failed")
266 describe_out = describe_out.strip()
267 full_out, rc = runner(GITS, ["rev-parse", "HEAD"], cwd=root)
268 if full_out is None:
269 raise NotThisMethod("'git rev-parse' failed")
270 full_out = full_out.strip()
271
272 pieces = {}
273 pieces["long"] = full_out
274 pieces["short"] = full_out[:7] # maybe improved later
275 pieces["error"] = None
276
277 branch_name, rc = runner(GITS, ["rev-parse", "--abbrev-ref", "HEAD"],
278 cwd=root)
279 # --abbrev-ref was added in git-1.6.3
280 if rc != 0 or branch_name is None:
281 raise NotThisMethod("'git rev-parse --abbrev-ref' returned error")
282 branch_name = branch_name.strip()
283
284 if branch_name == "HEAD":
285 # If we aren't exactly on a branch, pick a branch which represents
286 # the current commit. If all else fails, we are on a branchless
287 # commit.
288 branches, rc = runner(GITS, ["branch", "--contains"], cwd=root)
289 # --contains was added in git-1.5.4

Callers 1

get_versionsFunction · 0.70

Calls 3

popMethod · 0.80
splitMethod · 0.80
NotThisMethodClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…