From 9cd3f3768658b31198fbfc2b6fa5c237d869388a Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sun, 26 Mar 2023 09:45:48 +0200 Subject: [PATCH] [PR #6198/6fa833fe backport][stable-6] pipx: Allow injected modules to add apps (#6238) pipx: Allow injected modules to add apps (#6198) * pipx: Allow injected modules to add apps Add support for pipx inject's "--include-apps" parameter. * add changelog fragment * fix pipx test ("install_apps", not "include_apps") * fix pipx test -- add a second invocation for install_apps * Update changelogs/fragments/6198-pipx-inject-install-apps.yml Co-authored-by: Felix Fontein * Update plugins/modules/pipx.py Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein (cherry picked from commit 6fa833feed441a1b58585fd6ddf659aa73147558) Co-authored-by: Paul Aurich --- .../fragments/6198-pipx-inject-install-apps.yml | 2 ++ plugins/module_utils/pipx.py | 1 + plugins/modules/pipx.py | 12 ++++++++++-- tests/integration/targets/pipx/tasks/main.yml | 12 ++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/6198-pipx-inject-install-apps.yml diff --git a/changelogs/fragments/6198-pipx-inject-install-apps.yml b/changelogs/fragments/6198-pipx-inject-install-apps.yml new file mode 100644 index 0000000000..59cf0b94fc --- /dev/null +++ b/changelogs/fragments/6198-pipx-inject-install-apps.yml @@ -0,0 +1,2 @@ +minor_changes: + - pipx - optional ``install_apps`` parameter added to install applications from injected packages (https://github.com/ansible-collections/community.general/pull/6198). diff --git a/plugins/module_utils/pipx.py b/plugins/module_utils/pipx.py index 35804c329a..ed23645e39 100644 --- a/plugins/module_utils/pipx.py +++ b/plugins/module_utils/pipx.py @@ -32,6 +32,7 @@ def pipx_runner(module, command, **kwargs): state=fmt.as_map(_state_map), name=fmt.as_list(), name_source=fmt.as_func(fmt.unpack_args(lambda n, s: [s] if s else [n])), + install_apps=fmt.as_bool("--include-apps"), install_deps=fmt.as_bool("--include-deps"), inject_packages=fmt.as_list(), force=fmt.as_bool("--force"), diff --git a/plugins/modules/pipx.py b/plugins/modules/pipx.py index f3bddef459..343d3d5771 100644 --- a/plugins/modules/pipx.py +++ b/plugins/modules/pipx.py @@ -47,10 +47,17 @@ options: If the application source, such as a package with version specifier, or an URL, directory or any other accepted specification. See C(pipx) documentation for more details. - When specified, the C(pipx) command will use I(source) instead of I(name). + install_apps: + description: + - Add apps from the injected packages. + - Only used when I(state=inject). + type: bool + default: false + version_added: 6.5.0 install_deps: description: - Include applications of dependent packages. - - Only used when I(state=install) or I(state=upgrade). + - Only used when I(state=install), I(state=upgrade), or I(state=inject). type: bool default: false inject_packages: @@ -161,6 +168,7 @@ class PipX(StateModuleHelper): 'inject', 'upgrade', 'upgrade_all', 'reinstall', 'reinstall_all', 'latest']), 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), @@ -271,7 +279,7 @@ class PipX(StateModuleHelper): self.do_raise("Trying to inject packages into a non-existent application: {0}".format(self.vars.name)) if self.vars.force: self.changed = True - with self.runner('state index_url force editable pip_args name inject_packages', check_mode_skip=True) as ctx: + with self.runner('state index_url install_apps install_deps force editable pip_args name inject_packages', check_mode_skip=True) as ctx: ctx.run() self._capture_results(ctx) diff --git a/tests/integration/targets/pipx/tasks/main.yml b/tests/integration/targets/pipx/tasks/main.yml index 267c2a2d1a..13360af1d9 100644 --- a/tests/integration/targets/pipx/tasks/main.yml +++ b/tests/integration/targets/pipx/tasks/main.yml @@ -190,6 +190,15 @@ - licenses register: inject_pkgs_ansible_lint +- name: inject packages with apps + community.general.pipx: + state: inject + name: ansible-lint + inject_packages: + - black + install_apps: true + register: inject_pkgs_apps_ansible_lint + - name: cleanup ansible-lint community.general.pipx: state: absent @@ -203,6 +212,9 @@ - inject_pkgs_ansible_lint is changed - '"ansible-lint" in inject_pkgs_ansible_lint.application' - '"licenses" in inject_pkgs_ansible_lint.application["ansible-lint"]["injected"]' + - inject_pkgs_apps_ansible_lint is changed + - '"ansible-lint" in inject_pkgs_apps_ansible_lint.application' + - '"black" in inject_pkgs_apps_ansible_lint.application["ansible-lint"]["injected"]' - uninstall_ansible_lint is changed ##############################################################################