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

@@ -171,31 +171,30 @@ from ansible_collections.community.general.plugins.module_utils.module_helper im
class CPANMinus(ModuleHelper):
output_params = ['name', 'version']
output_params = ["name", "version"]
module = dict(
argument_spec=dict(
name=dict(type='str', aliases=['pkg']),
version=dict(type='str'),
from_path=dict(type='path'),
notest=dict(type='bool', default=False),
locallib=dict(type='path'),
mirror=dict(type='str'),
mirror_only=dict(type='bool', default=False),
installdeps=dict(type='bool', default=False),
install_recommendations=dict(type='bool'),
install_suggestions=dict(type='bool'),
executable=dict(type='path'),
mode=dict(type='str', default='new', choices=['compatibility', 'new']),
name_check=dict(type='str')
name=dict(type="str", aliases=["pkg"]),
version=dict(type="str"),
from_path=dict(type="path"),
notest=dict(type="bool", default=False),
locallib=dict(type="path"),
mirror=dict(type="str"),
mirror_only=dict(type="bool", default=False),
installdeps=dict(type="bool", default=False),
install_recommendations=dict(type="bool"),
install_suggestions=dict(type="bool"),
executable=dict(type="path"),
mode=dict(type="str", default="new", choices=["compatibility", "new"]),
name_check=dict(type="str"),
),
required_one_of=[('name', 'from_path')],
required_one_of=[("name", "from_path")],
)
command = 'cpanm'
command = "cpanm"
command_args_formats = dict(
notest=cmd_runner_fmt.as_bool("--notest"),
locallib=cmd_runner_fmt.as_opt_val('--local-lib'),
mirror=cmd_runner_fmt.as_opt_val('--mirror'),
locallib=cmd_runner_fmt.as_opt_val("--local-lib"),
mirror=cmd_runner_fmt.as_opt_val("--mirror"),
mirror_only=cmd_runner_fmt.as_bool("--mirror-only"),
installdeps=cmd_runner_fmt.as_bool("--installdeps"),
install_recommendations=cmd_runner_fmt.as_bool("--with-recommends", "--without-recommends", ignore_none=True),
@@ -209,7 +208,11 @@ class CPANMinus(ModuleHelper):
if v.mode == "compatibility":
if v.name_check:
self.do_raise("Parameter name_check can only be used with mode=new")
self.deprecate("'mode=compatibility' is deprecated, use 'mode=new' instead", version='13.0.0', collection_name="community.general")
self.deprecate(
"'mode=compatibility' is deprecated, use 'mode=new' instead",
version="13.0.0",
collection_name="community.general",
)
else:
if v.name and v.from_path:
self.do_raise("Parameters 'name' and 'from_path' are mutually exclusive when 'mode=new'")
@@ -220,7 +223,7 @@ class CPANMinus(ModuleHelper):
with self.runner("cpanm_version") as ctx:
rc, out, err = ctx.run()
line = out.split('\n')[0]
line = out.split("\n")[0]
match = re.search(r"version\s+([\d\.]+)\s+", line)
if not match:
self.do_raise(f"Failed to determine version number. First line of output: {line}")
@@ -230,27 +233,29 @@ class CPANMinus(ModuleHelper):
def process(rc, out, err):
return rc == 0
if name is None or name.endswith('.tar.gz'):
if name is None or name.endswith(".tar.gz"):
return False
version = "" if version is None else f" {version}"
env = {"PERL5LIB": f"{locallib}/lib/perl5"} if locallib else {}
runner = CmdRunner(self.module, ["perl", "-le"], {"mod": cmd_runner_fmt.as_list()}, check_rc=False, environ_update=env)
runner = CmdRunner(
self.module, ["perl", "-le"], {"mod": cmd_runner_fmt.as_list()}, check_rc=False, environ_update=env
)
with runner("mod", output_process=process) as ctx:
return ctx.run(mod=f'use {name}{version};')
return ctx.run(mod=f"use {name}{version};")
def sanitize_pkg_spec_version(self, pkg_spec, version):
if version is None:
return pkg_spec
if pkg_spec.endswith('.tar.gz'):
if pkg_spec.endswith(".tar.gz"):
self.do_raise(msg="parameter 'version' must not be used when installing from a file")
if os.path.isdir(pkg_spec):
self.do_raise(msg="parameter 'version' must not be used when installing from a directory")
if pkg_spec.endswith('.git'):
if version.startswith('~'):
if pkg_spec.endswith(".git"):
if version.startswith("~"):
self.do_raise(msg="operator '~' not allowed in version parameter when installing from git repository")
version = version if version.startswith('@') else f"@{version}"
elif version[0] not in ('@', '~'):
version = version if version.startswith("@") else f"@{version}"
elif version[0] not in ("@", "~"):
version = f"~{version}"
return pkg_spec + version
@@ -258,12 +263,12 @@ class CPANMinus(ModuleHelper):
def process(rc, out, err):
if self.vars.mode == "compatibility" and rc != 0:
self.do_raise(msg=err, cmd=self.vars.cmd_args)
return 'is up to date' not in err and 'is up to date' not in out
return "is up to date" not in err and "is up to date" not in out
v = self.vars
pkg_param = 'from_path' if v.from_path else 'name'
pkg_param = "from_path" if v.from_path else "name"
if v.mode == 'compatibility':
if v.mode == "compatibility":
if self._is_package_installed(v.name, v.locallib, v.version):
return
pkg_spec = v[pkg_param]
@@ -273,16 +278,19 @@ class CPANMinus(ModuleHelper):
return
pkg_spec = self.sanitize_pkg_spec_version(v[pkg_param], v.version)
with self.runner([
'notest',
'locallib',
'mirror',
'mirror_only',
'installdeps',
'install_recommendations',
'install_suggestions',
'pkg_spec'
], output_process=process) as ctx:
with self.runner(
[
"notest",
"locallib",
"mirror",
"mirror_only",
"installdeps",
"install_recommendations",
"install_suggestions",
"pkg_spec",
],
output_process=process,
) as ctx:
self.changed = ctx.run(pkg_spec=pkg_spec)
@@ -290,5 +298,5 @@ def main():
CPANMinus.execute()
if __name__ == '__main__':
if __name__ == "__main__":
main()