MCPcopy Create free account
hub / github.com/microsoft/debugpy / git_versions_from_keywords

Function git_versions_from_keywords

versioneer.py:1115–1175  ·  view source on GitHub ↗

Get version information from git keywords.

(keywords, tag_prefix, verbose)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

searchMethod · 0.80
matchMethod · 0.80
NotThisMethodClass · 0.70
getMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…