mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-26 06:57:32 +00:00
uv_python module: refactor code
This commit is contained in:
parent
458cd11c42
commit
21646442ce
1 changed files with 8 additions and 3 deletions
|
|
@ -51,12 +51,17 @@ python:
|
|||
type: dict
|
||||
'''
|
||||
|
||||
import re
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
class UV:
|
||||
"""
|
||||
Documentation for uv python https://docs.astral.sh/uv/concepts/python-versions/#installing-a-python-version
|
||||
"""
|
||||
def __init__(self, module, **kwargs):
|
||||
self.module = module
|
||||
self.python_version = module.params["version"]
|
||||
|
||||
def install_python(self):
|
||||
rc, out, _ = self._find_python()
|
||||
|
|
@ -65,7 +70,7 @@ class UV:
|
|||
if self.module.check_mode:
|
||||
return True, ""
|
||||
|
||||
cmd = [self.module.get_bin_path("uv", required=True), "python", "install", self.module.params["version"]]
|
||||
cmd = [self.module.get_bin_path("uv", required=True), "python", "install", self.python_version]
|
||||
_, out, _ = self.module.run_command(cmd, check_rc=True)
|
||||
return True, out
|
||||
|
||||
|
|
@ -76,12 +81,12 @@ class UV:
|
|||
if self.module.check_mode:
|
||||
return True, ""
|
||||
|
||||
cmd = [self.module.get_bin_path("uv", required=True), "python", "uninstall", self.module.params["version"]]
|
||||
cmd = [self.module.get_bin_path("uv", required=True), "python", "uninstall", self.python_version]
|
||||
_, out, _ = self.module.run_command(cmd, check_rc=True)
|
||||
return True, out
|
||||
|
||||
def _find_python(self):
|
||||
cmd = [self.module.get_bin_path("uv", required=True), "python", "find", self.module.params["version"]]
|
||||
cmd = [self.module.get_bin_path("uv", required=True), "python", "find", self.python_version]
|
||||
rc, out, err = self.module.run_command(cmd)
|
||||
return rc, out, err
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue