Skip to content

Add a uv package manager for Python CLI tools - #5801

Open
kai (yezhengkai) wants to merge 11 commits into
Devolutions:mainfrom
yezhengkai:feat/uv-manager
Open

kai (yezhengkai) wants to merge 11 commits into
Devolutions:mainfrom
yezhengkai:feat/uv-manager

Conversation

@yezhengkai

@yezhengkai kai (yezhengkai) commented Nov 19, 2026 •

Copy link
Copy Markdown
  • I have read the contributing guidelines, and I agree with the Code of Conduct.
  • Have you checked that there aren't other open pull requests for the same changes?
  • Have you tested that the committed code can be executed without errors?
  • Have you confirmed that this issue is caused by UniGetUI itself, and not by the package manager or the package involved? N/A: this PR adds a new package-manager integration; there is no pre-existing defect to attribute to UniGetUI.

What this adds

This PR adds a package manager for Astral's uv, focused on the uv tool subcommand. It lists, installs, updates and uninstalls Python CLI tools that uv keeps in isolated tool environments, and lets the install-options dialog pick which Python a tool runs on.

The new UniGetUI.PackageEngine.Managers.Uv project (id uv) follows the existing manager structure: a PackageManager implementation, one details helper, one operation helper, and a source helper.

A new shared project, UniGetUI.PackageEngine.Managers.Generic.PyPI, holds the PyPI index and project lookups. Pip now reads its index through the same service, so both managers share one pypi_simple_index.cache and rank search results the same way.

The TUI ships the manager too. uv stands in the fake data set, and the E2E suite updates a uv package through the fake manager process.

Decisions

  • Version comparison. uv versions come from PyPI, so the manager overrides CompareVersions with PEP 440 (PythonVersion in UniGetUI.Core.Tools). This orders 1.0.0rc1 below 1.0.0 and reads 1.0.0-1 as an implicit post-release, which the numeric default comparator would get backwards.
  • Yanked releases. PyPIProjectClient.ParseVersions drops a release only when every file in it is yanked, so a partially yanked release stays listed.
  • Skipped major updates. uv updates to an exact version, so with the existing "Skip major updates" option the manager offers the newest stable version within the installed major (PinUpdateToNewVersion), and UpdateVersionPin targets it exactly.
  • Pre-releases. Install and update pass --prerelease allow when the option is set (verified against uv 0.13.8). The version list for update selection includes pre-releases, matching Pip.
  • Python interpreter choice. uv python list --output-format json is the catalogue: a row with a non-null path is installed, one with a non-null url is downloadable. The chosen request is persisted as InstallOptions.Uv_PythonRequest, Uv_ManagedPython and Uv_NoPythonDownloads, and UvToolInstallRecords remembers the request an install used, so an upgrade repeats it instead of silently switching interpreters.
  • Proxy. SupportsProxy = Yes and SupportsProxyAuth = true, like Pip. uv honours HTTPS_PROXY, including user:pass@host.

Testing

Measured at cca3c5604 on Windows x64.

Local

The focused suite (uv, Pip, reinstall-on-update, skipped-major updates) passes on both target frameworks:

dotnet test src/UniGetUI.PackageEngine.Tests/UniGetUI.PackageEngine.Tests.csproj --filter "FullyQualifiedName~UvManagerTests|FullyQualifiedName~UvInstallOptionsTests|FullyQualifiedName~PipManagerTests|FullyQualifiedName~ReinstallOnUpdate|FullyQualifiedName~SkipMajorUpdates"

That is 202 tests on net10.0 and 210 on net10.0-windows10.0.26100.0.

The install-options dialog is covered through a headless Avalonia session that drives the real InstallOptionsControl: 3 tests. The interpreter test runs uv python list for real, and reports an empty catalogue when the build machine has no uv.

The whole solution, dotnet test src/UniGetUI.Windows.slnx -p:Platform=x64 -maxcpucount:1, reports 10797 passed, 3 failed and 25 skipped. All three come from this machine rather than from the branch: two tests create a symlink, which needs SeCreateSymbolicLinkPrivilege, and PowerShellOperationLauncherTests.TheScopeRetryMarkersSurviveTheLauncher reads a PowerShell error message that wraps differently under the longer x64 output path. None touch Uv, PyPI or Pip.

Both formatters exit 0: dotnet format whitespace src --folder and dotnet format style src/UniGetUI.Windows.slnx --no-restore.

GitHub Actions

.NET Tests passes on run 44879830307 at cca3c5604.


Closes #3696

Generated with OpenCode

The install-options dialog grows a Python section for managers that declare
SupportsCustomPythonInterpreters: an interpreter list built from
`uv python list --output-format json`, a uv-managed or system choice, and a
"Do not download Python interpreters" toggle. The choice travels as
InstallOptions.Uv_PythonRequest, Uv_ManagedPython and Uv_NoPythonDownloads;
ApplyOperationOverrides copies it onto the package on both the local and the
broker path, and UvToolInstallRecords keeps the original request so an
upgrade reuses it.

GetStandaloneParameters hands the options to the helper without applying
them to the package, which is the path the dialog previews through, so the
helper reads options.Uv_* before the package overrides. The command shown
while the dialog is open then carries the flags the same dialog would start.
`uv python` is a top-level subcommand, so its listing neither carries the
`tool` call arguments nor omits --output-format json.
The parser fixtures are text uv actually printed for `uv tool list`,
`uv outdated` and `uv python list`, so a new uv release that changes the
shape shows up as a failing test instead of a silent mismatch.
PyPI drops yanked releases and orders pre-releases below their final
release. The manager leaves a release out only when every file in it is
yanked, lists stable releases in the version dropdown while keeping
pre-releases available to within-major selection, and pins a skipped
major update to a version that is still eligible.
The install records call the JSON serializer through JsonTypeInfo, the
license table knows uv's Apache license, and the TUI expectations follow
the package counts the uv fake data adds.
@github-actions github-actions Bot added pip new-feature A new feature that could be useful in WingetUI labels Nov 19, 2026
Keep the PyPI index and version-lookup changes from upstream in the shared PyPI service: the idle release, the byte-array parse and the failure reporting now live in PyPIIndexClient and Pip, so nothing moved back into Pip.cs.
# Conflicts:
#	src/UniGetUI.PackageEngine.Tests/PipManagerTests.cs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this, the uv integration is well structured. A few things to look at, mostly around how the Python interpreter choice is persisted and how uv's process is run. Details inline.

o.Architecture = (SelectedArch != defaultLabel && SelectedArch is not null) ? SelectedArch : "";
o.InstallationScope = ScopeToString(SelectedScope);

o.Uv_PythonRequest = _pythonSelections.TryGetValue(SelectedPython ?? "", out string? request)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

_pythonSelections is only filled once LoadPythonOptionsAsync gets the result of uv python list, which can take a few seconds. If the user saves before that, SelectedPython is still null, TryGetValue fails and Uv_PythonRequest is saved as "", so the interpreter that was saved earlier is lost without any sign.

Could the snapshot keep _options.Uv_PythonRequest until the list has loaded (or until the user actually changes the selection)?

// The dialog previews a command through GetStandaloneParameters, which hands the
// options straight to this method without applying them to the package. Read the
// options first so the preview matches the operation the same dialog would start.
string? pythonRequest = options.Uv_PythonRequest.Length > 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think the interpreter can ever be set back to "Default" once a value is chosen:

  • an empty options.Uv_PythonRequest falls back to overrides.Uv_PythonRequest ?? recorded?.PythonRequest
  • ApplyOperationOverrides never clears an override
  • _getOperationResult records recorded?.PythonRequest again after each install/update
  • NoPythonDownloads is OR'ed with every earlier value, so unchecking it does nothing

So after one install with --python 3.11 --no-python-downloads, every later upgrade keeps both flags until uv_tool_install_records.json is deleted by hand. The dialog probably needs a way to say "explicitly default" that wins over the record, and the record should store what was actually used rather than merging it with the earlier one.

{ "npm", "Artistic License 2.0" },
{ "Pip", "MIT" },
{ "parse_pip_search", "MIT" },
{ "Uv", "Apache v2" },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Licenses.cs was removed on main (#5805): third-party notices are now generated from the build, so there is no hand-maintained license list any more. This currently conflicts (modify/delete) with main. uv isn't shipped with UniGetUI, so I think these entries can just be dropped when merging main (lang_en.json conflicts as well).


protected override void _performExtraLoadingSteps()
{
Environment.SetEnvironmentVariable("NO_COLOR", "1", EnvironmentVariableTarget.Process);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This sets NO_COLOR=1 for the whole UniGetUI process, so every child process inherits it, not only uv: WinGet, npm, Cargo, pre/post-install scripts, and apps launched from UniGetUI. Could it be set only on uv's processes instead (StartInfo.Environment["NO_COLOR"] = "1" in RunUvCli / _loadManagerVersion, and in the operation process), as XcodesRunner and AgentPluginProcessRunner do?

/// Runs the uv executable. Tool subcommands run under <c>uv tool</c>, which the manager's
/// call arguments already name; <c>uv python</c> is top level, so it must not carry them.
/// </summary>
internal IReadOnlyList<string> RunUvCli(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

RunUvCli returns whatever stdout contained and never looks at process.ExitCode. When uv tool list --outdated fails (offline, broken proxy, corrupt receipt), it writes only to stderr and exits non-zero. The caller then parses an empty list, closes the task with 0 and reports "Found 0 available updates", and the installed list has the same problem. Throwing on a non-zero exit would let the loader show the failure instead of an empty list.

query,
PyPIIndexClient.GetProjectNames(logger)
);
logger.Log($"Matched {matches.Length} packages for query '{query}'");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On success this never calls logger.Close(0); the logger is closed only in the catch. Pip's version closes it before returning, so each successful uv search currently leaves an unfinished FindPackages entry in the operation log.

{
// Both execution vehicles, the local process and the agent broker, funnel through
// here, so options persisted by the install-options GUI reach the helpers either way.
Package.Manager.OperationHelper.ApplyOperationOverrides(Package, Options, Role);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This now runs ApplyOperationOverrides for every manager at the start of every operation, to get uv's saved options to its helper. That changes a shared path:

  • WinGet's override sets options.Architecture on updates; it now runs here as well as from _getOperationParameters, and twice on the broker path (this call plus the existing one with CommandRole)
  • this call passes Role while the broker path passes CommandRole, and the two differ for reinstall-on-update

Since UvPkgOperationHelper._getOperationParameters already reads options before the overrides, could the uv-specific handling stay in the uv helper and leave this path unchanged?

/// True when the tool was installed with an exact `==` pin. uv refuses to upgrade such a
/// tool ("Nothing to upgrade"), so it must not be offered as an update candidate.
/// </summary>
public bool IsPinnedToExactVersion =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Together with the custom-version install (uv tool install "ruff==0.5.0"), this means that installing a specific version from the version picker hides every future update for that tool: uv records [required: ==0.5.0] and ParseAvailableUpdates then always skips it, even after the version is cleared in the install options. The only trace is a log line. Is that intended? If so, it may be worth telling the user somewhere other than the log.

Related: the skip-major path sends uv tool upgrade "pkg==X". The tests only check the argument list. Has it been verified that uv tool upgrade accepts a version specifier, and what requirement does it record afterwards?

/// the ~38 MB download inside the search timeout window. Only the file needs to be
/// ready; a fresh one is not loaded until a search.
/// </summary>
internal static Task PreWarmIndexAsync()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pip and uv both call PreWarmIndexAsync when they start, and GetProjectNamesCore has no single-flight guard. With a stale or missing cache (every 24 h, and on the first run after the rename to pypi_simple_index.cache), both download and parse the ~38 MB index at the same time, and both File.WriteAllLines to the same path. One of those writes fails, and a search that runs meanwhile can read a half-written file and keep a truncated index in memory. Sharing one in-flight task would fix it. The old pip_simple_index.cache is also left behind on disk.

return null;

JsonObject? file = contents["url"] as JsonObject
?? (contents["urls"] as JsonArray)?[0] as JsonObject;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(contents["urls"] as JsonArray)?[0] throws ArgumentOutOfRangeException when urls is an empty array (a project whose latest release has no files), so the details page fails part-way instead of this returning null. FirstOrDefault() would avoid it.

Also, PipPkgDetailsHelper still parses the same JSON itself; moving it onto PyPIProjectClient would keep the two managers from drifting apart (the dependency parsing already differs, for example on ~).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature A new feature that could be useful in WingetUI pip

Development

Successfully merging this pull request may close these issues.

[FEATURE REQUEST] add uv as an alternative to pip and pipx

2 participants