Skip to content

Commit

Permalink
fix: support textual 0.86 to at least 1.0.0 (#185)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii authored Dec 13, 2024
1 parent 174f9de commit f48dc18
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 35 deletions.
13 changes: 6 additions & 7 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,18 @@ You can set up a development environment by running:
```bash
python3 -m venv .venv
source ./.env/bin/activate
pip install -U pip
pip install -e '.[dev]'
pip install -U pip dependency-groups
pip install -e. $(dependency-groups dev)
```

If you have the [Python Launcher for Unix](https://github.com/brettcannon/python-launcher),
you can instead do:
If you use `uv`, you can do:

```bash
py -m venv .venv
py -m pip install -U pip
py -m pip install -e '.[dev]'
uv sync
```

instead.

# Post setup

You should prepare pre-commit, which will help you by checking that commits
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repos:
- click
- hist
- numpy
- textual>=0.32
- textual>=0.86

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
Expand Down
10 changes: 8 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
nox.options.default_venv_backend = "uv|virtualenv"


def dep_group(group: str) -> list[str]:
return nox.project.load_toml("pyproject.toml")["dependency-groups"][group] # type: ignore[no-any-return]


@nox.session(reuse_venv=True)
def lint(session: nox.Session) -> None:
"""
Expand All @@ -30,7 +34,7 @@ def tests(session: nox.Session) -> None:
"""
Run the unit and regular tests.
"""
session.install("-e.[test]")
session.install("-e.", *dep_group("test"))
session.run("pytest", *session.posargs)


Expand All @@ -39,7 +43,9 @@ def minimums(session: nox.Session) -> None:
"""
Run the unit and regular tests.
"""
session.install("-e.[test]", "--resolution=lowest-direct", "--only-binary=:all:")
session.install(
"-e.", *dep_group("test"), "--resolution=lowest-direct", "--only-binary=:all:"
)
session.run("pytest", *session.posargs)


Expand Down
28 changes: 13 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,11 @@ dependencies = [
]

[project.optional-dependencies]
test = [
"pytest >=8",
"pytest-asyncio >=0.24",
"scikit-hep-testdata >=0.4.10",
]
iterm = [
"matplotlib",
"itermplot==0.5",
"mplhep",
]
dev = [
"ipython >=6",
"pytest >=6",
"pytest-asyncio",
"scikit-hep-testdata",
]

[project.urls]
homepage = "https://github.com/scikit-hep/uproot-browser"
Expand All @@ -76,16 +65,25 @@ repository = "https://github.com/scikit-hep/uproot-browser"
[project.scripts]
uproot-browser = "uproot_browser.__main__:main"

[dependency-groups]
test = [
"pytest >=8",
"pytest-asyncio >=0.24",
"scikit-hep-testdata >=0.4.10",
]
dev = [
"ipython >=6",
"textual-dev",
{include-group = "test"},
]

[tool.hatch]
version.source = "vcs"
build.hooks.vcs.version-file = "src/uproot_browser/_version.py"

[tool.uv]
environments = [
"python_version >= '3.10'",
]
dev-dependencies = [
"uproot-browser[test]",
"python_version >= '3.11'",
]

[tool.pytest.ini_options]
Expand Down
4 changes: 2 additions & 2 deletions src/uproot_browser/tui/browser.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ Footer > .footer--key {
}

Footer > .footer--highlight-key {
background: $secondary-darken-3;
background: $secondary-darken-2;
text-style: bold;
}

Footer {
background: $secondary;
background: $secondary-lighten-2;
}

HelpScreen {
Expand Down
25 changes: 19 additions & 6 deletions src/uproot_browser/tui/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def action_quit_with_dump(self) -> None:
assert err_widget.exc
items = [err_widget.exc]

theme = "rrt" if self.dark else "default"
dark = self.dark if hasattr(self, "dark") else self.theme != "textual-light" # type: ignore[has-type]

theme = "ansi_dark" if dark else "ansi_light"

results = rich.console.Group(
*items,
Expand All @@ -133,18 +135,29 @@ def action_quit_with_dump(self) -> None:

def action_toggle_theme(self) -> None:
"""An action to toggle dark mode."""
dark = not self.dark
if self.plot_widget.item:
self.plot_widget.item.theme = "dark" if dark else "default"
self.dark = dark
if hasattr(self, "dark"):
# pylint: disable-next=access-member-before-definition
dark = not self.dark # type: ignore[has-type]
if self.plot_widget.item:
self.plot_widget.item.theme = "dark" if dark else "default"
# pylint: disable-next=attribute-defined-outside-init
self.dark = dark
else:
dark = self.theme != "textual-light"
theme = "textual-light" if dark else "textual-dark"

if self.plot_widget.item:
self.plot_widget.item.theme = "dark" if dark else "default"
self.theme = theme

def on_uproot_selected(self, message: UprootSelected) -> None:
"""A message sent by the tree when a file is clicked."""

content_switcher = self.query_one("#main-view", textual.widgets.ContentSwitcher)

try:
theme = "dark" if self.dark else "default"
dark = self.dark if hasattr(self, "dark") else self.theme != "textual-light"
theme = "dark" if dark else "default"
make_plot(message.upfile[message.path], theme, 20)
self.plot_widget.item = Plotext(message.upfile, message.path, theme)
content_switcher.current = "plot"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ async def test_help_focus() -> None:
).run_test() as pilot:
await pilot.press("?")
focus_chain = [widget.id for widget in pilot.app.screen.focus_chain]
assert focus_chain == ["help-text", None, "help-done"]
assert pilot.app.screen.focused.id == "help-text"
assert len(focus_chain) == 3
assert focus_chain[-1] == "help-done"

0 comments on commit f48dc18

Please sign in to comment.