Skip to content
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
29 changes: 17 additions & 12 deletions conda_index/index/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,

@dholth dholth Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

closed avoids type complaints when iterating over .values() in _make_repodata_revision_data

)

# in this style because "packages.conda" is not a Python identifier
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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": {},
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 4 additions & 5 deletions docs/v3-repodata.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down
4 changes: 4 additions & 0 deletions news/338-repodata-revisions-map
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 8 additions & 11 deletions tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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": {},
}
Expand All @@ -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": [],
Expand Down
Loading