Skip to content

Commit

Permalink
Port #525 (explicit channels, subdir and target prefix for libmamba c…
Browse files Browse the repository at this point in the history
…ontext)
  • Loading branch information
jaimergp committed Sep 21, 2024
1 parent 039e165 commit cc4bdf2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 11 additions & 4 deletions conda_libmamba_solver/mamba_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import os
import logging
import sys
from collections.abc import Iterable
from functools import lru_cache
from importlib.metadata import version

Expand All @@ -38,7 +39,11 @@ def _get_base_url(url: str, name: str | None = None):


@lru_cache(maxsize=1)
def init_libmamba_context() -> libmambapy.Context:
def init_libmamba_contextinit_api_context(
channels: Iterable[str] = None,
platform: str = None,
target_prefix: str = None,
) -> libmambapy.Context:
# This function has to be called BEFORE 1st initialization of the context
libmamba_context = libmambapy.Context(
libmambapy.ContextOptions(
Expand Down Expand Up @@ -66,7 +71,9 @@ def init_libmamba_context() -> libmambapy.Context:
# Prefix params
libmamba_context.prefix_params.conda_prefix = context.conda_prefix
libmamba_context.prefix_params.root_prefix = context.root_prefix
libmamba_context.prefix_params.target_prefix = context.target_prefix
libmamba_context.prefix_params.target_prefix = str(
target_prefix if target_prefix is not None else context.target_prefix
)

# Networking params -- we always operate offline from libmamba's perspective
libmamba_context.remote_fetch_params.user_agent = context.user_agent
Expand All @@ -84,8 +91,8 @@ def init_libmamba_context() -> libmambapy.Context:
libmamba_context.use_only_tar_bz2 = context.use_only_tar_bz2

# Channels and platforms
libmamba_context.platform = context.subdir
libmamba_context.channels = context.channels
libmamba_context.platform = platform if platform is not None else context.subdir
libmamba_context.channels = channels if channels is not None else context.channels
libmamba_context.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 @@ -114,7 +114,11 @@ def __init__(
self.subdirs = context.subdirs

self._repodata_fn = self._maybe_ignore_current_repodata()
self._libmamba_context = init_libmamba_context()
self._libmamba_context = init_libmamba_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),
)

def solve_final_state(
self,
Expand Down

0 comments on commit cc4bdf2

Please sign in to comment.