Skip to content

Commit 64f8d58

Browse files
committed
Merge branch 'main' into forman-60-custom_attrs
2 parents a4866a9 + e57527d commit 64f8d58

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Version 0.5.0 (in development)
22

3+
### Enhancements
4+
5+
* Added CLI option `--traceback`. [#57]
6+
7+
38
## Version 0.4.1 (from 2024-02-13)
49

510
### Fixes

docs/cli.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ Usage: zappend [OPTIONS] [SLICES]...
99
Create or update a Zarr datacube TARGET from slice datasets SLICES.
1010
1111
The zappend command concatenates the dataset SLICES along a given append
12-
dimension, e.g., `"time"` (the default) for geospatial satellite
13-
observations. Each append step is atomic, that is, the append operation is a
14-
transaction that can be rolled back, in case the append operation fails.
15-
This ensures integrity of the target data cube given by TARGET or in CONFIG.
12+
dimension, e.g., "time" (the default) for geospatial satellite observations.
13+
Each append step is atomic, that is, the append operation is a transaction
14+
that can be rolled back, in case the append operation fails. This ensures
15+
integrity of the target data cube given by TARGET or in CONFIG.
1616
1717
Options:
1818
-c, --config CONFIG Configuration JSON or YAML file. If multiple are
@@ -22,6 +22,7 @@ Options:
2222
'target_dir' configuration field.
2323
--dry-run Run the tool without creating, changing, or deleting
2424
any files.
25+
--traceback Show Python traceback on error.
2526
--version Show version and exit.
2627
--help-config json|md Show configuration help and exit.
2728
--help Show this message and exit.

tests/test_cli.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,25 @@ def test_some_slices_and_no_target(self):
112112
"Error: Missing 'target_dir' in configuration\n", result.output
113113
)
114114
self.assertFalse(FileObj("memory://target.zarr").exists())
115+
116+
def test_some_slices_and_no_target_with_traceback(self):
117+
make_test_dataset(uri="memory://slice-1.zarr")
118+
make_test_dataset(uri="memory://slice-2.zarr")
119+
make_test_dataset(uri="memory://slice-3.zarr")
120+
121+
runner = CliRunner()
122+
# noinspection PyTypeChecker
123+
result = runner.invoke(
124+
zappend,
125+
[
126+
"--traceback",
127+
"memory://slice-1.zarr",
128+
"memory://slice-2.zarr",
129+
"memory://slice-3.zarr",
130+
],
131+
)
132+
print(result.output)
133+
self.assertEqual(1, result.exit_code)
134+
self.assertIn("Traceback (most recent call last):\n", result.output)
135+
self.assertIn("Error: Missing 'target_dir' in configuration\n", result.output)
136+
self.assertFalse(FileObj("memory://target.zarr").exists())

tests/test_xrencoding.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def get_v_attrs():
2626

2727

2828
def get_v_meta():
29-
return read_json("v/.zarray")
29+
meta = read_json("v/.zarray")
30+
meta.pop("dimension_separator", None) # new in xarray/zarr
31+
return meta
3032

3133

3234
class XArrayEncodingTest(unittest.TestCase):

zappend/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright © 2024 Norman Fomferra
22
# Permissions are hereby granted under the terms of the MIT License:
33
# https://opensource.org/licenses/MIT.
4+
import sys
45

56
import click
67

@@ -28,6 +29,11 @@
2829
is_flag=True,
2930
help="Run the tool without creating, changing," " or deleting any files.",
3031
)
32+
@click.option(
33+
"--traceback",
34+
is_flag=True,
35+
help="Show Python traceback on error.",
36+
)
3137
@click.option(
3238
"--version",
3339
is_flag=True,
@@ -44,6 +50,7 @@ def zappend(
4450
config: tuple[str, ...],
4551
target: str | None,
4652
dry_run: bool,
53+
traceback: bool,
4754
version: bool,
4855
help_config: str | None,
4956
):
@@ -73,6 +80,10 @@ def zappend(
7380
try:
7481
zappend(slices, config=config, target_dir=target, dry_run=dry_run)
7582
except BaseException as e:
83+
if traceback:
84+
import traceback as tb
85+
86+
tb.print_exc(file=sys.stderr)
7687
raise click.ClickException(f"{e}") from e
7788

7889

0 commit comments

Comments
 (0)