Skip to content

Conversation

zanieb
Copy link
Member

@zanieb zanieb commented Aug 15, 2025

Allows pinning the Python build version via environment variables, e.g., UV_PYTHON_CPYTHON_BUILD=.... Each variable is implementation specific, because they use different versioning schemes.

Updates the Python download metadata to include a build string, so we can filter downloads by the pin. Writes the build version to a file in the managed install, e.g., cpython-3.10.18-macos-aarch64-none/BUILD, so we can filter installed versions by the pin.

Some important follow-up here:

  • Include the build version in not found errors (when pinned)
  • Automatically use a remote list of Python downloads to satisfy build versions not present in the latest embedded download metadata

Some less important follow-ups to consider:

  • Allow using ranges for build version pins

@zanieb zanieb force-pushed the zb/download-build-key branch from f12bae7 to 3212cb3 Compare August 15, 2025 19:26
@zanieb zanieb temporarily deployed to uv-test-registries August 15, 2025 19:30 — with GitHub Actions Inactive
@zanieb zanieb temporarily deployed to uv-test-registries August 15, 2025 19:35 — with GitHub Actions Inactive
@zanieb zanieb temporarily deployed to uv-test-registries August 15, 2025 20:20 — with GitHub Actions Inactive
@zanieb zanieb added enhancement New feature or improvement to existing functionality configuration Settings and such labels Aug 16, 2025
@zanieb zanieb temporarily deployed to uv-test-registries August 18, 2025 13:04 — with GitHub Actions Inactive
@zanieb zanieb force-pushed the zb/download-build-key branch from a0cd585 to 6a8d153 Compare August 18, 2025 14:29
@zanieb zanieb temporarily deployed to uv-test-registries August 18, 2025 14:36 — with GitHub Actions Inactive
@zanieb zanieb temporarily deployed to uv-test-registries August 18, 2025 21:49 — with GitHub Actions Inactive
@zanieb zanieb temporarily deployed to uv-test-publish August 18, 2025 21:49 — with GitHub Actions Inactive
@zanieb zanieb force-pushed the zb/download-build-key branch from ec1816c to b145177 Compare August 18, 2025 21:54
@zanieb zanieb force-pushed the zb/download-build-key branch from b145177 to 96a2dbd Compare August 18, 2025 22:09
@zanieb zanieb temporarily deployed to uv-test-registries August 18, 2025 22:23 — with GitHub Actions Inactive
@zanieb zanieb temporarily deployed to uv-test-registries August 19, 2025 21:09 — with GitHub Actions Inactive
@zanieb zanieb temporarily deployed to uv-test-publish August 19, 2025 21:09 — with GitHub Actions Inactive
@zanieb zanieb temporarily deployed to uv-test-registries August 19, 2025 22:36 — with GitHub Actions Inactive
@zanieb zanieb temporarily deployed to uv-test-registries August 20, 2025 15:52 — with GitHub Actions Inactive
@zanieb zanieb force-pushed the zb/download-build-key branch from 1767aee to 4c1c479 Compare August 20, 2025 15:58
@zanieb zanieb temporarily deployed to uv-test-registries August 20, 2025 16:00 — with GitHub Actions Inactive
@zanieb zanieb force-pushed the zb/download-build-key branch from 4c1c479 to 9a34dcd Compare August 20, 2025 16:43
@zanieb zanieb temporarily deployed to uv-test-registries August 20, 2025 16:45 — with GitHub Actions Inactive
@zanieb zanieb force-pushed the zb/download-build-key branch from 9a34dcd to 5115bd6 Compare August 20, 2025 17:43
@zanieb zanieb temporarily deployed to uv-test-registries August 20, 2025 17:46 — with GitHub Actions Inactive
@zanieb zanieb force-pushed the zb/download-build-key branch from 5115bd6 to 39f569d Compare August 20, 2025 18:51
@zanieb zanieb temporarily deployed to uv-test-registries August 20, 2025 18:53 — with GitHub Actions Inactive
@zanieb zanieb force-pushed the zb/download-build-key branch from 39f569d to 58c88e7 Compare August 20, 2025 19:22
@zanieb zanieb temporarily deployed to uv-test-registries August 20, 2025 19:25 — with GitHub Actions Inactive
@zanieb zanieb force-pushed the zb/download-build-key branch from 58c88e7 to a5291b7 Compare August 20, 2025 19:43
@zanieb zanieb temporarily deployed to uv-test-registries August 20, 2025 19:45 — with GitHub Actions Inactive
@zanieb zanieb force-pushed the zb/download-build-key branch from a5291b7 to 97825d0 Compare August 20, 2025 20:00
@zanieb zanieb temporarily deployed to uv-test-registries August 20, 2025 20:03 — with GitHub Actions Inactive
@zanieb zanieb force-pushed the zb/download-build-key branch from 97825d0 to e193380 Compare August 20, 2025 20:17
@zanieb zanieb temporarily deployed to uv-test-registries August 20, 2025 20:19 — with GitHub Actions Inactive
@zanieb zanieb marked this pull request as ready for review August 20, 2025 20:30
/// Add extra standard filtering for Python executable names, e.g., stripping version number
/// and `.exe` suffixes.
#[must_use]
pub fn with_filtered_python_names(mut self) -> Self {
Copy link
Member Author

Choose a reason for hiding this comment

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

Absolutely nightmarish to get the filters working on Windows and Unix. Hopefully this makes them more robust elsewhere.

Comment on lines +822 to +833
/// A wrapper type to display a `ManagedPythonDownload` with its build information.
pub struct ManagedPythonDownloadWithBuild<'a>(&'a ManagedPythonDownload);

impl Display for ManagedPythonDownloadWithBuild<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(build) = self.0.build {
write!(f, "{}+{}", self.0.key, build)
} else {
write!(f, "{}", self.0.key)
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I want to make use of this for some error messages to avoid confusion when this is in a request. I'm not sure what the best way to do so is yet though.

) -> Result<Option<String>, BuildVersionError> {
let variable = python_build_version_variable(implementation);

let Some(build_os) = env::var_os(variable) else {
Copy link
Member

Choose a reason for hiding this comment

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

We should use env::var here, this also avoids using our own error type

Copy link
Member Author

@zanieb zanieb Aug 21, 2025

Choose a reason for hiding this comment

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

I don't want to use env::var here, it will error if not present and I want that to have different behavior. I also want the dedicated error type for when we perform further validation of these values in the future, e.g., we know what a well formed build version looks like.

Copy link
Member

Choose a reason for hiding this comment

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

It makes sense if we add our own validation logic on top.

}

/// Get the environment variable name for the build constraint for a given implementation.
pub(crate) fn python_build_version_variable(implementation: ImplementationName) -> &'static str {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a method on implementation name?

Copy link
Member Author

Choose a reason for hiding this comment

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

It could be 🤔 I wanted to keep all this logic together but I don't feel strongly.

@zanieb zanieb temporarily deployed to uv-test-registries August 21, 2025 15:10 — with GitHub Actions Inactive
@zanieb zanieb temporarily deployed to uv-test-registries August 21, 2025 17:41 — with GitHub Actions Inactive
@zanieb zanieb merged commit 9b8d698 into main Aug 25, 2025
96 checks passed
@zanieb zanieb deleted the zb/download-build-key branch August 25, 2025 21:25
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Sep 2, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [astral-sh/uv](https://github.com/astral-sh/uv) | patch | `0.8.13` -> `0.8.14` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>astral-sh/uv (astral-sh/uv)</summary>

### [`v0.8.14`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0814)

[Compare Source](astral-sh/uv@0.8.13...0.8.14)

##### Python

- Add managed CPython distributions for aarch64 musl

##### Enhancements

- Add `--python-platform` to `uv pip check` ([#&#8203;15486](astral-sh/uv#15486))
- Add an environment variable for `UV_ISOLATED` ([#&#8203;15428](astral-sh/uv#15428))
- Add logging to the uv build backend ([#&#8203;15533](astral-sh/uv#15533))
- Allow more trailing null bytes in zip files ([#&#8203;15452](astral-sh/uv#15452))
- Allow pinning managed Python versions to specific build versions ([#&#8203;15314](astral-sh/uv#15314))
- Cache PyTorch wheels by default ([#&#8203;15481](astral-sh/uv#15481))
- Reject already-installed wheels that don't match the target platform ([#&#8203;15484](astral-sh/uv#15484))
- Add `--no-install-local` option to `uv sync`, `uv add` and `uv export`  ([#&#8203;15328](astral-sh/uv#15328))
- Include cycle error message in `uv pip` CLI ([#&#8203;15453](astral-sh/uv#15453))

##### Preview features

- Fix format of `{version}` on `uv format` failure ([#&#8203;15527](astral-sh/uv#15527))
- Lock during installs in `uv format` to prevent races ([#&#8203;15551](astral-sh/uv#15551))
- Respect `--project` in `uv format` ([#&#8203;15438](astral-sh/uv#15438))
- Run `uv format` in the project root ([#&#8203;15440](astral-sh/uv#15440))

##### Configuration

- Add file-to-CLI overrides for build isolation configuration ([#&#8203;15437](astral-sh/uv#15437))
- Add file-to-CLI overrides for reinstall configuration ([#&#8203;15426](astral-sh/uv#15426))

##### Performance

- Cache `WHEEL` and `METADATA` reads in installed distributions ([#&#8203;15489](astral-sh/uv#15489))

##### Bug fixes

- Avoid erroring when creating `venv` in current working directory ([#&#8203;15537](astral-sh/uv#15537))
- Avoid introducing unnecessary system dependency on CUDA ([#&#8203;15449](astral-sh/uv#15449))
- Clear discovered site packages when creating virtual environment ([#&#8203;15522](astral-sh/uv#15522))
- Read index credentials from the environment during `uv publish` checks ([#&#8203;15545](astral-sh/uv#15545))
- Refuse to remove non-virtual environments in `uv venv` ([#&#8203;15538](astral-sh/uv#15538))
- Stop setting `CLICOLOR_FORCE=1` when calling build backends ([#&#8203;15472](astral-sh/uv#15472))
- Support file or directory removal for Windows symlinks ([#&#8203;15543](astral-sh/uv#15543))

##### Documentation

- Fix GitHub guide highlight lines ([#&#8203;15443](astral-sh/uv#15443))
- Move Resolver to new Internals section in the Reference ([#&#8203;15465](astral-sh/uv#15465))
- Split the "Authentication" page into sections ([#&#8203;15575](astral-sh/uv#15575))
- Update uninstall docs to mention `uvw.exe` needs to be removed ([#&#8203;15536](astral-sh/uv#15536))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS44OC4wIiwidXBkYXRlZEluVmVyIjoiNDEuODguMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

configuration Settings and such enhancement New feature or improvement to existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants