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

Function git_versions_from_keywords

versioneer.py:1123–1190  ·  view source on GitHub ↗

Get version information from git keywords.

(keywords, tag_prefix, verbose)

Source from the content-addressed store, hash-verified

1121
1122@register_vcs_handler("git", "keywords")
1123def git_versions_from_keywords(keywords, tag_prefix, verbose):
1124 """Get version information from git keywords."""
1125 if "refnames" not in keywords:
1126 raise NotThisMethod("Short version file found")
1127 date = keywords.get("date")
1128 if date is not None:
1129 # Use only the last line. Previous lines may contain GPG signature
1130 # information.
1131 date = date.splitlines()[-1]
1132
1133 # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant
1134 # datestamp. However we prefer "%ci" (which expands to an "ISO-8601
1135 # -like" string, which we must then edit to make compliant), because
1136 # it's been around since git-1.5.3, and it's too difficult to
1137 # discover which version we're using, or to work around using an
1138 # older one.
1139 date = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
1140 refnames = keywords["refnames"].strip()
1141 if refnames.startswith("$Format"):
1142 if verbose:
1143 print("keywords are unexpanded, not using")
1144 raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
1145 refs = {r.strip() for r in refnames.strip("()").split(",")}
1146 # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
1147 # just "foo-1.0". If we see a "tag: " prefix, prefer those.
1148 TAG = "tag: "
1149 tags = {r[len(TAG) :] for r in refs if r.startswith(TAG)}
1150 if not tags:
1151 # Either we're using git < 1.8.3, or there really are no tags. We use
1152 # a heuristic: assume all version tags have a digit. The old git %d
1153 # expansion behaves like git log --decorate=short and strips out the
1154 # refs/heads/ and refs/tags/ prefixes that would let us distinguish
1155 # between branches and tags. By ignoring refnames without digits, we
1156 # filter out many common branch names like "release" and
1157 # "stabilization", as well as "HEAD" and "master".
1158 tags = {r for r in refs if re.search(r"\d", r)}
1159 if verbose:
1160 print("discarding '%s', no digits" % ",".join(refs - tags))
1161 if verbose:
1162 print("likely tags: %s" % ",".join(sorted(tags)))
1163 for ref in sorted(tags):
1164 # sorting will prefer e.g. "2.0" over "2.0rc1"
1165 if ref.startswith(tag_prefix):
1166 r = ref[len(tag_prefix) :]
1167 # Filter out refs that exactly match prefix or that don't start
1168 # with a number once the prefix is stripped (mostly a concern
1169 # when prefix is '')
1170 if not re.match(r"\d", r):
1171 continue
1172 if verbose:
1173 print("picking %s" % r)
1174 return {
1175 "version": r,
1176 "full-revisionid": keywords["full"].strip(),
1177 "dirty": False,
1178 "error": None,
1179 "date": date,
1180 }

Callers

nothing calls this directly

Calls 3

getMethod · 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…