diff --git a/conda_index/index/__init__.py b/conda_index/index/__init__.py index 67e841c..648e1dd 100644 --- a/conda_index/index/__init__.py +++ b/conda_index/index/__init__.py @@ -46,7 +46,12 @@ V3Section = TypedDict( "V3Section", - {"tar.bz2": dict, "conda": dict, "whl": dict}, + { + "tar.bz2": dict[str, dict[str, Any]], + "conda": dict[str, dict[str, Any]], + "whl": dict[str, dict[str, Any]], + }, + closed=True, ) # in this style because "packages.conda" is not a Python identifier @@ -206,7 +211,7 @@ def _make_seconds(timestamp): ) CHANNELDATA_VERSION = 1 RUN_EXPORTS_VERSION = 1 -REPODATA_REVISION_V3 = 3 +REPODATA_REVISION_V3 = "v3" REPODATA_JSON_FN = "repodata.json" REPODATA_FROM_PKGS_JSON_FN = "repodata_from_packages.json" REPODATA_SHARDS_FN = "repodata_shards.msgpack.zst" @@ -746,7 +751,7 @@ def index_subdir_shards(self, subdir, verbose=False, progress=False): (self.output_root / subdir).mkdir(parents=True, exist_ok=True) - v3_data = { + v3_data: V3Section = { "tar.bz2": {}, "conda": {}, "whl": {}, @@ -766,13 +771,13 @@ def index_subdir_shards(self, subdir, verbose=False, progress=False): shards[shard.name] = shard_hash if self.repodata_v3: - for section, records in repodata_shard["v3"].items(): + for section, records in repodata_shard.get("v3", {}).items(): v3_data[section].update(records) if self.repodata_v3: - shards_index["info"]["repodata_revisions"] = [ - self._make_repodata_revision_data(v3_data) - ] + revision_data = self._make_repodata_revision_data(v3_data) + revision = revision_data.pop("revision") + shards_index["info"]["repodata_revisions"] = {revision: revision_data} return shards_index @@ -803,9 +808,9 @@ def index_subdir(self, subdir, verbose=False, progress=False): new_repodata["v3"] = v3_packages new_repodata["packages"] = {} new_repodata["packages.conda"] = {} - new_repodata["info"]["repodata_revisions"] = [ - self._make_repodata_revision_data(v3_packages) - ] + revision_data = self._make_repodata_revision_data(v3_packages) + revision = revision_data.pop("revision") + new_repodata["info"]["repodata_revisions"] = {revision: revision_data} if self.base_url: # per https://github.com/conda-incubator/ceps/blob/main/cep-15.md @@ -878,8 +883,8 @@ def _indexed_shard_to_repodata(self, indexed_shard: IndexedShard) -> ShardDict: @staticmethod def _make_repodata_revision_data( - revision_data: dict[str, dict[str, dict]], - ) -> dict[str, int | None]: + revision_data: V3Section, + ) -> dict[str, int | str | None]: """ Return { "revision": 3, ... } dict with package statistics derived from revision_data, which is similar to monolithic repodata. diff --git a/docs/v3-repodata.md b/docs/v3-repodata.md index 9504093..5a7849e 100644 --- a/docs/v3-repodata.md +++ b/docs/v3-repodata.md @@ -28,14 +28,13 @@ structure: ```json { "info": { - "repodata_revisions": [ - { + "repodata_revisions": { + "v3": { "n_packages": 1, "newest": 1758039171969, - "oldest": 1758039171969, - "revision": 3 + "oldest": 1758039171969 } - ], + }, "subdir": "noarch" }, "packages": {}, diff --git a/news/338-repodata-revisions-map b/news/338-repodata-revisions-map new file mode 100644 index 0000000..695ef07 --- /dev/null +++ b/news/338-repodata-revisions-map @@ -0,0 +1,4 @@ +### Bug fixes + +* Change `info.repodata_revisions` from a list to a map keyed by revision id to + be compatible with py-rattler 0.25.0+. (#338) diff --git a/tests/test_index.py b/tests/test_index.py index 9a03017..b7e451c 100644 --- a/tests/test_index.py +++ b/tests/test_index.py @@ -1378,9 +1378,8 @@ def test_repodata_v3(index_data): noarch = json.loads((pkg_dir / "noarch" / "repodata.json").read_text()) - assert set(noarch["info"]["repodata_revisions"][0].keys()) == set( - ("revision", "n_packages", "oldest", "newest") - ) + revision_data = list(noarch["info"]["repodata_revisions"].values())[0] + assert set(revision_data.keys()) == set(("n_packages", "oldest", "newest")) assert "v3" in noarch assert set(noarch["v3"]) == {"tar.bz2", "conda", "whl"} @@ -1529,14 +1528,13 @@ def test_index_v3_format(tmp_path): "shards_base_url": "", "subdir": "noarch", "created_at": CREATED_AT, - "repodata_revisions": [ - { - "revision": 3, + "repodata_revisions": { + "v3": { "n_packages": 0, "oldest": None, "newest": None, } - ], + }, }, "shards": {}, } @@ -1547,14 +1545,13 @@ def test_index_v3_format(tmp_path): "packages.conda": {}, "info": { "subdir": "noarch", - "repodata_revisions": [ - { - "revision": 3, + "repodata_revisions": { + "v3": { "n_packages": 0, "oldest": None, "newest": None, } - ], + }, }, "repodata_version": 1, "removed": [],