Skip to content

Commit

Permalink
Support conda-build>=24.1 actions/Dist-less package resolution
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Bargull <marcel.bargull@udo.edu>
  • Loading branch information
mbargull committed Mar 16, 2024
1 parent f561bca commit 581e9e2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
54 changes: 50 additions & 4 deletions boa/cli/mambabuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _get_solver(channel_urls, subdir, output_folder):
return solver


def mamba_get_install_actions(
def mamba_get_package_records(
prefix,
specs,
env,
Expand Down Expand Up @@ -138,7 +138,8 @@ def mamba_get_install_actions(

_specs = [s.conda_build_form() for s in _specs]
try:
solution = solver.solve_for_action(_specs, prefix)
# We only create fresh environments in builds and can ignore unlink precs.
_, link_precs = solver.solve_for_unlink_link_precs(_specs, prefix)
except RuntimeError as e:
conflict_packages = parse_problems(str(e))

Expand All @@ -149,10 +150,55 @@ def mamba_get_install_actions(
err.subdir = subdir
raise err

return solution
return link_precs


if hasattr(conda_build, "get_package_records"):
# conda-build>=24.1 avoids the legacy "actions"/"Dist"-based installs.
conda_build.environ.get_package_records = mamba_get_package_records
else:
# conda-build<24.1 needs get_package_records' result wrapped in "actions" dict.
def mamba_get_install_actions(
prefix,
specs,
env,
retries=0,
subdir=None,
verbose=True,
debug=False,
locking=True,
bldpkgs_dirs=None,
timeout=900,
disable_pip=False,
max_env_retry=3,
output_folder=None,
channel_urls=None,
):
from conda.models.dist import Dist
from conda.plan import get_blank_actions

link_precs = mamba_get_package_records(
prefix=prefix,
specs=specs,
env=env,
retries=retries,
subdir=subdir,
verbose=verbose,
debug=debug,
locking=locking,
bldpkgs_dirs=bldpkgs_dirs,
timeout=timeout,
disable_pip=disable_pip,
max_env_retry=max_env_retry,
output_folder=output_folder,
channel_urls=channel_urls,
)
actions = get_blank_actions(prefix)
actions["LINK"].extend(Dist(prec) for prec in link_precs)
return actions


conda_build.environ.get_install_actions = mamba_get_install_actions
conda_build.environ.get_install_actions = mamba_get_install_actions


def prepare(**kwargs):
Expand Down
13 changes: 4 additions & 9 deletions boa/core/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from conda.common.url import remove_auth, split_anaconda_token
from conda.core.index import _supplement_index_with_system
from conda.base.context import context
from conda.plan import get_blank_actions
from conda.models.dist import Dist
from conda_build.conda_interface import pkgs_dirs
from conda.core.package_cache_data import PackageCacheData

Expand Down Expand Up @@ -60,7 +58,7 @@ def get_url_from_channel(c):
return split_anaconda_token(remove_auth(c))[0]


def to_action(specs_to_add, specs_to_remove, prefix, to_link, to_unlink, index):
def to_unlink_link_precs(specs_to_add, specs_to_remove, prefix, to_link, to_unlink, index):
to_link_records = []

prefix_data = PrefixData(prefix)
Expand All @@ -86,10 +84,7 @@ def to_action(specs_to_add, specs_to_remove, prefix, to_link, to_unlink, index):
specs_to_add=specs_to_add,
)

actions = get_blank_actions(prefix)
actions["UNLINK"].extend(Dist(prec) for prec in unlink_precs)
actions["LINK"].extend(Dist(prec) for prec in link_precs)
return actions
return unlink_precs, link_precs


def get_virtual_packages():
Expand Down Expand Up @@ -239,7 +234,7 @@ def solve(self, specs, pkg_cache_path=None):
package_cache = libmambapy.MultiPackageCache(pkg_cache_path)
return libmambapy.Transaction(api_solver, package_cache)

def solve_for_action(self, specs, prefix):
def solve_for_unlink_link_precs(self, specs, prefix):
t = self.solve(specs)
if not boa_config.quiet and not boa_config.is_mambabuild:
t.print()
Expand All @@ -248,7 +243,7 @@ def solve_for_action(self, specs, prefix):
specs_to_add = [MatchSpec(m) for m in mmb_specs[0]]
specs_to_remove = [MatchSpec(m) for m in mmb_specs[1]]

return to_action(
return to_unlink_link_precs(
specs_to_add,
specs_to_remove,
prefix,
Expand Down

0 comments on commit 581e9e2

Please sign in to comment.