1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-25 13:12:46 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -213,7 +213,11 @@ version:
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper
from ansible_collections.community.general.plugins.module_utils.pipx import pipx_runner, pipx_common_argspec, make_process_dict
from ansible_collections.community.general.plugins.module_utils.pipx import (
pipx_runner,
pipx_common_argspec,
make_process_dict,
)
from ansible_collections.community.general.plugins.module_utils.pkg_req import PackageRequirement
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
@ -225,44 +229,61 @@ def _make_name(name, suffix):
class PipX(StateModuleHelper):
output_params = ['name', 'source', 'index_url', 'force', 'installdeps']
output_params = ["name", "source", "index_url", "force", "installdeps"]
argument_spec = dict(
state=dict(type='str', default='install',
choices=[
'present', 'absent', 'install', 'install_all', 'uninstall', 'uninstall_all', 'inject', 'uninject',
'upgrade', 'upgrade_shared', 'upgrade_all', 'reinstall', 'reinstall_all', 'latest', 'pin', 'unpin',
]),
name=dict(type='str'),
source=dict(type='str'),
install_apps=dict(type='bool', default=False),
install_deps=dict(type='bool', default=False),
inject_packages=dict(type='list', elements='str'),
force=dict(type='bool', default=False),
include_injected=dict(type='bool', default=False),
index_url=dict(type='str'),
python=dict(type='str'),
system_site_packages=dict(type='bool', default=False),
editable=dict(type='bool', default=False),
pip_args=dict(type='str'),
suffix=dict(type='str'),
spec_metadata=dict(type='path'),
state=dict(
type="str",
default="install",
choices=[
"present",
"absent",
"install",
"install_all",
"uninstall",
"uninstall_all",
"inject",
"uninject",
"upgrade",
"upgrade_shared",
"upgrade_all",
"reinstall",
"reinstall_all",
"latest",
"pin",
"unpin",
],
),
name=dict(type="str"),
source=dict(type="str"),
install_apps=dict(type="bool", default=False),
install_deps=dict(type="bool", default=False),
inject_packages=dict(type="list", elements="str"),
force=dict(type="bool", default=False),
include_injected=dict(type="bool", default=False),
index_url=dict(type="str"),
python=dict(type="str"),
system_site_packages=dict(type="bool", default=False),
editable=dict(type="bool", default=False),
pip_args=dict(type="str"),
suffix=dict(type="str"),
spec_metadata=dict(type="path"),
)
argument_spec.update(pipx_common_argspec)
module = dict(
argument_spec=argument_spec,
required_if=[
('state', 'present', ['name']),
('state', 'install', ['name']),
('state', 'install_all', ['spec_metadata']),
('state', 'absent', ['name']),
('state', 'uninstall', ['name']),
('state', 'upgrade', ['name']),
('state', 'reinstall', ['name']),
('state', 'latest', ['name']),
('state', 'inject', ['name', 'inject_packages']),
('state', 'pin', ['name']),
('state', 'unpin', ['name']),
("state", "present", ["name"]),
("state", "install", ["name"]),
("state", "install_all", ["spec_metadata"]),
("state", "absent", ["name"]),
("state", "uninstall", ["name"]),
("state", "upgrade", ["name"]),
("state", "reinstall", ["name"]),
("state", "latest", ["name"]),
("state", "inject", ["name", "inject_packages"]),
("state", "pin", ["name"]),
("state", "unpin", ["name"]),
],
required_by=dict(
suffix="name",
@ -272,7 +293,7 @@ class PipX(StateModuleHelper):
def _retrieve_installed(self):
output_process = make_process_dict(include_injected=True)
installed, dummy = self.runner('_list global', output_process=output_process).run()
installed, dummy = self.runner("_list global", output_process=output_process).run()
if self.app_name is None:
return installed
@ -283,8 +304,8 @@ class PipX(StateModuleHelper):
if self.vars.executable:
self.command = [self.vars.executable]
else:
facts = ansible_facts(self.module, gather_subset=['python'])
self.command = [facts['python']['executable'], '-m', 'pipx']
facts = ansible_facts(self.module, gather_subset=["python"])
self.command = [facts["python"]["executable"], "-m", "pipx"]
self.runner = pipx_runner(self.module, self.command)
pkg_req = PackageRequirement(self.module, self.vars.name)
@ -292,7 +313,7 @@ class PipX(StateModuleHelper):
self.parsed_req = pkg_req.requirement
self.app_name = _make_name(self.parsed_name, self.vars.suffix)
self.vars.set('application', self._retrieve_installed(), change=True, diff=True)
self.vars.set("application", self._retrieve_installed(), change=True, diff=True)
with self.runner("version") as ctx:
rc, out, err = ctx.run()
@ -308,7 +329,7 @@ class PipX(StateModuleHelper):
self.vars.stdout = ctx.results_out
self.vars.stderr = ctx.results_err
self.vars.cmd = ctx.cmd
self.vars.set('run_info', ctx.run_info, verbosity=4)
self.vars.set("run_info", ctx.run_info, verbosity=4)
def state_install(self):
# If we have a version spec and no source, use the version spec as source
@ -317,7 +338,11 @@ class PipX(StateModuleHelper):
if self.vars.application.get(self.app_name):
is_installed = True
version_match = self.vars.application[self.app_name]['version'] in self.parsed_req.specifier if self.parsed_req else True
version_match = (
self.vars.application[self.app_name]["version"] in self.parsed_req.specifier
if self.parsed_req
else True
)
force = self.vars.force or (not version_match)
else:
is_installed = False
@ -328,7 +353,9 @@ class PipX(StateModuleHelper):
return
self.changed = True
args_order = 'state global index_url install_deps force python system_site_packages editable pip_args suffix name_source'
args_order = (
"state global index_url install_deps force python system_site_packages editable pip_args suffix name_source"
)
with self.runner(args_order, check_mode_skip=True) as ctx:
ctx.run(name_source=[self.parsed_name, self.vars.source], force=force)
self._capture_results(ctx)
@ -337,7 +364,10 @@ class PipX(StateModuleHelper):
def state_install_all(self):
self.changed = True
with self.runner('state global index_url force python system_site_packages editable pip_args spec_metadata', check_mode_skip=True) as ctx:
with self.runner(
"state global index_url force python system_site_packages editable pip_args spec_metadata",
check_mode_skip=True,
) as ctx:
ctx.run()
self._capture_results(ctx)
@ -348,14 +378,16 @@ class PipX(StateModuleHelper):
if self.vars.force:
self.changed = True
with self.runner('state global include_injected index_url force editable pip_args name', check_mode_skip=True) as ctx:
with self.runner(
"state global include_injected index_url force editable pip_args name", check_mode_skip=True
) as ctx:
ctx.run(name=name)
self._capture_results(ctx)
def state_uninstall(self):
if self.vars.application:
name = _make_name(self.vars.name, self.vars.suffix)
with self.runner('state global name', check_mode_skip=True) as ctx:
with self.runner("state global name", check_mode_skip=True) as ctx:
ctx.run(name=name)
self._capture_results(ctx)
@ -366,7 +398,7 @@ class PipX(StateModuleHelper):
if not self.vars.application:
self.do_raise(f"Trying to reinstall a non-existent application: {name}")
self.changed = True
with self.runner('state global name python', check_mode_skip=True) as ctx:
with self.runner("state global name python", check_mode_skip=True) as ctx:
ctx.run(name=name)
self._capture_results(ctx)
@ -376,7 +408,10 @@ class PipX(StateModuleHelper):
self.do_raise(f"Trying to inject packages into a non-existent application: {name}")
if self.vars.force:
self.changed = True
with self.runner('state global index_url install_apps install_deps force editable pip_args name inject_packages', check_mode_skip=True) as ctx:
with self.runner(
"state global index_url install_apps install_deps force editable pip_args name inject_packages",
check_mode_skip=True,
) as ctx:
ctx.run(name=name)
self._capture_results(ctx)
@ -384,51 +419,53 @@ class PipX(StateModuleHelper):
name = _make_name(self.vars.name, self.vars.suffix)
if not self.vars.application:
self.do_raise(f"Trying to uninject packages into a non-existent application: {name}")
with self.runner('state global name inject_packages', check_mode_skip=True) as ctx:
with self.runner("state global name inject_packages", check_mode_skip=True) as ctx:
ctx.run(name=name)
self._capture_results(ctx)
def state_uninstall_all(self):
with self.runner('state global', check_mode_skip=True) as ctx:
with self.runner("state global", check_mode_skip=True) as ctx:
ctx.run()
self._capture_results(ctx)
def state_reinstall_all(self):
with self.runner('state global python', check_mode_skip=True) as ctx:
with self.runner("state global python", check_mode_skip=True) as ctx:
ctx.run()
self._capture_results(ctx)
def state_upgrade_all(self):
if self.vars.force:
self.changed = True
with self.runner('state global include_injected force', check_mode_skip=True) as ctx:
with self.runner("state global include_injected force", check_mode_skip=True) as ctx:
ctx.run()
self._capture_results(ctx)
def state_upgrade_shared(self):
with self.runner('state global pip_args', check_mode_skip=True) as ctx:
with self.runner("state global pip_args", check_mode_skip=True) as ctx:
ctx.run()
self._capture_results(ctx)
def state_latest(self):
if not self.vars.application or self.vars.force:
self.changed = True
args_order = 'state global index_url install_deps force python system_site_packages editable pip_args suffix name_source'
args_order = "state global index_url install_deps force python system_site_packages editable pip_args suffix name_source"
with self.runner(args_order, check_mode_skip=True) as ctx:
ctx.run(state='install', name_source=[self.vars.name, self.vars.source])
ctx.run(state="install", name_source=[self.vars.name, self.vars.source])
self._capture_results(ctx)
with self.runner('state global include_injected index_url force editable pip_args name', check_mode_skip=True) as ctx:
ctx.run(state='upgrade')
with self.runner(
"state global include_injected index_url force editable pip_args name", check_mode_skip=True
) as ctx:
ctx.run(state="upgrade")
self._capture_results(ctx)
def state_pin(self):
with self.runner('state global name', check_mode_skip=True) as ctx:
with self.runner("state global name", check_mode_skip=True) as ctx:
ctx.run()
self._capture_results(ctx)
def state_unpin(self):
with self.runner('state global name', check_mode_skip=True) as ctx:
with self.runner("state global name", check_mode_skip=True) as ctx:
ctx.run()
self._capture_results(ctx)
@ -437,5 +474,5 @@ def main():
PipX.execute()
if __name__ == '__main__':
if __name__ == "__main__":
main()