Skip to content

Commit 906f8ad

Browse files
authored
Merge pull request #63 from bcdev/forman-55-lock_file_issue
Report that target parent must exist
2 parents 9e6ec28 + a7e02b1 commit 906f8ad

File tree

6 files changed

+32
-3
lines changed

6 files changed

+32
-3
lines changed

CHANGES.md

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

3+
### Fixes
4+
5+
* If the target _parent_ directory did not exist, an exception was raised
6+
reporting that the lock file to be written does not exist. Changed this to
7+
report that the target parent directory does not exist. [#55]
8+
39
### Enhancements
410

511
* Added missing documentation of the `append_step` setting in the

docs/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Variable metadata.
146146
## `target_dir`
147147

148148
Type _string_.
149-
The URI or local path of the target Zarr dataset. Must be a directory.
149+
The URI or local path of the target Zarr dataset. Must specify a directory whose parent directory must exist.
150150

151151
## `target_storage_options`
152152

docs/guide.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ zappend(os.listdir("inputs"), target_dir="output/mycube.zarr")
1616

1717
Both invocations will create the Zarr dataset `output/mycube.zarr` by concatenating
1818
the "slice" datasets provided in the `inputs` directory along their `time` dimension.
19-
Both the CLI command and the Python function can be run without any further
19+
`target_dir` must specify a directory for the Zarr dataset. (Its parent directory must
20+
exist.) Both the CLI command and the Python function can be run without any further
2021
configuration provided the paths of the target dataset and the source slice datasets
2122
are given. The target dataset path must point to a directory that will contain a Zarr
2223
group to be created and updated. The slice dataset paths may be provided as Zarr as
@@ -433,6 +434,7 @@ You can disable transaction management by specifying
433434
The `target_dir` setting is mandatory. If it is not specified in the configuration,
434435
it must be passed either as `--target` or `-t` option to the `zappend` command or as
435436
`target_dir` keyword argument when using the `zappend` Python function.
437+
Note, the parent directory of `target_dir` must already exist.
436438

437439
If the target path is given for another filesystem, additional storage options may be
438440
passed using the optional `target_storage_options` setting.

tests/test_api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ def test_some_slices_local(self):
5555
for slice_dir in slices:
5656
shutil.rmtree(slice_dir, ignore_errors=True)
5757

58+
def test_some_slices_local_output_to_non_existing_dir(self):
59+
target_dir = "non_existent_dir/target.zarr"
60+
slices = [
61+
"slice-1.zarr",
62+
"slice-2.zarr",
63+
"slice-3.zarr",
64+
]
65+
for uri in slices:
66+
make_test_dataset(uri=uri)
67+
with pytest.raises(
68+
FileNotFoundError,
69+
match="\\ATarget parent directory does not exist: .*/non_existent_dir\\Z",
70+
):
71+
zappend(slices, target_dir=target_dir)
72+
5873
def test_some_slices_with_class_slice_source(self):
5974
target_dir = "memory://target.zarr"
6075
slices = [make_test_dataset(), make_test_dataset(), make_test_dataset()]

zappend/config/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@
523523
target_dir={
524524
"description": (
525525
"The URI or local path of the target Zarr dataset."
526-
" Must be a directory."
526+
" Must specify a directory whose parent directory must exist."
527527
),
528528
"type": "string",
529529
"minLength": 1,

zappend/fsutil/transaction.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ def __enter__(self):
115115
)
116116
self._entered_ctx = True
117117

118+
if not self.target_dir.parent.exists():
119+
raise FileNotFoundError(
120+
f"Target parent directory does not exist:"
121+
f" {self.target_dir.parent.path}"
122+
)
123+
118124
lock_file = self._lock_file
119125
if lock_file.exists():
120126
raise OSError(f"Target is locked: {lock_file.uri}")

0 commit comments

Comments
 (0)