Skip to content

Commit

Permalink
Rename Zip index file name
Browse files Browse the repository at this point in the history
And remove some duplicated code that was writing the index
a second time.
  • Loading branch information
timj committed Oct 25, 2024
1 parent e253707 commit b9907d9
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 22 deletions.
5 changes: 2 additions & 3 deletions python/lsst/daf/butler/datastore/_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,9 +1049,8 @@ def retrieveArtifacts(
If `True` allow transfers to overwrite existing files at the
destination.
write_index : `bool`, optional
If `True` write a file at the top level called ``_index.json``
containing a serialization of a `ZipIndex` for the downloaded
datasets.
If `True` write a file at the top level containing a serialization
of a `ZipIndex` for the downloaded datasets.
add_prefix : `bool`, optional
If `True` and if ``preserve_path`` is `False`, apply a prefix to
the filenames corresponding to some part of the dataset ref ID.
Expand Down
5 changes: 2 additions & 3 deletions python/lsst/daf/butler/datastores/chainedDatastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,8 @@ def retrieveArtifacts(
If `True` allow transfers to overwrite existing files at the
destination.
write_index : `bool`, optional
If `True` write a file at the top level called ``_index.json``
containing a serialization of a `ZipIndex` for the downloaded
datasets.
If `True` write a file at the top level containing a serialization
of a `ZipIndex` for the downloaded datasets.
add_prefix : `bool`, optional
Add a prefix based on the DatasetId. Only used if ``preserve_path``
is `False`.
Expand Down
5 changes: 2 additions & 3 deletions python/lsst/daf/butler/datastores/fileDatastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -2073,9 +2073,8 @@ def retrieveArtifacts(
If `True` allow transfers to overwrite existing files at the
destination.
write_index : `bool`, optional
If `True` write a file at the top level called ``_index.json``
containing a serialization of a `ZipIndex` for the downloaded
datasets.
If `True` write a file at the top level containing a serialization
of a `ZipIndex` for the downloaded datasets.
add_prefix : `bool`, optional
If `True` and if ``preserve_path`` is `False`, apply a prefix to
the filenames corresponding to some part of the dataset ref ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class ZipIndex(BaseModel):
info_map: dict[str, SerializedStoredFileInfo]
"""Mapping of each Zip member to the associated datastore record."""

index_name: ClassVar[str] = "_index.json"
index_name: ClassVar[str] = "_butler_zip_index.json"
"""Name to use when saving the index to a file."""

def generate_uuid5(self) -> uuid.UUID:
Expand Down
5 changes: 2 additions & 3 deletions python/lsst/daf/butler/datastores/inMemoryDatastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,8 @@ def retrieveArtifacts(
If `True` allow transfers to overwrite existing files at the
destination.
write_index : `bool`, optional
If `True` write a file at the top level called ``_index.json``
containing a serialization of a `ZipIndex` for the downloaded
datasets.
If `True` write a file at the top level containing a serialization
of a `ZipIndex` for the downloaded datasets.
add_prefix : `bool`, optional
If `True` and if ``preserve_path`` is `False`, apply a prefix to
the filenames corresponding to some part of the dataset ref ID.
Expand Down
10 changes: 2 additions & 8 deletions python/lsst/daf/butler/direct_butler/_direct_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,20 +1309,14 @@ def retrieveArtifacts(
) -> list[ResourcePath]:
# Docstring inherited.
outdir = ResourcePath(destination)
paths, id_map, info_map = self._datastore.retrieveArtifacts(
paths, _, _ = self._datastore.retrieveArtifacts(
refs,
outdir,
transfer=transfer,
preserve_path=preserve_path,
overwrite=overwrite,
write_index=True,
)
# Write the index file.
index = ZipIndex.from_artifact_maps(
refs, id_map, info_map, ResourcePath(destination, forceDirectory=True)
)
index_path = outdir.join("_index.json")
with index_path.open("w") as fd:
print(index.model_dump_json(exclude_defaults=True, exclude_unset=True), file=fd)
return paths

def exists(
Expand Down
3 changes: 2 additions & 1 deletion tests/test_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def mock_aws(*args: Any, **kwargs: Any) -> Any: # type: ignore[no-untyped-def]
)
from lsst.daf.butler.datastore import NullDatastore
from lsst.daf.butler.datastore.file_templates import FileTemplate, FileTemplateValidationError
from lsst.daf.butler.datastores.file_datastore.retrieve_artifacts import ZipIndex
from lsst.daf.butler.datastores.fileDatastore import FileDatastore
from lsst.daf.butler.direct_butler import DirectButler
from lsst.daf.butler.registry import (
Expand Down Expand Up @@ -362,7 +363,7 @@ def runPutGetTest(self, storageClass: StorageClass, datasetTypeName: str) -> But
self.assertGreater(len(transferred), 0)
artifacts = list(ResourcePath.findFileResources([destination]))
# Filter out the index file.
artifacts = [a for a in artifacts if a.basename() != "_index.json"]
artifacts = [a for a in artifacts if a.basename() != ZipIndex.index_name]
self.assertEqual(set(transferred), set(artifacts))

for artifact in transferred:
Expand Down

0 comments on commit b9907d9

Please sign in to comment.