Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Version 0.5.0 (in development)

### Enhancements

* Added CLI option `--traceback`. [#57]


## Version 0.4.1 (from 2024-02-13)

### Fixes
Expand Down
9 changes: 5 additions & 4 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Usage: zappend [OPTIONS] [SLICES]...
Create or update a Zarr datacube TARGET from slice datasets SLICES.

The zappend command concatenates the dataset SLICES along a given append
dimension, e.g., `"time"` (the default) for geospatial satellite
observations. Each append step is atomic, that is, the append operation is a
transaction that can be rolled back, in case the append operation fails.
This ensures integrity of the target data cube given by TARGET or in CONFIG.
dimension, e.g., "time" (the default) for geospatial satellite observations.
Each append step is atomic, that is, the append operation is a transaction
that can be rolled back, in case the append operation fails. This ensures
integrity of the target data cube given by TARGET or in CONFIG.

Options:
-c, --config CONFIG Configuration JSON or YAML file. If multiple are
Expand All @@ -22,6 +22,7 @@ Options:
'target_dir' configuration field.
--dry-run Run the tool without creating, changing, or deleting
any files.
--traceback Show Python traceback on error.
--version Show version and exit.
--help-config json|md Show configuration help and exit.
--help Show this message and exit.
Expand Down
22 changes: 22 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,25 @@ def test_some_slices_and_no_target(self):
"Error: Missing 'target_dir' in configuration\n", result.output
)
self.assertFalse(FileObj("memory://target.zarr").exists())

def test_some_slices_and_no_target_with_traceback(self):
make_test_dataset(uri="memory://slice-1.zarr")
make_test_dataset(uri="memory://slice-2.zarr")
make_test_dataset(uri="memory://slice-3.zarr")

runner = CliRunner()
# noinspection PyTypeChecker
result = runner.invoke(
zappend,
[
"--traceback",
"memory://slice-1.zarr",
"memory://slice-2.zarr",
"memory://slice-3.zarr",
],
)
print(result.output)
self.assertEqual(1, result.exit_code)
self.assertIn("Traceback (most recent call last):\n", result.output)
self.assertIn("Error: Missing 'target_dir' in configuration\n", result.output)
self.assertFalse(FileObj("memory://target.zarr").exists())
11 changes: 11 additions & 0 deletions zappend/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright © 2024 Norman Fomferra
# Permissions are hereby granted under the terms of the MIT License:
# https://opensource.org/licenses/MIT.
import sys

import click

Expand Down Expand Up @@ -28,6 +29,11 @@
is_flag=True,
help="Run the tool without creating, changing," " or deleting any files.",
)
@click.option(
"--traceback",
is_flag=True,
help="Show Python traceback on error.",
)
@click.option(
"--version",
is_flag=True,
Expand All @@ -44,6 +50,7 @@ def zappend(
config: tuple[str, ...],
target: str | None,
dry_run: bool,
traceback: bool,
version: bool,
help_config: str | None,
):
Expand Down Expand Up @@ -73,6 +80,10 @@ def zappend(
try:
zappend(slices, config=config, target_dir=target, dry_run=dry_run)
except BaseException as e:
if traceback:
import traceback as tb

tb.print_exc(file=sys.stderr)
raise click.ClickException(f"{e}") from e


Expand Down