From 9f55804887cfc8f904e3d4753e1525a53511dd2b Mon Sep 17 00:00:00 2001 From: Orion Yeung <11580988+orionyeung001@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:40:13 -0600 Subject: [PATCH 1/4] add default click group to specify browse command --- README.md | 2 +- pyproject.toml | 1 + src/uproot_browser/__main__.py | 9 +++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 18b2446..96da73b 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ pipx run uproot-browser uproot-browser currently provides the following features (get help with `-h` or `--help`, view the current version with `--version`): -- `browse` can be used to display a TUI (text user interface). +- `browse` can be used to display a TUI (text user interface), acts as default if no subcommand specified - `plot` can be used to display a plot. - `tree` can be used to display a tree. diff --git a/pyproject.toml b/pyproject.toml index 9f049fc..21adbc3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,6 +39,7 @@ dynamic = ["version"] dependencies = [ 'awkward >=1', 'click >=8', + 'click-default-group >=1.2', 'hist >=2.4', 'importlib_resources; python_version<"3.9"', 'lz4', diff --git a/src/uproot_browser/__main__.py b/src/uproot_browser/__main__.py index 5b5c692..949220d 100644 --- a/src/uproot_browser/__main__.py +++ b/src/uproot_browser/__main__.py @@ -10,6 +10,7 @@ from typing import Any, Callable import click +from click_default_group import DefaultGroup import uproot from ._version import version as __version__ @@ -19,7 +20,7 @@ VERSION = __version__ -@click.group(context_settings=CONTEXT_SETTINGS) +@click.group(context_settings=CONTEXT_SETTINGS, cls=DefaultGroup, default='browse') @click.version_option(version=VERSION) def main() -> None: """ @@ -28,7 +29,7 @@ def main() -> None: @main.command() -@click.argument("filename") +@click.argument("filename", type=click.Path(exists=True)) def tree(filename: str) -> None: """ Display a tree. @@ -53,7 +54,7 @@ def new_func(*args: Any, **kwargs: Any) -> Any: @main.command() -@click.argument("filename") +@click.argument("filename", type=click.Path(exists=True)) @click.option( "--iterm", is_flag=True, help="Display an iTerm plot (requires [iterm] extra)." ) @@ -94,7 +95,7 @@ def plot(filename: str, iterm: bool) -> None: @main.command() -@click.argument("filename") +@click.argument("filename", type=click.Path(exists=True)) def browse(filename: str) -> None: """ Display a TUI. From d3ce7f518138c92fbb8ef11f3b69a233830edfc0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Nov 2023 20:54:27 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/uproot_browser/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uproot_browser/__main__.py b/src/uproot_browser/__main__.py index 949220d..075af23 100644 --- a/src/uproot_browser/__main__.py +++ b/src/uproot_browser/__main__.py @@ -10,8 +10,8 @@ from typing import Any, Callable import click -from click_default_group import DefaultGroup import uproot +from click_default_group import DefaultGroup from ._version import version as __version__ @@ -20,7 +20,7 @@ VERSION = __version__ -@click.group(context_settings=CONTEXT_SETTINGS, cls=DefaultGroup, default='browse') +@click.group(context_settings=CONTEXT_SETTINGS, cls=DefaultGroup, default="browse") @click.version_option(version=VERSION) def main() -> None: """ From fd7d1b2ad3d7fe490bbd90ba0df4d15201517b2c Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 28 Nov 2023 12:24:50 -0500 Subject: [PATCH 3/4] fix(types): Ignore DefaultGroup when typing Signed-off-by: Henry Schreiner --- src/uproot_browser/__main__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/uproot_browser/__main__.py b/src/uproot_browser/__main__.py index 075af23..d6c3b84 100644 --- a/src/uproot_browser/__main__.py +++ b/src/uproot_browser/__main__.py @@ -6,12 +6,12 @@ import functools import os +import typing from pathlib import Path from typing import Any, Callable import click import uproot -from click_default_group import DefaultGroup from ._version import version as __version__ @@ -19,6 +19,11 @@ VERSION = __version__ +if typing.TYPE_CHECKING: + DefaultGroup = click.Group +else: + from click_default_group import DefaultGroup + @click.group(context_settings=CONTEXT_SETTINGS, cls=DefaultGroup, default="browse") @click.version_option(version=VERSION) From add5374e7cfdea2a93700fc45131ca4145fa4a23 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 28 Nov 2023 12:30:54 -0500 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 96da73b..123cc61 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ pipx run uproot-browser uproot-browser currently provides the following features (get help with `-h` or `--help`, view the current version with `--version`): -- `browse` can be used to display a TUI (text user interface), acts as default if no subcommand specified +- `browse` can be used to display a TUI (text user interface), acts as default if no subcommand specified. - `plot` can be used to display a plot. - `tree` can be used to display a tree.