Skip to content

Commit

Permalink
pipx: Allow injected modules to add apps (#6198)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update plugins/modules/pipx.py

Co-authored-by: Felix Fontein <[email protected]>

---------

Co-authored-by: Felix Fontein <[email protected]>
(cherry picked from commit 6fa833f)
  • Loading branch information
darkrain42 authored and patchback[bot] committed Mar 26, 2023
1 parent 5e1508e commit 6075145
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/6198-pipx-inject-install-apps.yml
Original file line number Diff line number Diff line change
@@ -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).
1 change: 1 addition & 0 deletions plugins/module_utils/pipx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
12 changes: 10 additions & 2 deletions plugins/modules/pipx.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,17 @@
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:
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -271,7 +279,7 @@ def state_inject(self):
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)

Expand Down
12 changes: 12 additions & 0 deletions tests/integration/targets/pipx/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

##############################################################################
Expand Down

0 comments on commit 6075145

Please sign in to comment.