Skip to content

Conversation

@zanieb
Copy link
Member

@zanieb zanieb commented Aug 4, 2025

This is the first part of fixing a 0.8.0 regression from #7934

There, we added handling for skipping managed interpreters on the PATH when only-system is used, but did not update the logic to prefer system interpreters over managed ones when system is used. Here, we fix that by skipping managed interpreters when system is used unless only managed interpreters are available. While this logic is applied during in a general discovery method, it's only relevant for the PATH (and the Windows registry) because we already change the order that we inspect installations in when system is used, so the managed installation directory is inspected last.

This behavior did not regress in 0.8, it's always been this way, however, I need this change in order to fix a different bug.

@zanieb zanieb added the bug Something isn't working label Aug 4, 2025
@zanieb zanieb temporarily deployed to uv-test-registries August 4, 2025 14:14 — with GitHub Actions Inactive
@zanieb zanieb changed the title zb/system fix Fix handling of python-preference = system when managed interpreters are on the PATH Aug 4, 2025
@zanieb zanieb temporarily deployed to uv-test-registries August 4, 2025 14:35 — with GitHub Actions Inactive
Comment on lines +781 to +789
// We find the unmanaged interpreter with system Python preferred
uv_snapshot!(context.filters(), context.python_find().arg("--python-preference").arg("system"), @r"
success: true
exit_code: 0
----- stdout -----
[PYTHON-3.12]
----- stderr -----
");
Copy link
Member Author

@zanieb zanieb Aug 4, 2025

Choose a reason for hiding this comment

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

This test case failed prior to this pull request, it'd discover 3.11.

}
}

pub(crate) fn is_system_interpreter(source: PythonSource, interpreter: &Interpreter) -> bool {
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved without change

@zanieb zanieb marked this pull request as ready for review August 4, 2025 14:40
// If we only found managed installations, and the preference allows them, we should return
// the first one.
if let Some(installation) = first_managed {
return Ok(Ok(installation));
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we log something here since we log skipping this installation earlier?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't for first_prerelease, so I just copied that pattern. It does seem reasonable though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

@zanieb zanieb temporarily deployed to uv-test-registries August 4, 2025 15:51 — with GitHub Actions Inactive
@zanieb zanieb enabled auto-merge (squash) August 4, 2025 15:54
@zanieb zanieb merged commit 64e91a7 into main Aug 4, 2025
92 checks passed
@zanieb zanieb deleted the zb/system-fix branch August 4, 2025 16:02
zanieb added a commit that referenced this pull request Aug 5, 2025
…is used (#15061)

This fixes a regression from 0.8.0 from
#7934 and follows
#15059

The regression is from [this
change](https://github.com/astral-sh/uv/pull/7934/files#diff-c7a660ac39628d5e12f388b0cacc7360affa3d7bb21191184d7ee78489675e83),
which was made because we'd otherwise (with the other changes in that
pull request) _filter out_ managed Python interpreters found in virtual
environments.

When `--system` is used we'll convert the default Python preference of
`managed` to `system` which avoids things like `uv pip install --system`
targeting a managed Python installation.

The basic test is

```
uv python install
uv pip install --system anyio
```

Prior to this change, we'd read a managed interpreter from our managed
installation directory and target that. After this change, without
#15059, we'd read a managed interpreter from the PATH and target that.
Both of those experiences are bad, because the managed interpreters are
marked as externally managed. After this change, with #15059, we
properly target the system interpreter.

Since we use `system` instead of `only-system`, if there is not a system
interpreter we'll still retain our existing behavior and use a managed
interpreter. This should limit breakage from the change. Given the
source of the regression, we could probably use `only-system` here. I
don't feel strongly. I think the main benefit of doing so would be that
we'd omit the check for managed installations in error messages when an
interpreter cannot be found?

We can't really add test coverage here because the test suite always has
externally managed interpreters :)
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Aug 6, 2025
This MR contains the following updates:

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

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.5`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#085)

[Compare Source](astral-sh/uv@0.8.4...0.8.5)

##### Enhancements

- Enable `uv run` with a GitHub Gist ([#&#8203;15058](astral-sh/uv#15058))
- Improve HTTP response caching log messages ([#&#8203;15067](astral-sh/uv#15067))
- Show wheel tag hints in install plan ([#&#8203;15066](astral-sh/uv#15066))
- Support installing additional executables in `uv tool install` ([#&#8203;14014](astral-sh/uv#14014))

##### Preview features

- Enable extra build dependencies to 'match runtime' versions ([#&#8203;15036](astral-sh/uv#15036))
- Remove duplicate `extra-build-dependencies` warnings for `uv pip` ([#&#8203;15088](astral-sh/uv#15088))
- Use "option" instead of "setting" in `pylock` warning ([#&#8203;15089](astral-sh/uv#15089))
- Respect extra build requires when reading from wheel cache ([#&#8203;15030](astral-sh/uv#15030))
- Preserve lowered extra build dependencies ([#&#8203;15038](astral-sh/uv#15038))

##### Bug fixes

- Add Python versions to markers implied from wheels ([#&#8203;14913](astral-sh/uv#14913))
- Ensure consistent indentation when adding dependencies ([#&#8203;14991](astral-sh/uv#14991))
- Fix handling of `python-preference = system` when managed interpreters are on the PATH ([#&#8203;15059](astral-sh/uv#15059))
- Fix symlink preservation in virtual environment creation ([#&#8203;14933](astral-sh/uv#14933))
- Gracefully handle entrypoint permission errors ([#&#8203;15026](astral-sh/uv#15026))
- Include wheel hashes from local Simple indexes ([#&#8203;14993](astral-sh/uv#14993))
- Prefer system Python installations over managed ones when `--system` is used ([#&#8203;15061](astral-sh/uv#15061))
- Remove retry wrapper when matching on error kind ([#&#8203;14996](astral-sh/uv#14996))
- Revert `h2` upgrade ([#&#8203;15079](astral-sh/uv#15079))

##### Documentation

- Improve visibility of copy and line separator in dark mode ([#&#8203;14987](astral-sh/uv#14987))

</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:eyJjcmVhdGVkSW5WZXIiOiI0MS41Mi4yIiwidXBkYXRlZEluVmVyIjoiNDEuNTIuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants