MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / hint

Function hint

src/commoncode/version.py:43–61  ·  view source on GitHub ↗

Return a version found in a ``path`` or None. Prefix the version with 'v ' if the version does not start with v.

(path)

Source from the content-addressed store, hash-verified

41
42
43def hint(path):
44 """
45 Return a version found in a ``path`` or None. Prefix the version with 'v ' if
46 the version does not start with v.
47 """
48 for pattern in VERSION_PATTERNS_REGEX():
49 segments = path.split("/")
50 # skip the first path segment unless there's only one segment
51 first_segment = 1 if len(segments) > 1 else 0
52 interesting_segments = segments[first_segment:]
53 # we iterate backwards from the end of the paths segments list
54 for segment in interesting_segments[::-1]:
55 version = re.search(pattern, segment)
56 if version:
57 v = version.group(0)
58 # prefix with v space
59 if not v.lower().startswith("v"):
60 v = f"v {v}"
61 return v
62
63
64def is_dot_num(s):

Callers

nothing calls this directly

Calls 4

VERSION_PATTERNS_REGEXFunction · 0.85
groupMethod · 0.80
splitMethod · 0.45
searchMethod · 0.45

Tested by

no test coverage detected