Fix: Avoid LegacyVersion casting due to hyphens
Plugins are no longer following semantic versioning, and frequently include additional versioning information. pkg_resources.parse_version generally handles this well, but some versions with a hyphen will return a LegacyVersion object rather than a Version object, causing it to always compare as lower than any Version object. Simply replacing any '-' with '+' fixes this issue, and does not materially change the versioning. Signed-off-by: Eric Ball <eball@linuxfoundation.org> Change-Id: I5ad949d688ce7ebd0d183d69f4ce87b35343357f
This commit is contained in:
parent
79a5cb8b11
commit
97ad297610
@ -72,6 +72,29 @@ class ModuleRegistry(object):
|
||||
r"(.*)-(?:SNAPSHOT|BETA).*", r"\g<1>.preview", version
|
||||
)
|
||||
|
||||
if isinstance(
|
||||
pkg_resources.parse_version(plugin_info["version"]),
|
||||
pkg_resources.extern.packaging.version.LegacyVersion,
|
||||
):
|
||||
plugin_info["version"] = plugin_info["version"].replace("-", "+")
|
||||
if isinstance(
|
||||
pkg_resources.parse_version(plugin_info["version"]),
|
||||
pkg_resources.extern.packaging.version.LegacyVersion,
|
||||
):
|
||||
plugin_name = plugin_info.get(
|
||||
"shortName", plugin_info.get("longName", None)
|
||||
)
|
||||
if plugin_name:
|
||||
logger.warning(
|
||||
"Version %s for plugin %s is being treated as a LegacyVersion"
|
||||
% (plugin_info["version"], plugin_name)
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
"Version %s is being treated as a LegacyVersion"
|
||||
% plugin_info["version"]
|
||||
)
|
||||
|
||||
aliases = []
|
||||
for key in ["longName", "shortName"]:
|
||||
value = plugin_info.get(key, None)
|
||||
|
@ -37,6 +37,10 @@ class ModuleRegistryPluginInfoTestsWithScenarios(
|
||||
v1="1.4.6-SNAPSHOT (private-0986edd9-example)", op="__gt__", v2="1.4.5"
|
||||
),
|
||||
),
|
||||
("s16", dict(v1="1.0.1-1.v1", op="__gt__", v2="1.0.1")),
|
||||
("s17", dict(v1="1.0.1-1.v1", op="__lt__", v2="1.0.2")),
|
||||
("s18", dict(v1="1.0.2-1.v1", op="__gt__", v2="1.0.1")),
|
||||
("s19", dict(v1="1.0.2-1.v1", op="__gt__", v2="1.0.1-2")),
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
|
Loading…
Reference in New Issue
Block a user