Skip to content

Commit 5ae6b1c

Browse files
committed
Reset environment with permenant deps
1 parent 8019465 commit 5ae6b1c

3 files changed

Lines changed: 20 additions & 23 deletions

File tree

conda_self/cli/main_reset.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff 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,

conda_self/constants.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
11
from typing import Final
22

33
PERMANENT_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
)

conda_self/query.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import sys
6+
from functools import cache
67
from typing import TYPE_CHECKING
78

89
from conda.base.context import context
@@ -13,8 +14,11 @@
1314
PackagesNotFoundError,
1415
)
1516
from conda.models.channel import Channel
17+
from conda.models.prefix_graph import PrefixGraph
1618
from conda.models.version import VersionOrder
1719

20+
from .constants import PERMANENT_PACKAGES
21+
1822
if 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)

0 commit comments

Comments
 (0)