Skip to content

Commit

Permalink
fix: CLI methods returned exit status 1 since paths were returned
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Apr 22, 2024
1 parent 545d28d commit 7ffe974
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
0.58.5
- fix: CLI methods returned exit status 1 since paths were returned
0.58.4
- fix: support relative paths in basins with both nt `\\` and
posix `/` path separators
Expand Down
12 changes: 9 additions & 3 deletions dclab/cli/task_compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def compress(
path_in: str | pathlib.Path = None,
path_out: str | pathlib.Path = None,
force: bool = False,
check_suffix: bool = True):
check_suffix: bool = True,
ret_path: bool = False,
):
"""Create a new dataset with all features compressed lossless
Parameters
Expand All @@ -32,10 +34,12 @@ def compress(
DEPRECATED
check_suffix: bool
check suffixes for input and output files
ret_path: bool
whether to return the output path
Returns
-------
path_out: pathlib.Path
path_out: pathlib.Path (optional)
output path (with possibly corrected suffix)
"""
cmp_kw = hdf5plugin.Zstd(clevel=5)
Expand Down Expand Up @@ -98,7 +102,9 @@ def compress(

# Finally, rename temp to out
path_temp.rename(path_out)
return path_out

if ret_path:
return path_out


def compress_parser():
Expand Down
11 changes: 8 additions & 3 deletions dclab/cli/task_condense.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def condense(
ancillaries: bool = None,
store_ancillary_features: bool = True,
store_basin_features: bool = True,
check_suffix: bool = True):
check_suffix: bool = True,
ret_path: bool = False
):
"""Create a new dataset with all available scalar-only features
Besides the innate scalar features, this also includes all
Expand All @@ -44,10 +46,12 @@ def condense(
copy basin features from the input path to the output file
check_suffix: bool
check suffixes for input and output files
ret_path: bool
whether to return the output path
Returns
-------
path_out: pathlib.Path
path_out: pathlib.Path (optional)
output path (with possibly corrected suffix)
"""
if ancillaries is not None:
Expand Down Expand Up @@ -85,7 +89,8 @@ def condense(

# Finally, rename temp to out
path_temp.rename(path_out)
return path_out
if ret_path:
return path_out


def condense_dataset(
Expand Down
11 changes: 8 additions & 3 deletions dclab/cli/task_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class FeatureSetNotIdenticalJoinWarning(UserWarning):
def join(
paths_in: List[str | pathlib.Path] = None,
path_out: str | pathlib.Path = None,
metadata: Dict = None):
metadata: Dict = None,
ret_path: bool = False,
):
"""Join multiple RT-DC measurements into a single .rtdc file
Parameters
Expand All @@ -36,10 +38,12 @@ def join(
metadata: dict
optional metadata dictionary (configuration dict) to store
in the output file
ret_path: bool
whether to return the output path
Returns
-------
path_out: pathlib.Path
path_out: pathlib.Path (optional)
output path (with corrected path suffix if applicable)
Notes
Expand Down Expand Up @@ -204,7 +208,8 @@ def join(

# Finally, rename temp to out
path_temp.rename(path_out)
return path_out
if ret_path:
return path_out


def join_parser():
Expand Down
9 changes: 7 additions & 2 deletions dclab/cli/task_repack.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def repack(
path_out: str | pathlib.Path = None,
strip_basins: bool = False,
strip_logs: bool = False,
check_suffix: bool = True):
check_suffix: bool = True,
ret_path: bool = False,
):
"""Repack/recreate an .rtdc file, optionally stripping the logs
Parameters
Expand All @@ -32,6 +34,8 @@ def repack(
do not write logs to the output file
check_suffix: bool
check suffixes for input and output files
ret_path: bool
whether to return the output path
Returns
-------
Expand Down Expand Up @@ -64,7 +68,8 @@ def repack(

# Finally, rename temp to out
path_temp.rename(path_out)
return path_out
if ret_path:
return path_out


def repack_parser():
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cli_compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def test_compress():
# same directory (will be cleaned up with path_in)
path_out = path_in.with_name("compressed.rtdc")

cli.compress(path_in=path_in, path_out=path_out)
ret = cli.compress(path_in=path_in, path_out=path_out)
assert ret is None, "by default, this method should return 0 (exit 0)"
with new_dataset(path_out) as dsj, new_dataset(path_in) as ds0:
assert "dclab-compress" in dsj.logs
assert len(dsj)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cli_condense.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def test_condense():
# same directory (will be cleaned up with path_in)
path_out = path_in.with_name("condensed.rtdc")

cli.condense(path_in=path_in, path_out=path_out)
ret = cli.condense(path_in=path_in, path_out=path_out)
assert ret is None, "by default, this method should return 0 (exit 0)"
with new_dataset(path_out) as dsj, new_dataset(path_in) as ds0:
assert "dclab-condense" in dsj.logs
assert len(dsj)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cli_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def test_join_rtdc():
# same directory (will be cleaned up with path_in)
path_out = path_in.with_name("out.rtdc")

cli.join(paths_in=[path_in, path_in], path_out=path_out)
ret = cli.join(paths_in=[path_in, path_in], path_out=path_out)
assert ret is None, "by default, this method should return 0 (exit 0)"
with new_dataset(path_out) as dsj, new_dataset(path_in) as ds0:
assert "dclab-join" in dsj.logs
assert len(dsj)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cli_repack.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def test_repack_basic():
# same directory (will be cleaned up with path_in)
path_out = path_in.with_name("repacked.rtdc")

cli.repack(path_in=path_in, path_out=path_out)
ret = cli.repack(path_in=path_in, path_out=path_out)
assert ret is None, "by default, this method should return 0 (exit 0)"

with new_dataset(path_out) as dsj, new_dataset(path_in) as ds0:
assert len(dsj)
Expand Down

0 comments on commit 7ffe974

Please sign in to comment.