Skip to content

Commit

Permalink
fix: support anything uproot supports
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Oct 18, 2024
1 parent c0598c9 commit 75d033e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 62 deletions.
25 changes: 5 additions & 20 deletions src/uproot_browser/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import functools
import os
import typing
from pathlib import Path
from typing import Any, Callable

import click
Expand All @@ -25,15 +24,6 @@
from click_default_group import DefaultGroup


def _existing_path_before_colon(_ctx: object, _value: object, path: str) -> str:
prefix, _, _ = path.partition(":")
if not Path(prefix).is_file():
msg = "{prefix!r} must be an exiting path"
raise click.BadParameter(msg)

return path


@click.group(context_settings=CONTEXT_SETTINGS, cls=DefaultGroup, default="browse")
@click.version_option(version=VERSION)
def main() -> None:
Expand All @@ -43,7 +33,7 @@ def main() -> None:


@main.command()
@click.argument("filename", callback=_existing_path_before_colon)
@click.argument("filename")
def tree(filename: str) -> None:
"""
Display a tree.
Expand All @@ -68,7 +58,7 @@ def new_func(*args: Any, **kwargs: Any) -> Any:


@main.command()
@click.argument("filename", callback=_existing_path_before_colon)
@click.argument("filename")
@click.option(
"--iterm", is_flag=True, help="Display an iTerm plot (requires [iterm] extra)."
)
Expand All @@ -87,10 +77,7 @@ def plot(filename: str, iterm: bool) -> None:

import uproot_browser.dirs # pylint: disable=import-outside-toplevel

fname = uproot_browser.dirs.filename(filename)
selections = uproot_browser.dirs.selections(filename)
my_tree = uproot.open(fname)
*_, item = uproot_browser.dirs.apply_selection(my_tree, selections)
item = uproot.open(filename)

if iterm:
uproot_browser.plot_mpl.plot(item)
Expand All @@ -109,18 +96,16 @@ def plot(filename: str, iterm: bool) -> None:


@main.command()
@click.argument("filename", callback=_existing_path_before_colon)
@click.argument("filename")
def browse(filename: str) -> None:
"""
Display a TUI.
"""
import uproot_browser.dirs # pylint: disable=import-outside-toplevel
import uproot_browser.tui.browser # pylint: disable=import-outside-toplevel

fname = uproot_browser.dirs.filename(filename)

app = uproot_browser.tui.browser.Browser(
path=Path(fname),
path=filename,
)

app.run()
Expand Down
31 changes: 0 additions & 31 deletions src/uproot_browser/dirs.py

This file was deleted.

11 changes: 3 additions & 8 deletions src/uproot_browser/tui/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import contextlib
import sys
from pathlib import Path
from typing import Any, ClassVar

import plotext as plt
Expand Down Expand Up @@ -66,7 +65,7 @@ class Browser(textual.app.App[object]):

show_tree = var(True)

def __init__(self, path: Path, **kwargs: Any) -> None:
def __init__(self, path: str, **kwargs: Any) -> None:
self.path = path
super().__init__(**kwargs)

Expand Down Expand Up @@ -161,10 +160,6 @@ def on_uproot_selected(self, message: UprootSelected) -> None:


if __name__ in {"<run_path>", "__main__"}:
import uproot_browser.dirs

fname = uproot_browser.dirs.filename(
"../scikit-hep-testdata/src/skhep_testdata/data/uproot-Event.root"
)
app = Browser(path=Path(fname))
fname = "../scikit-hep-testdata/src/skhep_testdata/data/uproot-Event.root"
app = Browser(path=fname)
app.run()
5 changes: 2 additions & 3 deletions src/uproot_browser/tui/left_panel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from pathlib import Path
from typing import Any, ClassVar

import rich.panel
Expand Down Expand Up @@ -37,10 +36,10 @@ class UprootTree(textual.widgets.Tree[UprootEntry]):
textual.binding.Binding("l", "cursor_in", "Cursor in", show=False),
]

def __init__(self, path: Path, **args: Any) -> None:
def __init__(self, path: str, **args: Any) -> None:
self.upfile = uproot.open(path)
data = UprootEntry("/", self.upfile)
super().__init__(name=path.name, data=data, label=path.stem, **args)
super().__init__(name=path, data=data, label=path, **args)

def render_label(
self,
Expand Down

0 comments on commit 75d033e

Please sign in to comment.