Skip to content

Commit

Permalink
Merge branch '139-skip-current-repodata' into sharded-repodata
Browse files Browse the repository at this point in the history
  • Loading branch information
dholth committed Jun 7, 2024
2 parents 3de27b6 + 4c112df commit 62eb37f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
2 changes: 1 addition & 1 deletion conda_index/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ def cli(
write_run_exports=run_exports,
compact_json=compact,
base_url=base_url,
write_current_repodata=current_repodata,
save_fs_state=save_fs_state,
current_repodata=current_repodata,
)

if save_fs_state is False:
Expand Down
20 changes: 15 additions & 5 deletions conda_index/index/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def __init__(
fs: MinimalFS | None = None,
base_url: str | None = None,
save_fs_state=True,
current_repodata=True,
write_current_repodata=True,
):
if threads is None:
threads = MAX_THREADS_DEFAULT
Expand Down Expand Up @@ -539,7 +539,7 @@ def __init__(
self.compact_json = compact_json
self.base_url = base_url
self.save_fs_state = save_fs_state
self.current_repodata = current_repodata
self.write_current_repodata = write_current_repodata

def index(
self,
Expand Down Expand Up @@ -652,7 +652,7 @@ def index_prepared_subdir(

self._write_repodata(subdir, patched_repodata, REPODATA_JSON_FN)

if self.current_repodata:
if self.write_current_repodata:
log.info("%s Building current_repodata subset", subdir)

current_repodata = _build_current_repodata(
Expand All @@ -667,8 +667,7 @@ def index_prepared_subdir(
json_filename="current_repodata.json",
)
else:
# XXX delete now-outdated current_repodata.json
pass
self._remove_repodata(subdir, "current_repodata.json")

if self.write_run_exports:
log.info("%s Building run_exports data", subdir)
Expand Down Expand Up @@ -884,6 +883,17 @@ def _write_repodata(self, subdir, repodata, json_filename):
self._maybe_remove(repodata_zst_path)
return write_result

def _remove_repodata(self, subdir, json_filename):
"""
Remove json_filename and variants, to avoid keeping outdated repodata.
"""
repodata_json_path = join(self.channel_root, subdir, json_filename)
repodata_bz2_path = repodata_json_path + ".bz2"
repodata_zst_path = repodata_json_path + ".zst"
self._maybe_remove(repodata_json_path)
self._maybe_remove(repodata_bz2_path)
self._maybe_remove(repodata_zst_path)

def _write_subdir_index_html(self, subdir, repodata):
repodata_legacy_packages = repodata["packages"]
repodata_conda_packages = repodata["packages.conda"]
Expand Down
20 changes: 20 additions & 0 deletions news/139-no-current-repodata
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Enhancements

* Add `--current-repodata/--no-current-repodata` flags to control whether
`current_repodata.json` is generated. (#139)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
27 changes: 27 additions & 0 deletions tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,3 +1335,30 @@ def test_base_url(index_data):

package_url = urllib.parse.urljoin(osx["info"]["base_url"], "package-1.0.conda")
assert package_url == "https://example.org/somechannel/osx-64/package-1.0.conda"


def test_write_current_repodata(index_data):
"""
Test that we can skip current_repodata, and that it deletes the old one.
"""
pkg_dir = Path(index_data, "packages")
pattern = "*/current_repodata.json*"

# compact json
channel_index = conda_index.index.ChannelIndex(
str(pkg_dir),
None,
write_bz2=True,
write_zst=True,
compact_json=True,
threads=1,
)

channel_index.index(None)

assert list(pkg_dir.glob(pattern))

channel_index.write_current_repodata = False
channel_index.index(None)

assert not list(pkg_dir.glob(pattern))

0 comments on commit 62eb37f

Please sign in to comment.