🥅 Improve error resilience
Check for PEP440 compliance
This commit is contained in:
1 parent
713045dcc4
commit
aabb13eb57
2 files changed
+30
-10
No files matched your search
@@ -53,6 +53,7 @@ core_deps = [
|
||||
"markdown>=3.4.3,<4",
|
||||
"netaddr>=0.8,<0.9", # changelog hints at breaking changes on minor version increases
|
||||
"netifaces2>=0.0.14,<0.1",
|
||||
"packaging>=23.2,<24",
|
||||
"passlib>=1.7.4,<2",
|
||||
"pathvalidate>=2.5.2,<3",
|
||||
"pkginfo>=1.9.6,<2",
|
||||
|
||||
+29
-10
@@ -80,6 +80,9 @@ branch = "{branch}"
|
||||
revision = "{revision}"
|
||||
""".strip()
|
||||
|
||||
FALLBACK = "0+unknown"
|
||||
FALLBACK_WITH_SHA = "0+unknown.g{short}"
|
||||
|
||||
_verbose = False
|
||||
|
||||
|
||||
@@ -186,6 +189,16 @@ def _parse_branch_versions():
|
||||
return branch_versions
|
||||
|
||||
|
||||
def _validate_version(version):
|
||||
from packaging.version import parse
|
||||
|
||||
try:
|
||||
parse(version)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def _get_data_from_git():
|
||||
branch = _get_branch()
|
||||
if _verbose:
|
||||
@@ -214,13 +227,8 @@ def _get_data_from_git():
|
||||
if not matcher.match(branch):
|
||||
continue
|
||||
|
||||
# might fail if ref_commit is not reachable from HEAD
|
||||
distance = _get_distance(ref_commit)
|
||||
if distance is None:
|
||||
tag = None
|
||||
break
|
||||
|
||||
tag = virtual_tag
|
||||
distance = _get_distance(ref_commit)
|
||||
template = "{tag}.dev{distance}+g{short}"
|
||||
dirty = ".dirty"
|
||||
break
|
||||
@@ -235,16 +243,27 @@ def _get_data_from_git():
|
||||
"short": short,
|
||||
}
|
||||
|
||||
if tag is None:
|
||||
if any([vars[x] is None and "{" + x + "}" in template for x in vars]):
|
||||
if short is None:
|
||||
template = "0+unknown"
|
||||
template = FALLBACK
|
||||
else:
|
||||
template = "0+unknown.g{short}"
|
||||
template = FALLBACK_WITH_SHA
|
||||
if is_dirty:
|
||||
template += ".dirty"
|
||||
|
||||
for t in (
|
||||
template,
|
||||
FALLBACK_WITH_SHA + ".dirty" if is_dirty else FALLBACK_WITH_SHA,
|
||||
FALLBACK + ".dirty" if is_dirty else FALLBACK,
|
||||
):
|
||||
version = t.format(**vars)
|
||||
if _validate_version(version):
|
||||
break
|
||||
else:
|
||||
version = FALLBACK
|
||||
|
||||
return {
|
||||
"version": template.format(**vars),
|
||||
"version": version,
|
||||
"branch": branch,
|
||||
"revision": sha,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user