Skip to content

Add module to manage Python versions using uv#11537

Open
mriamah wants to merge 93 commits intoansible-collections:mainfrom
mriamah:feature/uv_python_module
Open

Add module to manage Python versions using uv#11537
mriamah wants to merge 93 commits intoansible-collections:mainfrom
mriamah:feature/uv_python_module

Conversation

@mriamah
Copy link

@mriamah mriamah commented Feb 24, 2026

SUMMARY

Introduces a new module uv_python to manage Python versions using the uv python subcommand from the Astral uv package manager. The module allows users to install, remove, and upgrade patch version of Python interpreters managed by uv.

Design Decisions

  • Valid version numbers consist of two or three dot-separated numeric components, with an optional 'pre-release' tag on the end such as 3.12, 3.12.3, 3.15.0a5.
  • Does not support advanced uv selector formats in the initial release (e.g. >=3.12,<3.13, cpython@3.12).
  • Implements full check_mode support.
  • Does not implement diff_mode.

ISSUE TYPE

  • New Module/Plugin Pull Request

COMPONENT NAME

uv_python


ADDITIONAL INFORMATION

Example Usage

- name: Ensure Python 3.12 latest patch is installed
  community.general.uv_python:
    version: "3.12"
    state: latest

- name: Install exact Python version
  community.general.uv_python:
    version: 3.12.3
    state: present

- name: Remove all 3.11 patch versions
  community.general.uv_python:
    version: 3.11
    state: absent

This was recently published as a collection mriamah.uv.python in Ansible galaxy.

@ansibullbot ansibullbot added the needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI label Feb 25, 2026
Co-authored-by: Felix Fontein <felix@fontein.de>
@ansibullbot ansibullbot removed the needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI label Feb 25, 2026
Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mriamah thank you for your contribution!

Please see some initial comments. The markup comments apply to other parts as well, please review the entire docs, not just the place pointed to.

state:
description:
- Desired state of the specified Python version.
- |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not have effect you are likely imagining: the content will be rendered as a single paragraph block, the newlines will be reduced to single spaces. If you want to make multiple paragraphs, make each one of them a list item under description.

Copy link
Author

@mriamah mriamah Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. I actually did that to avoid a linting error since the paragraphs are over 160 charaters.

EXAMPLES = r"""
- name: Install Python 3.14
community.general.uv_python:
version: "3.14"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add a note in the description of version to remind users that when version is major or major.minor, the number must be enclosed in quotes so it is parsed as string (and not as an int or a float).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, whether the user puts quotes or not, the value given will always be converted to a string. I just made some examples with versions in quotes or without to show that it can be written in both forms, but I didn't see that my examples could also be interpreted this way, I will add more examples to clarify this. Thanks for pointing this out.

@mriamah mriamah force-pushed the feature/uv_python_module branch from 8c1a765 to d28c9b7 Compare March 5, 2026 16:55
@ansibullbot ansibullbot added the ci_verified Push fixes to PR branch to re-run CI label Mar 5, 2026
@mriamah mriamah closed this Mar 5, 2026
@mriamah mriamah force-pushed the feature/uv_python_module branch from 6c93ad8 to e853a6f Compare March 5, 2026 17:26
@mriamah mriamah reopened this Mar 5, 2026
@mriamah mriamah force-pushed the feature/uv_python_module branch 2 times, most recently from d28c9b7 to f8bc6e8 Compare March 5, 2026 17:40
@ansibullbot ansibullbot added ci_verified Push fixes to PR branch to re-run CI and removed ci_verified Push fixes to PR branch to re-run CI labels Mar 5, 2026
@mriamah mriamah force-pushed the feature/uv_python_module branch 3 times, most recently from 00d8ec2 to 05c100c Compare March 5, 2026 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-12 Automatically create a backport for the stable-12 branch check-before-release PR will be looked at again shortly before release and merged if possible. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR new_contributor Help guide this first time contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants