-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpip-reset.fish
34 lines (30 loc) · 1.09 KB
/
pip-reset.fish
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function pip-reset -d 'Removes local Python packages, except the default ones'
set default_requirements_path ~/.default-python-packages
if set -q MISE_PYTHON_DEFAULT_PACKAGES_FILE
set default_requirements_path "$MISE_PYTHON_DEFAULT_PACKAGES_FILE"
else if set -q ASDF_PYTHON_DEFAULT_PACKAGES_FILE
set default_requirements_path "$ASDF_PYTHON_DEFAULT_PACKAGES_FILE"
end
set pattern (string join '|' (cat "$default_requirements_path"))
if test -z "$pattern"
echo -s \
(set_color yellow) \
"no packages to remove" \
(set_color normal)
return 0
end
if command -q uv
uv pip uninstall --system (
uv pip freeze --system | grep --invert-match "$pattern"
)
else if command -q pip
# pip itself is never included in freeze results
pip uninstall -y (pip freeze | grep --invert-match "$pattern")
else
echo -s \
(set_color $fish_color_error) \
"error: no Python package installer found" \
(set_color normal)
return 1
end
end