5 Commits

Author SHA1 Message Date
Aurelio Jargas
34c30b9fa5 Add role: ensure-python-command, refactor similar roles
This role ensures that a specific pip-installable command is
available.

Example usage:

    - role: ensure-python-command
      vars:
        ensure_python_command_name: poetry
        ensure_python_command_version: ==1.8.5  # omit to install latest

In this case, if the `poetry` command is not already available, pip will
install it in a new venv. Either way, after running this role, the
`ensure_python_command_executable` variable will hold the full path to
the command.

We already have similar roles for specific commands:

- ensure-nox
- ensure-poetry
- ensure-pyproject-build
- ensure-tox
- ensure-twine
- ensure-uv

These roles are essentially copies of each other with different command
names. This new role consolidates that code. The existing roles now act
as wrappers that just set variables and call the new role.

> Note: The `ensure-tox` role has not been refactored due to exclusive
> legacy code related to Python 2, which must be removed first.

The new role introduces three variables to replace the overloaded
`ensure_<command>_executable` variable from the other roles:

- `ensure_python_command_name` (input, command name)
- `ensure_python_command_existing` (input, existing path for the command)
- `ensure_python_command_executable` (output, detected/installed path)

This separation avoids using the same variable as both input and output,
which can cause issues due to Ansible's variable precedence rules:

    https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html

    Understanding variable precedence

    ...
    19. set_facts / registered vars
    20. role (and include_role) params
    ...

Since we use `set_fact` inside the role, it is ineffective when the same
variable is also passed as a role parameter :/

I'm not adding tests for the new role because its functionality is
already covered by the existing tests for all the refactored roles:

- test-playbooks/ensure-nox.yaml
- test-playbooks/ensure-poetry.yaml
- test-playbooks/ensure-pyproject-build.yaml
- test-playbooks/ensure-twine.yaml
- test-playbooks/ensure-uv.yaml

Change-Id: Idd970cb31bd928576bca3602ce96fbc491ecdb60
2025-03-25 22:06:34 +01:00
Brian Haley
84082ed982 Update ensure-twine role
Install twine into a venv and set appropriate environment
variables. Also added tests.

Based on commit adding `ensure-nox` (77b1b24) role.

Related-bug: #2095514
Change-Id: Ibb4e89f79879b4d0ae0294440c9c0b79fc57a7fa
2025-01-31 12:23:08 -05:00
Ian Wienand
ffe4f4fea5 ensure-twine: make python3 default, ensure pip installed
Make the default twine python installation use "python3".  Use the
ensure-pip role before calling pip.

This role currently isn't tested; it is added with upload-pypi testing
in the follow-on Ie40ec32b3b2ffc4646301c6e145c527fe6a3bae2

Change-Id: I55ef79bf9c5af9e4d1da24ed654821277edb663b
2022-07-13 15:18:10 +10:00
Guillaume Chauvel
76eda39210 ensure-twine: Fix missing default value twine_executable
Change-Id: I7a9221ecc8fc40a152040b9ae857253a8f7775ff
2020-06-01 09:57:20 +02:00
Doug Hellmann
125eeed6fe enable setting python version for ensure-twine
Add twine_python so we can control the version of python used to
install twine.

Change-Id: I36ddbdf78f549ddc022cce86f3ada9631fb19c37
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2018-11-08 14:06:07 -05:00