Add pipx support for installing Python applications#250
Open
mvance wants to merge 3 commits into
Open
Conversation
This PR adds native support for installing global Python applications via pipx, resolving PEP 668 ('externally-managed-environment') errors on modern macOS/Homebrew setups.
Key features:
- Integrated pipx into the default Homebrew package list.
- Added pipx_packages and backend configuration to default.config.yml.
- Implemented robust pipx tasks in tasks/extra-packages.yml with support for:
- Custom executables and backends (e.g., uv).
- Both simple string and dictionary-based package lists.
- Safe handling of null or missing configuration keys.
- Added pipx_ensurepath option with accurate idempotency reporting.
- Updated documentation and requirements (community.general >= 5.5.0) to ensure compatibility.
- Expanded CI test coverage for both string and mapping input formats.
- Polished playbook output using loop_control labels.
Replace verbose `if item is mapping else` conditionals with the standard `default()` filter pattern used by npm, pip, and gem tasks. These patterns are functionally equivalent in Ansible/Jinja2 — `item.name | default(item)` correctly handles both string and mapping inputs. Also remove the boolean second argument to `default()` calls for consistency with existing tasks. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
refactor: simplify Jinja2 patterns in pipx task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the interest of full disclosure, I leveraged AI assistance for this PR; I'd classify it as "Level 6: Bots coded, human understands mostly" on the VisiData scale. That said, I've put the changes through multiple rounds of code review using CodeRabbit, Gemini, cubic.dev, and Claude to achieve consensus.
With Python 3.12, Homebrew began following PEP 668 and recommends using pipx to install Python CLI applications in isolated virtual environments.
This PR adds
pipxsupport, following the pattern used for npm, pip, gem, and composer packages. It adds:pipx_packages: list of applications to install viapipx, supporting both simple strings (- ntfy) and dicts with per-item overrides (state,executable,backend)pipx_ensurepath: opt-in flag to runpipx ensurepathand add the pipx bin directory toPATH(defaults tofalse)pipx_executableandpipx_default_backend: playbook-wide defaults for the pipx binary and package backend (piporuv)pipxadded tohomebrew_installed_packagesso it's present before the tasks runcommunity.general >= 5.5.0added torequirements.yml(thepipxmodule was introduced in 3.8.0, butstate: latestrequires 5.5.0)All new variables default to empty lists or
falseto avoid impacting existing users.NOTE: existing tasks in extra-packages.yml use short module names (pip, gem, etc.); the new tasks use fully-qualified names (ansible.builtin.command, community.general.pipx). The FQCN is required for the community.general module and used on the command task for consistency, but I can align those to short names if you'd prefer uniformity.