1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-03-22 13:19:13 +00:00

uv_python module: handle case when provided python version does not exist in latest state

This commit is contained in:
Mariam Ahhttouche 2026-02-16 14:33:33 +01:00
parent cfecbc6d7b
commit 5c842b805b

View file

@ -70,9 +70,9 @@ class UV:
self.python_version = StrictVersion(python_version)
self.python_version_str = self.python_version.__str__()
except ValueError:
module.fail_json(
self.module.fail_json(
msg=(
f"Invalid version '{python_version}'. "
f"Invalid version {python_version}. "
"Expected formats are X.Y or X.Y.Z"
)
)
@ -126,11 +126,23 @@ class UV:
return rc, out, err
def _get_latest_patch_release(self):
"""
Returns latest available patch release for a given python version
"""
_, out, _ = self._list_python() # uv returns versions in descending order but we sort them just in case future uv behavior changes
results = json.loads(out)
versions = [StrictVersion(result["version"]) for result in results]
return max(versions).__str__()
latest_version = ""
try:
results = json.loads(out)
versions = [StrictVersion(result["version"]) for result in results]
latest_version = max(versions).__str__()
except ValueError:
self.module.fail_json(
msg=(
f"Version {self.python_version_str} does not exist. "
)
)
return latest_version
def main():
module = AnsibleModule(