Skip to content

Commit bb1c3fe

Browse files
authored
Merge pull request #499 from will-moore/ome_zarr_view_no_images
ome_zarr view doesn't try to check for images
2 parents 5c5b45e + 86f501c commit bb1c3fe

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

docs/source/cli.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ Local data::
2828
view
2929
====
3030

31-
Use the `ome_zarr` command to view Zarr data in the https://ome.github.io/ome-ngff-validator::
31+
Use the `ome_zarr` command to serve local Zarr data and view in the https://ome.github.io/ome-ngff-validator::
3232

3333
ome_zarr view 6001240.zarr/
3434

35+
# Use -f or --force to open in browser even if no valid data is found
36+
ome_zarr view 6001240.zarr/ -f
37+
3538
finder
3639
======
3740

ome_zarr/cli.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def info(args: argparse.Namespace) -> None:
3535
def view(args: argparse.Namespace) -> None:
3636
"""Wrap the :func:`~ome_zarr.utils.view` method."""
3737
config_logging(logging.WARNING, args)
38-
zarr_view(args.path, args.port)
38+
zarr_view(args.path, args.port, force=args.force)
3939

4040

4141
def finder(args: argparse.Namespace) -> None:
@@ -133,6 +133,12 @@ def main(args: list[str] | None = None) -> None:
133133
parser_view.add_argument(
134134
"--port", type=int, default=8000, help="Port to serve the data (default: 8000)"
135135
)
136+
parser_view.add_argument(
137+
"--force",
138+
"-f",
139+
action="store_true",
140+
help="Force open in browser. Don't check for OME-Zarr data first.",
141+
)
136142
parser_view.set_defaults(func=view)
137143

138144
# finder (open a dir of images in BioFile Finder in a browser)

ome_zarr/utils.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,24 @@ def info(path: str, stats: bool = False) -> Iterator[Node]:
7373
yield node
7474

7575

76-
def view(input_path: str, port: int = 8000, dry_run: bool = False) -> None:
76+
def view(
77+
input_path: str, port: int = 8000, dry_run: bool = False, force: bool = False
78+
) -> None:
7779
# serve the parent directory in a simple server with CORS. Open browser
7880
# dry_run is for testing, so we don't open the browser or start the server
7981

80-
zarrs = []
81-
if (Path(input_path) / ".zattrs").exists() or (
82-
Path(input_path) / "zarr.json"
83-
).exists():
84-
zarrs = find_multiscales(Path(input_path))
85-
if len(zarrs) == 0:
86-
print(
87-
f"No OME-Zarr images found in {input_path}. "
88-
f"Try $ ome_zarr finder {input_path}"
89-
)
90-
return
82+
if not force:
83+
zarrs = []
84+
if (Path(input_path) / ".zattrs").exists() or (
85+
Path(input_path) / "zarr.json"
86+
).exists():
87+
zarrs = find_multiscales(Path(input_path))
88+
if len(zarrs) == 0:
89+
print(
90+
f"No OME-Zarr images found in {input_path}. "
91+
f"Try $ ome_zarr finder {input_path} or use -f to force open in browser."
92+
)
93+
return
9194

9295
parent_dir, image_name = os.path.split(input_path)
9396
if len(image_name) == 0:

tests/test_cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ def _rotate_and_test(self, *hierarchy: Path, reverse: bool = True):
153153
self._rotate_and_test(*list(secondpass), reverse=False)
154154

155155
def test_view(self):
156+
# view empty dir for code coverage
157+
view(str(self.path), 8000, True)
158+
view(str(self.path), 8000, True, force=True)
159+
156160
filename = f"{self.path}-4"
157161
main(["create", "--method=astronaut", filename])
158162
# CLI doesn't support the dry_run option yet

0 commit comments

Comments
 (0)