Skip to content

Commit 77e397c

Browse files
ZephOnepatchback[bot]
authored andcommitted
Add cpanm option --with-recommends (#9555)
* Add cpanm option --with-recommands Fix #9554 * With accepted suggestions * Use install_recommendations for cpanm option --with-recommends * Fix typo in changelogs/fragments/9554 recommands -> recommends * Doc for options users have for recommands and suggests dependencies * Add new args to the command runner. * Add test for cpanm --with-recommends (cherry picked from commit e2d19a9)
1 parent 6907ae5 commit 77e397c

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
minor_changes:
2+
- cpanm - enable usage of option ``--with-recommends`` (https://github.com/ansible-collections/community.general/issues/9554, https://github.com/ansible-collections/community.general/pull/9555).
3+
- cpanm - enable usage of option ``--with-suggests`` (https://github.com/ansible-collections/community.general/pull/9555).

plugins/modules/cpanm.py

+30-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@
5656
- Only install dependencies.
5757
type: bool
5858
default: false
59+
install_recommendations:
60+
description:
61+
- If V(true), installs dependencies declared as recommends per META spec.
62+
- If V(false), it ensures the dependencies declared as recommends are not installed, overriding any decision made earlier in E(PERL_CPANM_OPT).
63+
- If parameter is not set, C(cpanm) will use its existing defaults.
64+
- When these dependencies fail to install, cpanm continues the installation, since they are just recommendation.
65+
type: bool
66+
version_added: 10.3.0
67+
install_suggestions:
68+
description:
69+
- If V(true), installs dependencies declared as suggests per META spec.
70+
- If V(false), it ensures the dependencies declared as suggests are not installed, overriding any decision made earlier in E(PERL_CPANM_OPT).
71+
- If parameter is not set, C(cpanm) will use its existing defaults.
72+
- When these dependencies fail to install, cpanm continues the installation, since they are just suggestion.
73+
type: bool
74+
version_added: 10.3.0
5975
version:
6076
description:
6177
- Version specification for the perl module. When O(mode) is V(new), C(cpanm) version operators are accepted.
@@ -167,6 +183,8 @@ class CPANMinus(ModuleHelper):
167183
mirror=dict(type='str'),
168184
mirror_only=dict(type='bool', default=False),
169185
installdeps=dict(type='bool', default=False),
186+
install_recommendations=dict(type='bool'),
187+
install_suggestions=dict(type='bool'),
170188
executable=dict(type='path'),
171189
mode=dict(type='str', default='new', choices=['compatibility', 'new']),
172190
name_check=dict(type='str')
@@ -181,6 +199,8 @@ class CPANMinus(ModuleHelper):
181199
mirror=cmd_runner_fmt.as_opt_val('--mirror'),
182200
mirror_only=cmd_runner_fmt.as_bool("--mirror-only"),
183201
installdeps=cmd_runner_fmt.as_bool("--installdeps"),
202+
install_recommendations=cmd_runner_fmt.as_bool("--with-recommends", "--without-recommends", ignore_none=True),
203+
install_suggestions=cmd_runner_fmt.as_bool("--with-suggests", "--without-suggests", ignore_none=True),
184204
pkg_spec=cmd_runner_fmt.as_list(),
185205
cpanm_version=cmd_runner_fmt.as_fixed("--version"),
186206
)
@@ -254,7 +274,16 @@ def process(rc, out, err):
254274
return
255275
pkg_spec = self.sanitize_pkg_spec_version(v[pkg_param], v.version)
256276

257-
with self.runner(['notest', 'locallib', 'mirror', 'mirror_only', 'installdeps', 'pkg_spec'], output_process=process) as ctx:
277+
with self.runner([
278+
'notest',
279+
'locallib',
280+
'mirror',
281+
'mirror_only',
282+
'installdeps',
283+
'install_recommendations',
284+
'install_suggestions',
285+
'pkg_spec'
286+
], output_process=process) as ctx:
258287
self.changed = ctx.run(pkg_spec=pkg_spec)
259288

260289

tests/unit/plugins/modules/test_cpanm.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,43 @@ test_cases:
361361
cpanm (App::cpanminus) version 1.7047 (/usr/local/bin/cpanm)
362362
perl version 5.041005 (/usr/local/bin/perl)
363363
err: ""
364+
- id: install_dancer_with_recommends
365+
input:
366+
name: Dancer2
367+
install_recommendations: true
368+
output:
369+
changed: true
370+
mocks:
371+
run_command:
372+
- command: [/testbin/cpanm, --version]
373+
environ: *env-def-true
374+
rc: 0
375+
out: |
376+
cpanm (App::cpanminus) version 1.7047 (/usr/local/bin/cpanm)
377+
perl version 5.041005 (/usr/local/bin/perl)
378+
err: ""
379+
- command: [/testbin/cpanm, --with-recommends, Dancer2]
380+
environ: *env-def-true
381+
rc: 0
382+
out: ""
383+
err: ""
384+
- id: install_dancer_with_suggests
385+
input:
386+
name: Dancer2
387+
install_suggestions: true
388+
output:
389+
changed: true
390+
mocks:
391+
run_command:
392+
- command: [/testbin/cpanm, --version]
393+
environ: *env-def-true
394+
rc: 0
395+
out: |
396+
cpanm (App::cpanminus) version 1.7047 (/usr/local/bin/cpanm)
397+
perl version 5.041005 (/usr/local/bin/perl)
398+
err: ""
399+
- command: [/testbin/cpanm, --with-suggests, Dancer2]
400+
environ: *env-def-true
401+
rc: 0
402+
out: ""
403+
err: ""

0 commit comments

Comments
 (0)