Skip to content
Merged
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
40 changes: 24 additions & 16 deletions src/spec0/releasesource.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,22 +265,30 @@ class CondaReleaseSource(ReleaseSource):
"""

def __init__(self, channel_platforms: list[str]):
# TODO: determine if can use the bz2 instead
self._repodata = {"packages": {}, "packages.conda": {}}

for channel_platform in channel_platforms:
channel, platform = channel_platform.split("/", 1)
url = f"https://conda.anaconda.org/{channel}/{platform}/repodata.json"
cachefile = CACHE_DIR / channel_platform / "repodata.json"
cachefile = get_file(url, cachefile)
with open(cachefile, "r") as f:
data = json.load(f)

# Merge packages
for pkg_name, pkg_info in data.get("packages", {}).items():
self._repodata["packages"][pkg_name] = pkg_info
for pkg_name, pkg_info in data.get("packages.conda", {}).items():
self._repodata["packages.conda"][pkg_name] = pkg_info
self._channel_platforms = channel_platforms
self._repodata_cache = None

@property
Copy link

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider using functools.cached_property instead of a manual cache to simplify the implementation and reduce boilerplate.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

hmm... I hadn't been aware of that. Nice trick to know, but I don't think I'll use it here. We might invalidate this cache at some point, and that's considerably uglier and less obvious with a functools.cached_property (you have to delete the entry from the instance's __dict__, as opposed to setting self._cache = None)

def _repodata(self):
if self._repodata_cache is None:
# TODO: determine if can use the bz2 instead
self._repodata_cache = {"packages": {}, "packages.conda": {}}

for channel_platform in self._channel_platforms:
channel, platform = channel_platform.split("/", 1)
url = f"https://conda.anaconda.org/{channel}/{platform}/repodata.json"
cachefile = CACHE_DIR / channel_platform / "repodata.json"
cachefile = get_file(url, cachefile)
with open(cachefile, "r") as f:
data = json.load(f)

# Merge packages
for pkg_name, pkg_info in data.get("packages", {}).items():
self._repodata_cache["packages"][pkg_name] = pkg_info
for pkg_name, pkg_info in data.get("packages.conda", {}).items():
self._repodata_cache["packages.conda"][pkg_name] = pkg_info

return self._repodata_cache

def _get_releases(self, package):
# Combine "packages" and "packages.conda" if present
Expand Down
Loading