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 5 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
25 changes: 25 additions & 0 deletions conda_libmamba_solver/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
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
Expand All @@ -88,6 +89,7 @@
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 @@ -409,3 +411,26 @@ def _process_query_result(

# for conda-build
_CachedLibMambaIndexHelper = lru_cache(maxsize=None)(LibMambaIndexHelper)


def _LibMambaIndexForCondaBuild(*args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type change from class to function for the index helper is a little miffy, I'd rather see use a subclass and then override context.offline in the _CachedLibMambaIndexHelper.__init__ when calling super.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I like it.

"""
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.
"""
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."
)
return _CachedLibMambaIndexHelper(*args, **kwargs)

with context._override("offline", True):
jaimergp marked this conversation as resolved.
Show resolved Hide resolved
return _CachedLibMambaIndexHelper(*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