From 468d512fcca502e00c027a77f7751a6281723c18 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 2 Feb 2025 21:06:51 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- surfactant/__main__.py | 2 +- surfactant/cmd/config_tui.py | 4 +- surfactant/cmd/tui.py | 89 ++++++++++++++++++++---------------- 3 files changed, 52 insertions(+), 43 deletions(-) diff --git a/surfactant/__main__.py b/surfactant/__main__.py index 071f3a0f..97a8f1cb 100755 --- a/surfactant/__main__.py +++ b/surfactant/__main__.py @@ -14,7 +14,6 @@ from surfactant.cmd.cli import add, edit, find from surfactant.cmd.config import config from surfactant.cmd.config_tui import config_tui -from surfactant.cmd.tui import tui from surfactant.cmd.createconfig import create_config from surfactant.cmd.generate import sbom as generate from surfactant.cmd.merge import merge_command @@ -27,6 +26,7 @@ plugin_update_db_cmd, ) from surfactant.cmd.stat import stat +from surfactant.cmd.tui import tui from surfactant.cmd.ui import ui diff --git a/surfactant/cmd/config_tui.py b/surfactant/cmd/config_tui.py index a6bd5940..8c0a6aa6 100644 --- a/surfactant/cmd/config_tui.py +++ b/surfactant/cmd/config_tui.py @@ -294,9 +294,7 @@ def on_mount(self): def action_toggle_dark(self) -> None: """A binding for toggling dark mode""" # pylint: disable=attribute-defined-outside-init - self.theme = ( - "textual-dark" if self.theme == "textual-light" else "textual-light" - ) + self.theme = "textual-dark" if self.theme == "textual-light" else "textual-light" def action_save_sbom(self) -> None: """Saves the current SBOM to file""" diff --git a/surfactant/cmd/tui.py b/surfactant/cmd/tui.py index afa58a52..a14daeee 100644 --- a/surfactant/cmd/tui.py +++ b/surfactant/cmd/tui.py @@ -19,6 +19,7 @@ import surfactant.cmd.generate import surfactant.cmd.merge + class SelectFileButtons(textual.widgets.Static): # pylint: disable=too-few-public-methods def __init__(self, allow_folder_selection: bool): @@ -76,7 +77,7 @@ def __init__(self, label: str, allow_file_selection: bool, allow_folder_selectio self.label = label self.allow_file_selection = allow_file_selection self.allow_folder_selection = allow_folder_selection - self.input_path = '' + self.input_path = "" def compose(self) -> textual.app.ComposeResult: if len(self.input_path) == 0: @@ -88,12 +89,13 @@ def on_click(self): def set_path(path: Optional[textual.widgets.DirectoryTree.FileSelected]): if path: self.input_path = path - self.query_one(textual.widgets.Label).update( - f"{self.label} {path}" - ) + self.query_one(textual.widgets.Label).update(f"{self.label} {path}") + + base_dir = "./" if len(self.input_path) == 0 else self.input_path + self.app.push_screen( + SelectFile(self.allow_file_selection, self.allow_folder_selection, base_dir), set_path + ) - base_dir = './' if len(self.input_path) == 0 else self.input_path - self.app.push_screen(SelectFile(self.allow_file_selection, self.allow_folder_selection, base_dir), set_path) class GenerateTab(textual.widgets.Static): def __init__(self): @@ -107,25 +109,31 @@ def __init__(self): self.input_format = textual.widgets.Select([("CyTRICS", "CyTRICS")], allow_blank=False) self.skip_install_path = textual.widgets.Checkbox("Skip Install Path") self.recorded_institution = textual.widgets.Input(placeholder="Recorded Institution") - self.output_format = textual.widgets.Select([ - ("CyTRICS", "CyTRICS"), - ("SPDX", "SPDX"), - ("CSV", "CSV") - ], allow_blank=False) + self.output_format = textual.widgets.Select( + [("CyTRICS", "CyTRICS"), ("SPDX", "SPDX"), ("CSV", "CSV")], allow_blank=False + ) def compose(self) -> textual.app.ComposeResult: yield self.file_input yield self.output_dir - yield textual.containers.HorizontalGroup(textual.widgets.Label("Output Filename: "), self.output_name) + yield textual.containers.HorizontalGroup( + textual.widgets.Label("Output Filename: "), self.output_name + ) yield textual.widgets.Rule() yield textual.widgets.Label("Optional options:") yield self.input_sbom yield self.skip_gather yield self.skip_relationships - yield textual.containers.HorizontalGroup(textual.widgets.Label("Input Format: "), self.input_format) + yield textual.containers.HorizontalGroup( + textual.widgets.Label("Input Format: "), self.input_format + ) yield self.skip_install_path - yield textual.containers.HorizontalGroup(textual.widgets.Label("Recorded Institution: "), self.recorded_institution) - yield textual.containers.HorizontalGroup(textual.widgets.Label("Output Format: "), self.output_format) + yield textual.containers.HorizontalGroup( + textual.widgets.Label("Recorded Institution: "), self.recorded_institution + ) + yield textual.containers.HorizontalGroup( + textual.widgets.Label("Output Format: "), self.output_format + ) yield textual.widgets.Button("Run", id="run") @textual.on(textual.widgets.Button.Pressed, "#run") @@ -164,6 +172,7 @@ def handle_run(self) -> None: _ = input() self.app.refresh() + class MergePath(textual.widgets.Static): def __init__(self): super().__init__() @@ -172,8 +181,7 @@ def __init__(self): def compose(self) -> textual.app.ComposeResult: yield textual.containers.HorizontalGroup( - textual.widgets.Button("-", id=f"remove_path"), - self.path_selector + textual.widgets.Button("-", id="remove_path"), self.path_selector ) @textual.on(textual.widgets.Button.Pressed, "#remove_path") @@ -181,6 +189,7 @@ def remove_path(self): self.active = False self.remove() + class MergePathsHolder(textual.widgets.Static): def __init__(self): super().__init__() @@ -197,33 +206,38 @@ def add_merge_path(self): self.merge_paths.append(MergePath()) self.mount(self.merge_paths[-1], before="#add_merge_path") + class MergeTab(textual.widgets.Static): def __init__(self): super().__init__() self.merge_paths = MergePathsHolder() self.output_dir = FileInput("Output directory:", False, True) self.output_name = textual.widgets.Input(placeholder="Output Filename") - self.input_format = textual.widgets.Select([ - ("CyTRICS", "CyTRICS"), - ("SPDX", "SPDX"), - ("CSV", "CSV") - ], allow_blank=False) - self.output_format = textual.widgets.Select([ - ("CyTRICS", "CyTRICS"), - ("SPDX", "SPDX"), - ("CSV", "CSV") - ], allow_blank=False) + self.input_format = textual.widgets.Select( + [("CyTRICS", "CyTRICS"), ("SPDX", "SPDX"), ("CSV", "CSV")], allow_blank=False + ) + self.output_format = textual.widgets.Select( + [("CyTRICS", "CyTRICS"), ("SPDX", "SPDX"), ("CSV", "CSV")], allow_blank=False + ) self.config_file = FileInput("Config File", True, False) def compose(self) -> textual.app.ComposeResult: yield self.merge_paths yield self.output_dir - yield textual.containers.HorizontalGroup(textual.widgets.Label("Output Filename: "), self.output_name) + yield textual.containers.HorizontalGroup( + textual.widgets.Label("Output Filename: "), self.output_name + ) yield textual.widgets.Rule() yield textual.widgets.Label("Optional options:") - yield textual.containers.HorizontalGroup(textual.widgets.Label("Input Format: "), self.input_format) - yield textual.containers.HorizontalGroup(textual.widgets.Label("Output Format: "), self.output_format) - yield textual.containers.HorizontalGroup(textual.widgets.Label("Config File: "), self.config_file) + yield textual.containers.HorizontalGroup( + textual.widgets.Label("Input Format: "), self.input_format + ) + yield textual.containers.HorizontalGroup( + textual.widgets.Label("Output Format: "), self.output_format + ) + yield textual.containers.HorizontalGroup( + textual.widgets.Label("Config File: "), self.config_file + ) yield textual.widgets.Button("Run", id="run") @textual.on(textual.widgets.Button.Pressed, "#run") @@ -283,16 +297,14 @@ def compose(self) -> textual.app.ComposeResult: yield textual.widgets.Tabs(Tab("Generate", id="Generate"), Tab("Merge", id="Merge")) yield textual.containers.ScrollableContainer(id="MainContainer") - def on_mount(self) -> None: self.query_one(textual.widgets.Tabs).focus() def on_tabs_tab_activated(self, event: textual.widgets.Tabs.TabActivated) -> None: - TABS = ( - ("Generate", self.generate_tab), - ("Merge", self.merge_tab) + TABS = (("Generate", self.generate_tab), ("Merge", self.merge_tab)) + main_container = self.get_child_by_id( + "MainContainer", textual.containers.ScrollableContainer ) - main_container = self.get_child_by_id("MainContainer", textual.containers.ScrollableContainer) main_container.query_children().remove() for name, tab in TABS: if event.tab.id == name: @@ -301,13 +313,12 @@ def on_tabs_tab_activated(self, event: textual.widgets.Tabs.TabActivated) -> Non def action_toggle_dark(self) -> None: """A binding for toggling dark mode""" # pylint: disable=attribute-defined-outside-init - self.theme = ( - "textual-dark" if self.theme == "textual-light" else "textual-light" - ) + self.theme = "textual-dark" if self.theme == "textual-light" else "textual-light" def action_quit(self) -> None: self.app.exit() + @click.command("tui") def tui(): """Create a configuration input file with a TUI"""