Repository navigation
Add a uv package manager for Python CLI tools - #5801
kai (yezhengkai) wants to merge 11 commits into
Conversation
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.
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
Gabriel Dufresne (GabrielDuf)
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
_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 |
There was a problem hiding this comment.
I don't think the interpreter can ever be set back to "Default" once a value is chosen:
- an empty
options.Uv_PythonRequestfalls back tooverrides.Uv_PythonRequest ?? recorded?.PythonRequest ApplyOperationOverridesnever clears an override_getOperationResultrecordsrecorded?.PythonRequestagain after each install/updateNoPythonDownloadsis 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" }, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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}'"); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.Architectureon updates; it now runs here as well as from_getOperationParameters, and twice on the broker path (this call plus the existing one withCommandRole) - this call passes
Rolewhile the broker path passesCommandRole, 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 => |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
(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 ~).
What this adds
This PR adds a package manager for Astral's uv, focused on the
uv toolsubcommand. 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.Uvproject (iduv) follows the existing manager structure: aPackageManagerimplementation, 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 onepypi_simple_index.cacheand 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
CompareVersionswith PEP 440 (PythonVersioninUniGetUI.Core.Tools). This orders1.0.0rc1below1.0.0and reads1.0.0-1as an implicit post-release, which the numeric default comparator would get backwards.PyPIProjectClient.ParseVersionsdrops a release only when every file in it is yanked, so a partially yanked release stays listed.PinUpdateToNewVersion), andUpdateVersionPintargets it exactly.--prerelease allowwhen the option is set (verified against uv 0.13.8). The version list for update selection includes pre-releases, matching Pip.uv python list --output-format jsonis the catalogue: a row with a non-nullpathis installed, one with a non-nullurlis downloadable. The chosen request is persisted asInstallOptions.Uv_PythonRequest,Uv_ManagedPythonandUv_NoPythonDownloads, andUvToolInstallRecordsremembers the request an install used, so an upgrade repeats it instead of silently switching interpreters.SupportsProxy = YesandSupportsProxyAuth = true, like Pip. uv honoursHTTPS_PROXY, includinguser:pass@host.Testing
Measured at
cca3c5604on Windows x64.Local
The focused suite (uv, Pip, reinstall-on-update, skipped-major updates) passes on both target frameworks:
That is 202 tests on
net10.0and 210 onnet10.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 runsuv python listfor 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 needsSeCreateSymbolicLinkPrivilege, andPowerShellOperationLauncherTests.TheScopeRetryMarkersSurviveTheLauncherreads a PowerShell error message that wraps differently under the longerx64output path. None touchUv,PyPIorPip.Both formatters exit 0:
dotnet format whitespace src --folderanddotnet format style src/UniGetUI.Windows.slnx --no-restore.GitHub Actions
.NET Testspasses on run 44879830307 atcca3c5604.Closes #3696
Generated with OpenCode