Skip to content

Commit b1b6bb1

Browse files
committed
CLI Typer replcement of arg parser , improved sample name display
1 parent 3289625 commit b1b6bb1

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "servicex_analysis_utils"
7-
version = "1.0.b3"
7+
version = "1.0.0"
88
description = "A package with analysis tools for ServiceX."
99
authors = [{name = "Artur Cordeiro Oudot Choi", email = "acordeir@cern.ch"}]
1010
readme = "README.md"
@@ -38,7 +38,7 @@ test = [
3838
]
3939

4040
[project.scripts]
41-
servicex-get-structure = "servicex_analysis_utils.cli:run_from_command"
41+
servicex-get-structure = "servicex_analysis_utils.cli:app"
4242

4343

4444
[tool.hatch.build.targets.wheel]

servicex_analysis_utils/cli.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import argparse
21
import sys
32
import json
43
import os
54
import logging
65
from .file_peeking import get_structure
6+
import typer
7+
from typing import List
8+
9+
app = typer.Typer()
710

811

912
def make_dataset_list(dataset_arg):
@@ -46,30 +49,25 @@ def make_dataset_list(dataset_arg):
4649
return dataset
4750

4851

49-
def run_from_command():
52+
@app.command()
53+
def run_from_command(
54+
dataset: List[str] = typer.Argument(
55+
...,
56+
help="Input datasets (Rucio DID) or path to JSON file containing datasets in a dict.",
57+
),
58+
filter_branch: str = typer.Option(
59+
"", "--filter-branch", help="Only display branches containing this string."
60+
),
61+
):
5062
"""
5163
Calls the get_structure function and sends results to stdout.
52-
To run on command line: servicex-get-structure -dataset --fileter-branch
64+
To run on command line: servicex-get-structure -dataset --filter-branch
5365
"""
54-
parser = argparse.ArgumentParser(
55-
description="CLI tool for retrieving ROOT file structures."
56-
)
57-
58-
parser.add_argument(
59-
"dataset",
60-
nargs="+",
61-
help="Input datasets (Rucio DID) or a JSON file containing datasets in a dict.",
62-
)
63-
parser.add_argument(
64-
"--filter-branch",
65-
default="",
66-
help="Only display branches containing this string.",
67-
)
68-
69-
args = parser.parse_args()
66+
ds_format = make_dataset_list(dataset)
67+
result = get_structure(ds_format, filter_branch=filter_branch, do_print=False)
7068

71-
ds_format = make_dataset_list(args.dataset)
69+
print(result)
7270

73-
result = get_structure(ds_format, filter_branch=args.filter_branch, do_print=False)
7471

75-
print(result)
72+
if __name__ == "__main__":
73+
app()

servicex_analysis_utils/file_peeking.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ def build_deliver_spec(datasets):
9898
user_in = type(datasets)
9999

100100
if user_in == str:
101-
dataset_dict.update({"Sample": datasets})
101+
dataset_dict.update({datasets: datasets})
102102
elif user_in == list and type(datasets[0]) is str:
103-
for i in range(len(datasets)):
104-
name = "Sample" + str(i + 1) # write number for humans
105-
dataset_dict.update({name: datasets[i]})
103+
for ds in datasets:
104+
dataset_dict.update({ds: ds})
106105
elif user_in == dict:
107106
dataset_dict = datasets
108107
else:

0 commit comments

Comments
 (0)