Skip to content

Commit

Permalink
Use index in offline mode when called from conda-build (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimergp authored Dec 6, 2023
1 parent 96c59f3 commit 6d61b0f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
32 changes: 28 additions & 4 deletions conda_libmamba_solver/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,17 @@
from typing import Iterable

import libmambapy as api
from conda import __version__ as conda_version
from conda.base.constants import REPODATA_FN
from conda.base.context import context
from conda.common.io import DummyExecutor, ThreadLimitedThreadPoolExecutor
from conda.base.context import context, reset_context
from conda.common.io import DummyExecutor, ThreadLimitedThreadPoolExecutor, env_var
from conda.common.serialize import json_dump, json_load
from conda.common.url import percent_decode, remove_auth, split_anaconda_token
from conda.core.subdir_data import SubdirData
from conda.models.channel import Channel
from conda.models.match_spec import MatchSpec
from conda.models.records import PackageRecord
from conda.models.version import VersionOrder

from .mamba_utils import set_channel_priorities
from .state import IndexHelper
Expand Down Expand Up @@ -407,5 +409,27 @@ def _process_query_result(
return result


# for conda-build
_CachedLibMambaIndexHelper = lru_cache(maxsize=None)(LibMambaIndexHelper)
@lru_cache(maxsize=None)
class _LibMambaIndexForCondaBuild(LibMambaIndexHelper):
"""
See https://github.com/conda/conda-libmamba-solver/issues/386
conda-build needs to operate offline so the index doesn't get updated
accidentally during long build phases. However, this is only guaranteed
to work if https://github.com/conda/conda/pull/13357 is applied. Otherwise
the condarc configuration might be ignored, resulting in bad index configuration
and missing packages anyway.
"""

def __init__(self, *args, **kwargs):
if VersionOrder(conda_version) <= VersionOrder("23.10.0"):
log.warning(
"conda-build requires conda >=23.11.0 for offline index support. "
"Falling back to online index. This might result in KeyError messages, "
"specially if the remote repodata is updated during the build phase. "
"See https://github.com/conda/conda-libmamba-solver/issues/386."
)
super().__init__(*args, **kwargs)
else:
with env_var("CONDA_OFFLINE", "true", callback=reset_context):
super().__init__(*args, **kwargs)
4 changes: 2 additions & 2 deletions conda_libmamba_solver/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

from . import __version__
from .exceptions import LibMambaUnsatisfiableError
from .index import LibMambaIndexHelper, _CachedLibMambaIndexHelper
from .index import LibMambaIndexHelper, _LibMambaIndexForCondaBuild
from .mamba_utils import init_api_context, mamba_version
from .state import SolverInputState, SolverOutputState
from .utils import is_channel_available
Expand Down Expand Up @@ -177,7 +177,7 @@ def solve_final_state(
rec.channel: None for rec in self._index if rec.channel.scheme == "file"
}
# Cache indices for conda-build, it gets heavy otherwise
IndexHelper = _CachedLibMambaIndexHelper
IndexHelper = _LibMambaIndexForCondaBuild
else:
IndexHelper = LibMambaIndexHelper
conda_bld_channels = ()
Expand Down
20 changes: 20 additions & 0 deletions news/395-offline-conda-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Enhancements

* <news item>

### Bug fixes

* Instantiate `IndexHelper` in offline mode for compatibility with conda-build. Otherwise
the index can get out of sync during long build processes. (#386 via #395)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
2 changes: 1 addition & 1 deletion tests/data/conda_build_recipes/stackvana/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% set name = "stackvana-core" %}
{% set name = "stackvana-split" %}
{% set version = "0.2021.43" %}
{% set eups_product = "lsst_distrib" %}

Expand Down

0 comments on commit 6d61b0f

Please sign in to comment.