From df09b992d5de6df328f36e249fa589f3c107dd96 Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Mon, 27 Nov 2023 11:31:57 +0100 Subject: [PATCH] Consider add_pip in SubdirData's runtime cache 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: - https://github.com/conda/conda/pull/13357#issuecomment-1824673734 - https://github.com/conda/conda-build/pull/5083#issuecomment-1826868484 Signed-off-by: Marcel Bargull --- conda/core/subdir_data.py | 25 ++++++++++++++++++------- news/13357-subdir_data-cache-add_pip | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 news/13357-subdir_data-cache-add_pip diff --git a/conda/core/subdir_data.py b/conda/core/subdir_data.py index 2843974ab70..7db43c92270 100644 --- a/conda/core/subdir_data.py +++ b/conda/core/subdir_data.py @@ -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://"): @@ -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 @@ -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 @@ -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 @@ -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 @@ -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() @@ -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), @@ -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.")) ): diff --git a/news/13357-subdir_data-cache-add_pip b/news/13357-subdir_data-cache-add_pip new file mode 100644 index 00000000000..c2a99ab43c1 --- /dev/null +++ b/news/13357-subdir_data-cache-add_pip @@ -0,0 +1,19 @@ +### Enhancements + +* + +### 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 + +* + +### Docs + +* + +### Other + +*