mirror of
https://github.com/nix-community/home-manager.git
synced 2026-10-02 19:49:18 +00:00
The prune option uninstalled all managed Python versions (and tools) and reinstalled them on every activation, which is slow. Instead, resolve each requested version to the install target uv would produce and uninstall only the difference; already-correct versions are left untouched. Resolving to the install target (not every installed match) also prunes superseded patch releases, which uv retains on upgrade. Tools are diffed by PEP 503-normalized package name: requested names are extracted and normalized at build time, and the installed set is read from uv's tool directory, whose entries are already normalized, so no uv output is parsed. Pruning to an empty set still removes everything.
46 lines
1.6 KiB
Nix
46 lines
1.6 KiB
Nix
{
|
|
programs.uv = {
|
|
enable = true;
|
|
tool = {
|
|
packages = [
|
|
"ruff"
|
|
"black==24.1.0"
|
|
];
|
|
prune = true;
|
|
};
|
|
};
|
|
|
|
test.stubs.uv.name = "uv";
|
|
|
|
nmt.script = ''
|
|
# With prune the set is fully declarative, but only the diff is touched: the
|
|
# installed tools are read from uv's tool directory (entries are already
|
|
# PEP 503-normalized package names) and diffed against the requested names
|
|
# (extras and version specifiers dropped and normalized at build time), so
|
|
# only tools that are no longer requested are uninstalled, one by one.
|
|
assertFileContains activate \
|
|
'uvToolDir=$(@uv@/bin/uv tool dir)'
|
|
assertFileContains activate \
|
|
'ls -1 "$uvToolDir" | sort -u'
|
|
assertFileContains activate \
|
|
"comm -23 - <(printf '%s\n' ruff black | sort -u)"
|
|
assertFileContains activate \
|
|
'run @uv@/bin/uv tool uninstall $VERBOSE_ARG "$uvTool"'
|
|
|
|
# Name normalization happens in Nix now; no shell helper or output parsing.
|
|
assertFileNotRegex activate 'uvNorm'
|
|
assertFileNotRegex activate 'uv tool list'
|
|
|
|
# The old brute-force `uninstall --all` reinstall churn is gone; kept tools
|
|
# are only installed/upgraded, never uninstalled and reinstalled.
|
|
assertFileNotRegex activate 'tool uninstall \$VERBOSE_ARG --all'
|
|
|
|
assertFileContains activate \
|
|
'run @uv@/bin/uv tool install $VERBOSE_ARG ruff'
|
|
assertFileContains activate \
|
|
"run @uv@/bin/uv tool install \$VERBOSE_ARG 'black==24.1.0'"
|
|
assertFileContains activate \
|
|
"run @uv@/bin/uv tool upgrade \$VERBOSE_ARG ruff 'black==24.1.0'"
|
|
'';
|
|
}
|