Skip to content

Commit

Permalink
Initialize mamba context with Solver arguments explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimergp committed Sep 12, 2024
1 parent 0977db9 commit e016dce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 11 additions & 5 deletions conda_libmamba_solver/mamba_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import logging
from functools import lru_cache
from importlib.metadata import version
from typing import Dict
from typing import Dict, Iterable

import libmambapy as api
from conda.base.constants import ChannelPriority
Expand Down Expand Up @@ -84,7 +84,11 @@ def set_channel_priorities(index: Dict[str, "_ChannelRepoInfo"], has_priority: b
return index


def init_api_context() -> api.Context:
def init_api_context(
channels: Iterable[str] = None,
platform: str = None,
target_prefix: str = None,
) -> api.Context:
# This function has to be called BEFORE 1st initialization of the context
api.Context.use_default_signal_handler(False)
api_ctx = api.Context()
Expand All @@ -100,7 +104,9 @@ def init_api_context() -> api.Context:
# Prefix params
api_ctx.prefix_params.conda_prefix = context.conda_prefix
api_ctx.prefix_params.root_prefix = context.root_prefix
api_ctx.prefix_params.target_prefix = context.target_prefix
api_ctx.prefix_params.target_prefix = (
target_prefix if target_prefix is not None else context.target_prefix
)

# Networking params -- we always operate offline from libmamba's perspective
api_ctx.remote_fetch_params.user_agent = context.user_agent
Expand All @@ -118,8 +124,8 @@ def init_api_context() -> api.Context:
api_ctx.use_only_tar_bz2 = context.use_only_tar_bz2

# Channels and platforms
api_ctx.platform = context.subdir
api_ctx.channels = context.channels
api_ctx.platform = platform if platform is not None else context.subdir
api_ctx.channels = channels if channels is not None else context.channels
api_ctx.channel_alias = str(_get_base_url(context.channel_alias.url(with_credentials=True)))

RESERVED_NAMES = {"local", "defaults"}
Expand Down
6 changes: 5 additions & 1 deletion conda_libmamba_solver/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ def solve_final_state(
return none_or_final_state

# From now on we _do_ require a solver and the index
init_api_context()
init_api_context(
channels=[c.canonical_name for c in self.channels],
platform=next(s for s in self.subdirs if s != "noarch"),
target_prefix=str(self.prefix),
)
subdirs = self.subdirs
if self._called_from_conda_build():
log.info("Using solver via 'conda.plan.install_actions' (probably conda build)")
Expand Down

0 comments on commit e016dce

Please sign in to comment.