-
-
Notifications
You must be signed in to change notification settings - Fork 356
Add CLI for converting v2 metadata to v3 #3257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 29 commits
45bb4e5
456c9e7
242a338
1045c33
4e2442f
c63f0b8
2947ce4
ba81755
67f9580
0d7c2c8
cf39580
11499e7
90b0996
85159bb
53ba166
d4cdc04
dfdc729
ad60991
66bae0d
97df9bf
42e0435
9e20b39
6586e66
ce409a3
fb7136b
6585f24
46e958d
08fc138
3540434
0889979
d906dba
5e03e3c
89aa095
ade9c3b
218e8a8
49787f6
488485c
18487c9
a5cd760
bde452f
671c5e3
0281cc1
2ffe854
432eae6
7cb42c5
6e6788d
4abc84a
0bdd6f8
f2fa389
4d98121
649bb20
dba4073
b702060
b900a0e
42aa7db
d3fc21e
5c05c0c
f62fe31
71067ba
34e97f0
9f6b875
1362cc6
4ae3491
f301172
0449ef7
14b9cfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ jobs: | |
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # grab all branches and tags | ||
# - name: cuda-toolkit | ||
# uses: Jimver/[email protected] | ||
# id: cuda-toolkit | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import logging | ||
from typing import Annotated, Literal, cast | ||
|
||
import typer | ||
|
||
from zarr.core.metadata.converter.converter_v2_v3 import convert_v2_to_v3, remove_metadata | ||
from zarr.core.sync import sync | ||
|
||
app = typer.Typer() | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def _set_logging_config(verbose: bool) -> None: | ||
if verbose: | ||
lvl = logging.INFO | ||
else: | ||
lvl = logging.WARNING | ||
fmt = "%(message)s" | ||
logging.basicConfig(level=lvl, format=fmt) | ||
dstansby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def _set_verbose_level() -> None: | ||
logging.getLogger().setLevel(logging.INFO) | ||
dstansby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
@app.command() # type: ignore[misc] | ||
def convert( | ||
store: Annotated[ | ||
str, | ||
typer.Argument( | ||
help="Store or path to directory in file system or name of zip file e.g. 'data/example-1.zarr', 's3://example-bucket/example'..." | ||
), | ||
], | ||
path: Annotated[str | None, typer.Option(help="The path within the store to open")] = None, | ||
dry_run: Annotated[ | ||
bool, | ||
typer.Option( | ||
help="Enable a dry-run: files that would be converted are logged, but no new files are actually created." | ||
), | ||
] = False, | ||
) -> None: | ||
"""Convert all v2 metadata in a zarr hierarchy to v3. This will create a zarr.json file at each level | ||
(for every group / array). V2 files (.zarray, .zattrs etc.) will be left as-is. | ||
""" | ||
if dry_run: | ||
_set_verbose_level() | ||
logger.info( | ||
"Dry run enabled - no new files will be created. Log of files that would be created on a real run:" | ||
K-Meech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
convert_v2_to_v3(store=store, path=path, dry_run=dry_run) | ||
|
||
|
||
@app.command() # type: ignore[misc] | ||
def clear( | ||
store: Annotated[ | ||
str, | ||
typer.Argument( | ||
help="Store or path to directory in file system or name of zip file e.g. 'data/example-1.zarr', 's3://example-bucket/example'..." | ||
), | ||
], | ||
zarr_format: Annotated[ | ||
int, | ||
typer.Argument( | ||
help="Which format's metadata to remove - 2 or 3.", | ||
min=2, | ||
max=3, | ||
), | ||
], | ||
path: Annotated[str | None, typer.Option(help="The path within the store to open")] = None, | ||
dry_run: Annotated[ | ||
bool, | ||
typer.Option( | ||
help="Enable a dry-run: files that would be deleted are logged, but no files are actually removed." | ||
K-Meech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
), | ||
] = False, | ||
) -> None: | ||
"""Remove all v2 (.zarray, .zattrs, .zgroup, .zmetadata) or v3 (zarr.json) metadata files from the given Zarr. | ||
Note - this will remove metadata files at all levels of the hierarchy (every group and array). | ||
""" | ||
if dry_run: | ||
_set_verbose_level() | ||
logger.info( | ||
"Dry run enabled - no files will be deleted. Log of files that would be deleted on a real run:" | ||
) | ||
|
||
sync( | ||
remove_metadata( | ||
store=store, zarr_format=cast(Literal[2, 3], zarr_format), path=path, dry_run=dry_run | ||
) | ||
) | ||
|
||
|
||
@app.callback() # type: ignore[misc] | ||
def main( | ||
verbose: Annotated[ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found it a bit annoying that I couldn't do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it's annoying to put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I'm not sure. Unless anyone else weighs in with a strong opinion, we can leave it as is I think. It doesn't prevent someone coming along and adding the option for |
||
bool, | ||
typer.Option( | ||
help="enable verbose logging - will print info about metadata files being deleted / saved." | ||
), | ||
] = False, | ||
) -> None: | ||
""" | ||
Convert metadata from v2 to v3. See available commands below - access help for individual commands with | ||
zarr-converter COMMAND --help. | ||
""" | ||
_set_logging_config(verbose) | ||
|
||
|
||
if __name__ == "__main__": | ||
app() |
Uh oh!
There was an error while loading. Please reload this page.