Formatting with python black

This commit is contained in:
Stephen Seo 2023-02-04 13:14:06 +09:00
parent 74133fb363
commit 9e5b5d4d54

View file

@ -27,11 +27,11 @@ DEFAULT_EDITOR = "/usr/bin/nano"
IS_DIGIT_REGEX = re.compile("^[0-9]+$") IS_DIGIT_REGEX = re.compile("^[0-9]+$")
class ArchPkgVersion(): class ArchPkgVersion:
def __init__(self, version_str): def __init__(self, version_str):
self.versions = [] self.versions = []
self.pkgver = 0 self.pkgver = 0
end_dash_idx = version_str.rfind('-') end_dash_idx = version_str.rfind("-")
if end_dash_idx != -1: if end_dash_idx != -1:
try: try:
self.pkgver = int(version_str[end_dash_idx + 1 :]) self.pkgver = int(version_str[end_dash_idx + 1 :])
@ -39,7 +39,7 @@ class ArchPkgVersion():
self.pkgver = version_str[end_dash_idx + 1 :] self.pkgver = version_str[end_dash_idx + 1 :]
version_str = version_str[:end_dash_idx] version_str = version_str[:end_dash_idx]
for sub in version_str.split('.'): for sub in version_str.split("."):
if IS_DIGIT_REGEX.match(sub) is not None: if IS_DIGIT_REGEX.match(sub) is not None:
self.versions.append(int(sub)) self.versions.append(int(sub))
else: else:
@ -92,12 +92,18 @@ class ArchPkgVersion():
try: try:
if self.versions[i][j] < other_self.versions[i][j]: if self.versions[i][j] < other_self.versions[i][j]:
return -1 return -1
elif self.versions[i][j] > other_self.versions[i][j]: elif (
self.versions[i][j] > other_self.versions[i][j]
):
return 1 return 1
except TypeError: except TypeError:
if str(self.versions[i][j]) < str(other_self.versions[i][j]): if str(self.versions[i][j]) < str(
other_self.versions[i][j]
):
return -1 return -1
elif str(self.versions[i][j]) > str(other_self.versions[i][j]): elif str(self.versions[i][j]) > str(
other_self.versions[i][j]
):
return 1 return 1
if self_subcount < other_subcount: if self_subcount < other_subcount:
return -1 return -1
@ -205,7 +211,7 @@ class ArchPkgVersion():
else: else:
self_str += str(self.versions[idx]) self_str += str(self.versions[idx])
if idx + 1 < len(self.versions): if idx + 1 < len(self.versions):
self_str += '.' self_str += "."
self_str += "-" + str(self.pkgver) self_str += "-" + str(self.pkgver)
return self_str return self_str
@ -695,7 +701,9 @@ def version_parse_checked(version_str: str):
return version.parse(version_str) return version.parse(version_str)
except version.InvalidVersion: except version.InvalidVersion:
self_version = ArchPkgVersion(version_str) self_version = ArchPkgVersion(version_str)
log_print(f'WARNING: version.parse(\"{version_str}\") failed to parse! Defaulting to self-defined version \"{self_version}\".') log_print(
f'WARNING: version.parse("{version_str}") failed to parse! Defaulting to self-defined version "{self_version}".'
)
return self_version return self_version