Safer way to detect python package version
This commit is contained in:
@@ -58,18 +58,25 @@ def get_package_version(name, venv=None, **kwargs):
|
|||||||
f"Output is: {output}")
|
f"Output is: {output}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
output_list = output.decode().split("\n")
|
|
||||||
version_item_list = output_list[1].split(":")
|
|
||||||
version_list = version_item_list[1].split(".")
|
|
||||||
version_list_clean = []
|
version_list_clean = []
|
||||||
for element in version_list:
|
for line in output.decode().split("\n"):
|
||||||
try:
|
if not line.startswith("Version:"):
|
||||||
version_list_clean.append(int(element))
|
continue
|
||||||
except ValueError:
|
version_item_list = line.split(":")
|
||||||
utils.printcolor(
|
version_list = version_item_list[1].split(".")
|
||||||
f"Failed to decode some part of the version of {name}",
|
for element in version_list:
|
||||||
utils.YELLOW)
|
try:
|
||||||
version_list_clean.append(element)
|
version_list_clean.append(int(element))
|
||||||
|
except ValueError:
|
||||||
|
utils.printcolor(
|
||||||
|
f"Failed to decode some part of the version of {name}",
|
||||||
|
utils.YELLOW)
|
||||||
|
version_list_clean.append(element)
|
||||||
|
if len(version_list_clean) == 0:
|
||||||
|
utils.printcolor(
|
||||||
|
f"Failed to find the version of {name}",
|
||||||
|
utils.RED)
|
||||||
|
sys.exit(1)
|
||||||
return version_list_clean
|
return version_list_clean
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user