File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,12 +20,13 @@ def execute(args: argparse.Namespace) -> int:
2020 from conda .core .link import PrefixSetup , UnlinkLinkTransaction
2121 from conda .base .context import context
2222
23- from ..constants import PERMANENT_PACKAGES
23+ from ..query import permanent_dependencies
2424
2525 print ("Resetting 'base' environment..." )
2626
27+ uninstallable_packages = permanent_dependencies ()
2728 installed = sorted (PrefixData (sys .prefix ).iter_records (), key = lambda x : x .name )
28- packages_to_remove = [pkg for pkg in installed if pkg .name not in PERMANENT_PACKAGES ]
29+ packages_to_remove = [pkg for pkg in installed if pkg .name not in uninstallable_packages ]
2930
3031 stp = PrefixSetup (
3132 target_prefix = sys .prefix ,
Original file line number Diff line number Diff line change 11from typing import Final
22
33PERMANENT_PACKAGES : Final = (
4- "archspec" ,
5- "boltons" ,
64 "conda" ,
7- "charset-normalizer" ,
8- "conda-libmamba-solver" ,
9- "conda-package-handling" ,
10- "conda-self" ,
11- "distro" ,
12- "frozendict" ,
13- "jsonpatch" ,
14- "menuinst" ,
15- "packaging" ,
16- "platformdirs" ,
17- "pluggy" ,
18- "pycosat"
19- "python" ,
20- "requests" ,
21- "ruamel.yaml"
22- "setuptools" ,
23- "tqdm" ,
24- "truststore" ,
25- "zstandard" ,
265)
Original file line number Diff line number Diff line change 33from __future__ import annotations
44
55import sys
6+ from functools import cache
67from typing import TYPE_CHECKING
78
89from conda .base .context import context
1314 PackagesNotFoundError ,
1415)
1516from conda .models .channel import Channel
17+ from conda .models .prefix_graph import PrefixGraph
1618from conda .models .version import VersionOrder
1719
20+ from .constants import PERMANENT_PACKAGES
21+
1822if TYPE_CHECKING :
1923 from collections .abc import Iterable
2024
@@ -56,3 +60,16 @@ def latest(
5660 if best is None :
5761 raise PackagesNotFoundError (package_name , channels )
5862 return best
63+
64+
65+ @cache
66+ def permanent_dependencies () -> list [str ]:
67+ """Get the full list of dependencies for all the permanent packages."""
68+ installed = PrefixData (sys .prefix )
69+ prefix_graph = PrefixGraph (installed .iter_records ())
70+
71+ packages = []
72+ for pkg in PERMANENT_PACKAGES :
73+ node = prefix_graph .get_node_by_name (pkg )
74+ packages .extend ([record .name for record in prefix_graph .all_ancestors (node )])
75+ return set (packages )
You can’t perform that action at this time.
0 commit comments