mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-22 05:09:12 +00:00
Fix typing to be compatible with python versions <= 3.8
This commit is contained in:
parent
f8bc6e8483
commit
05c100c661
1 changed files with 9 additions and 8 deletions
|
|
@ -109,6 +109,7 @@ rc:
|
|||
"""
|
||||
|
||||
import json
|
||||
from typing import Tuple
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.compat.version import LooseVersion, StrictVersion
|
||||
|
||||
|
|
@ -146,7 +147,7 @@ class UV:
|
|||
required_version=MINIMUM_UV_VERSION,
|
||||
)
|
||||
|
||||
def install_python(self) -> tuple[bool, str, str, int, list, list]:
|
||||
def install_python(self) -> Tuple[bool, str, str, int, list, list]:
|
||||
"""
|
||||
Runs command 'uv python install X.Y.Z' which installs specified python version.
|
||||
If patch version is not specified uv installs latest available patch version.
|
||||
|
|
@ -173,7 +174,7 @@ class UV:
|
|||
latest_version, path = self._get_latest_patch_release("--only-installed", "--managed-python")
|
||||
return True, out, err, rc, [latest_version], [path]
|
||||
|
||||
def uninstall_python(self) -> tuple[bool, str, str, int, list, list]:
|
||||
def uninstall_python(self) -> Tuple[bool, str, str, int, list, list]:
|
||||
"""
|
||||
Runs command 'uv python uninstall X.Y.Z' which removes specified python version from environment.
|
||||
If patch version is not specified all correspending installed patch versions are removed.
|
||||
|
|
@ -194,7 +195,7 @@ class UV:
|
|||
rc, out, err = self._exec(self.python_version_str, "uninstall", check_rc=True)
|
||||
return True, out, err, rc, installed_versions, install_paths
|
||||
|
||||
def upgrade_python(self) -> tuple[bool, str, str, int, list, list]:
|
||||
def upgrade_python(self) -> Tuple[bool, str, str, int, list, list]:
|
||||
"""
|
||||
Runs command 'uv python install X.Y.Z' with latest patch version available.
|
||||
Returns:
|
||||
|
|
@ -222,7 +223,7 @@ class UV:
|
|||
latest_version_str, latest_path = self._get_latest_patch_release("--only-installed", "--managed-python")
|
||||
return True, out, err, rc, [latest_version_str], [latest_path]
|
||||
|
||||
def _exec(self, python_version, command, *args, check_rc=False) -> tuple[int, str, str]:
|
||||
def _exec(self, python_version, command, *args, check_rc=False) -> Tuple[int, str, str]:
|
||||
"""
|
||||
Execute a uv python subcommand.
|
||||
Args:
|
||||
|
|
@ -238,7 +239,7 @@ class UV:
|
|||
rc, out, err = self.module.run_command(cmd, check_rc=check_rc)
|
||||
return rc, out, err
|
||||
|
||||
def _find_python(self, *args, check_rc=False) -> tuple[int, str, str]:
|
||||
def _find_python(self, *args, check_rc=False) -> Tuple[int, str, str]:
|
||||
"""
|
||||
Runs command 'uv python find' which returns path of installed patch releases for a given python version.
|
||||
If multiple patch versions are installed, "uv python find" returns the one used by default
|
||||
|
|
@ -255,7 +256,7 @@ class UV:
|
|||
out = out.strip()
|
||||
return rc, out, err
|
||||
|
||||
def _list_python(self, *args, check_rc=False) -> tuple[int, list, str]:
|
||||
def _list_python(self, *args, check_rc=False) -> Tuple[int, list, str]:
|
||||
"""
|
||||
Runs command 'uv python list' (which returns list of installed patch releases for a given python version).
|
||||
Official documentation https://docs.astral.sh/uv/reference/cli/#uv-python-list
|
||||
|
|
@ -275,7 +276,7 @@ class UV:
|
|||
pass
|
||||
return rc, pythons_installed, err
|
||||
|
||||
def _get_latest_patch_release(self, *args) -> tuple[str, str]:
|
||||
def _get_latest_patch_release(self, *args) -> Tuple[str, str]:
|
||||
"""
|
||||
Returns latest available patch release for a given python version.
|
||||
Args:
|
||||
|
|
@ -295,7 +296,7 @@ class UV:
|
|||
path = version.get("path", "")
|
||||
return latest_version, path
|
||||
|
||||
def _get_installed_versions(self, *args) -> tuple[list, list]:
|
||||
def _get_installed_versions(self, *args) -> Tuple[list, list]:
|
||||
"""
|
||||
Returns installed patch releases for a given python version.
|
||||
Args:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue