Skip to content

Commit

Permalink
Consider add_pip in SubdirData's runtime cache
Browse files Browse the repository at this point in the history
Dependencies of python are altered acc. to add_pip_as_python_dependency.
In case that configuration value is changed at runtime (currently only
observed in conda-build's tests), SubdirData._cache_ gets invalid.
The offline cache on disk already considers the option, such that the
changes here make runtime behavior consistent with the offline cache.

refs:
- conda#13357 (comment)
- conda/conda-build#5083 (comment)

Signed-off-by: Marcel Bargull <[email protected]>
  • Loading branch information
mbargull committed Nov 27, 2023
1 parent e9db136 commit df09b99
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
25 changes: 18 additions & 7 deletions conda/core/subdir_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def __call__(cls, channel, repodata_fn=REPODATA_FN):
assert type(channel) is Channel
now = time()
repodata_fn = repodata_fn or REPODATA_FN
cache_key = channel.url(with_credentials=True), repodata_fn
add_pip = context.add_pip_as_python_dependency
cache_key = channel.url(with_credentials=True), repodata_fn, add_pip
if cache_key in SubdirData._cache_:
cache_entry = SubdirData._cache_[cache_key]
if cache_key[0] and cache_key[0].startswith("file://"):
Expand All @@ -85,7 +86,10 @@ def __call__(cls, channel, repodata_fn=REPODATA_FN):
else:
return cache_entry
subdir_data_instance = super().__call__(
channel, repodata_fn, RepoInterface=get_repo_interface()
channel,
repodata_fn,
RepoInterface=get_repo_interface(),
add_pip=add_pip,
)
subdir_data_instance._mtime = now
SubdirData._cache_[cache_key] = subdir_data_instance
Expand Down Expand Up @@ -189,7 +193,11 @@ def query(self, package_ref_or_match_spec):
yield prec

def __init__(
self, channel, repodata_fn=REPODATA_FN, RepoInterface=CondaRepoInterface
self,
channel,
repodata_fn=REPODATA_FN,
RepoInterface=CondaRepoInterface,
add_pip=None,
):
assert channel.subdir
# metaclass __init__ asserts no package_filename
Expand All @@ -204,6 +212,10 @@ def __init__(
# whether or not to try using the new, trimmed-down repodata
self.repodata_fn = repodata_fn
self.RepoInterface = RepoInterface
if add_pip is None:
self._add_pip = context.add_pip_as_python_dependency
else:
self._add_pip = add_pip
self._loaded = False
self._key_mgr = None

Expand Down Expand Up @@ -352,7 +364,7 @@ def _pickle_valid_checks(self, pickled_state, mod, etag):
yield (
"_add_pip",
pickled_state.get("_add_pip"),
context.add_pip_as_python_dependency,
self._add_pip,
)
yield "_mod", pickled_state.get("_mod"), mod
yield "_etag", pickled_state.get("_etag"), etag
Expand Down Expand Up @@ -424,7 +436,6 @@ def _process_raw_repodata(self, repodata: dict, state: RepodataState | None = No

subdir = repodata.get("info", {}).get("subdir") or self.channel.subdir
assert subdir == self.channel.subdir
add_pip = context.add_pip_as_python_dependency
schannel = self.channel.canonical_name

self._package_records = _package_records = PackageRecordList()
Expand All @@ -446,7 +457,7 @@ def _process_raw_repodata(self, repodata: dict, state: RepodataState | None = No
"_mod": state.get("_mod"),
"_cache_control": state.get("_cache_control"),
"_url": state.get("_url"),
"_add_pip": add_pip,
"_add_pip": self._add_pip,
"_pickle_version": REPODATA_PICKLE_VERSION,
"_schannel": schannel,
"repodata_version": state.get("repodata_version", 0),
Expand Down Expand Up @@ -503,7 +514,7 @@ def _process_raw_repodata(self, repodata: dict, state: RepodataState | None = No
"size"
)
if (
add_pip
self._add_pip
and info["name"] == "python"
and info["version"].startswith(("2.", "3."))
):
Expand Down
19 changes: 19 additions & 0 deletions news/13357-subdir_data-cache-add_pip
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Consider add_pip_as_python_dependency in SubdirData's runtime cache. (https://github.com/conda/conda/pull/13357#issuecomment-1824673734 via #13357)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>

0 comments on commit df09b99

Please sign in to comment.