From c90d99bb8324ba9344f472ba4542f336b6526732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=AB=20Bilodeau?= <70441641+zbilodea@users.noreply.github.com> Date: Thu, 21 Mar 2024 16:03:26 +0100 Subject: [PATCH] fix: cannot input multiple files when using "add" or "merge-root" in the command line (#80) * fixed force option, fixed multiple args --- src/hepconvert/__main__.py | 24 ++++++++++++------------ src/hepconvert/histogram_adding.py | 2 +- src/hepconvert/merge.py | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/hepconvert/__main__.py b/src/hepconvert/__main__.py index 6751462..500f5d2 100644 --- a/src/hepconvert/__main__.py +++ b/src/hepconvert/__main__.py @@ -42,7 +42,7 @@ def main() -> None: @click.option( "-f", "--force", - default=False, + is_flag=True, help="If True, overwrites destination file if it already exists.", ) def parquet_to_root( @@ -59,7 +59,7 @@ def parquet_to_root( resize_factor=10.0, compression="zlib", compression_level=1, - force=False, + force, ): """ Convert Parquet file to ROOT file. @@ -111,7 +111,7 @@ def parquet_to_root( @click.option( "-f", "--force", - default=False, + is_flag=True, help="If True, overwrites destination file if it already exists.", ) def copy_root( @@ -125,7 +125,7 @@ def copy_root( cut=None, expressions=None, progress_bar=None, - force=False, + force, title="", field_name=lambda outer, inner: inner if outer == "" else outer + "_" + inner, initial_basket_capacity=10, @@ -164,11 +164,11 @@ def copy_root( @main.command() @click.argument("destination") -@click.argument("files") +@click.argument("files", nargs=-1) @click.option( "-f", "--force", - default=False, + is_flag=True, help="Overwrite destination file if it already exists", ) @click.option("--progress-bar", default=None, type=bool, required=False) @@ -203,7 +203,7 @@ def add( files, *, progress_bar=False, - force=False, + force, append=False, compression="zlib", compression_level=1, @@ -232,7 +232,7 @@ def add( @main.command() @click.argument("destination") -@click.argument("files") +@click.argument("files", nargs=-1) @click.option("--title", required=False, default="", help="Set title of new TTree.") @click.option( "--initial-basket-capacity", @@ -257,7 +257,7 @@ def add( @click.option("--cut", default=None, type=str or list, required=False) @click.option("--expressions", default=None, type=str or list, required=False) @click.option( - "--force", default=True, help="Overwrite destination file if it already exists" + "--force", is_flag=True, help="Overwrite destination file if it already exists" ) @click.option("--append", default=False, help="Append histograms to an existing file") @click.option( @@ -293,7 +293,7 @@ def merge_root( resize_factor=10.0, counter_name=lambda counted: "n" + counted, step_size="100 MB", - force=True, + force, append=False, compression="LZ4", compression_level=1, @@ -342,7 +342,7 @@ def merge_root( @click.option( "-f", "--force", - default=False, + is_flag=True, type=bool, help="If a file already exists at specified path, it gets replaced", ) @@ -503,7 +503,7 @@ def root_to_parquet( parquet_extra_options=None, storage_options=None, tree=None, - force=False, + force, step_size=100, ): """ diff --git a/src/hepconvert/histogram_adding.py b/src/hepconvert/histogram_adding.py index bc99785..1a9fe47 100644 --- a/src/hepconvert/histogram_adding.py +++ b/src/hepconvert/histogram_adding.py @@ -461,7 +461,7 @@ def add_histograms( ), ) - if not isinstance(files, list): + if not isinstance(files, list) and not isinstance(files, tuple): path = Path(files) files = sorted(path.glob("**/*.root")) diff --git a/src/hepconvert/merge.py b/src/hepconvert/merge.py index 5ed4c92..febbdfa 100644 --- a/src/hepconvert/merge.py +++ b/src/hepconvert/merge.py @@ -159,7 +159,7 @@ def merge_root( ) first = True - if not isinstance(files, list): + if not isinstance(files, list) and not isinstance(files, tuple): path = Path(files) files = sorted(path.glob("**/*.root"))