Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use index in offline mode when called from conda-build #395

Merged
merged 7 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions conda_libmamba_solver/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,17 @@
from typing import Dict, Iterable, Optional, Tuple, Union

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 @@ -49,7 +49,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 @@ -175,7 +175,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
Loading