diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index fc098b2..f133ca8 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 45caed4..889daaa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/noxfile.py b/noxfile.py index d1398b7..ef610f7 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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: """ @@ -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) @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 1299cd1..cb5e637 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -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] diff --git a/src/uproot_browser/tui/browser.css b/src/uproot_browser/tui/browser.css index 5012af3..b221842 100644 --- a/src/uproot_browser/tui/browser.css +++ b/src/uproot_browser/tui/browser.css @@ -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 { diff --git a/src/uproot_browser/tui/browser.py b/src/uproot_browser/tui/browser.py index 89c57ce..2faf7a1 100644 --- a/src/uproot_browser/tui/browser.py +++ b/src/uproot_browser/tui/browser.py @@ -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, @@ -133,10 +135,20 @@ 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.""" @@ -144,7 +156,8 @@ def on_uproot_selected(self, message: UprootSelected) -> None: 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" diff --git a/tests/test_tui.py b/tests/test_tui.py index 03b936d..d235adb 100644 --- a/tests/test_tui.py +++ b/tests/test_tui.py @@ -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"