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

Function git_versions_from_keywords

monai/_version.py:168–228  ·  view source on GitHub ↗

Get version information from git keywords.

(keywords, tag_prefix, verbose)

Source from the content-addressed store, hash-verified

166
167@register_vcs_handler("git", "keywords")
168def git_versions_from_keywords(keywords, tag_prefix, verbose):
169 """Get version information from git keywords."""
170 if "refnames" not in keywords:
171 raise NotThisMethod("Short version file found")
172 date = keywords.get("date")
173 if date is not None:
174 # Use only the last line. Previous lines may contain GPG signature
175 # information.
176 date = date.splitlines()[-1]
177
178 # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant
179 # datestamp. However we prefer "%ci" (which expands to an "ISO-8601
180 # -like" string, which we must then edit to make compliant), because
181 # it's been around since git-1.5.3, and it's too difficult to
182 # discover which version we're using, or to work around using an
183 # older one.
184 date = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
185 refnames = keywords["refnames"].strip()
186 if refnames.startswith("$Format"):
187 if verbose:
188 print("keywords are unexpanded, not using")
189 raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
190 refs = {r.strip() for r in refnames.strip("()").split(",")}
191 # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
192 # just "foo-1.0". If we see a "tag: " prefix, prefer those.
193 TAG = "tag: "
194 tags = {r[len(TAG):] for r in refs if r.startswith(TAG)}
195 if not tags:
196 # Either we're using git < 1.8.3, or there really are no tags. We use
197 # a heuristic: assume all version tags have a digit. The old git %d
198 # expansion behaves like git log --decorate=short and strips out the
199 # refs/heads/ and refs/tags/ prefixes that would let us distinguish
200 # between branches and tags. By ignoring refnames without digits, we
201 # filter out many common branch names like "release" and
202 # "stabilization", as well as "HEAD" and "master".
203 tags = {r for r in refs if re.search(r'\d', r)}
204 if verbose:
205 print("discarding '%s', no digits" % ",".join(refs - tags))
206 if verbose:
207 print("likely tags: %s" % ",".join(sorted(tags)))
208 for ref in sorted(tags):
209 # sorting will prefer e.g. "2.0" over "2.0rc1"
210 if ref.startswith(tag_prefix):
211 r = ref[len(tag_prefix):]
212 # Filter out refs that exactly match prefix or that don't start
213 # with a number once the prefix is stripped (mostly a concern
214 # when prefix is '')
215 if not re.match(r'\d', r):
216 continue
217 if verbose:
218 print("picking %s" % r)
219 return {"version": r,
220 "full-revisionid": keywords["full"].strip(),
221 "dirty": False, "error": None,
222 "date": date}
223 # no suitable tags, so version is "0+unknown", but full hex is still there
224 if verbose:
225 print("no suitable tags, using unknown + full revision id")

Callers 1

get_versionsFunction · 0.70

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…