Skip to content

Commit

Permalink
Init mamba context from conda and delete code we do not know what it …
Browse files Browse the repository at this point in the history
…does
  • Loading branch information
AntoinePrv committed Oct 25, 2023
1 parent 7040ed5 commit 440c423
Showing 1 changed file with 2 additions and 35 deletions.
37 changes: 2 additions & 35 deletions mamba/mamba/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import libmambapy

from .utils import get_index, load_channels
from .utils import init_api_context, load_channels

__all__ = ["MambaSolver", "create", "install"]

Expand All @@ -24,7 +24,6 @@ def __init__(self, channels, platform, context, output_folder=None):
self.local_index = []
self.local_repos = {}
# load local repo, too
self.replace_channels()

def replace_installed(self, prefix):
prefix_data = libmambapy.PrefixData(prefix)
Expand All @@ -33,39 +32,6 @@ def replace_installed(self, prefix):
repo = libmambapy.Repo(self.pool, prefix_data)
repo.set_installed()

def replace_channels(self):
self.local_index = get_index(
(self.output_folder,), platform=self.platform, prepend=False
)

for _, v in self.local_repos.items():
v.clear(True)

start_prio = len(self.channels) + len(self.index)
for subdir, channel in self.local_index:
if not subdir.loaded():
continue

# support new mamba
if isinstance(channel, dict):
channelstr = channel["url"]
channelurl = channel["url"]
else:
channelstr = str(channel)
channelurl = channel.url(with_credentials=True)

cp = subdir.cache_path()
if cp.endswith(".solv"):
os.remove(subdir.cache_path())
cp = cp.replace(".solv", ".json")

self.local_repos[channelstr] = libmambapy.Repo(
self.pool, channelstr, cp, channelurl
)

self.local_repos[channelstr].set_priority(start_prio, 0)
start_prio -= 1

def solve(self, specs, pkg_cache_path=None):
"""Solve given a set of specs.
Parameters
Expand Down Expand Up @@ -143,6 +109,7 @@ def install(
(prefix / "conda-meta").mkdir(parents=True, exist_ok=True)
(base_prefix / "pkgs").mkdir(parents=True, exist_ok=True)

init_api_context()
context = libmambapy.Context()
context.prefix_params.target_prefix = str(prefix)
context.pkgs_dirs = [str(base_prefix / "pkgs")]
Expand Down

0 comments on commit 440c423

Please sign in to comment.