From 2e57bf3f11e9c007bd6677fd4169f287e4b50f59 Mon Sep 17 00:00:00 2001 From: babysor00 Date: Sat, 9 Apr 2022 11:11:58 +0800 Subject: [PATCH] Remove unused codes --- .vscode/launch.json | 2 +- mkgui/base/_cli.py | 43 ----------------------------------- mkgui/base/ui/streamlit_ui.py | 15 ++++-------- 3 files changed, 6 insertions(+), 54 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index bca81a9..8b82132 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -68,7 +68,7 @@ "request": "launch", "program": "mkgui\\base\\_cli.py", "console": "integratedTerminal", - "args": ["launch-ui", "mkgui.app:mocking_bird" + "args": [ "mkgui.app:mocking_bird" ] }, ] diff --git a/mkgui/base/_cli.py b/mkgui/base/_cli.py index 3706271..937a839 100644 --- a/mkgui/base/_cli.py +++ b/mkgui/base/_cli.py @@ -1,10 +1,6 @@ -"""Command line interface.""" - import os import sys - import typer -from pydantic.error_wrappers import ValidationError cli = typer.Typer() @@ -21,44 +17,5 @@ def launch_ui(opyrator: str, port: int = typer.Option(8051, "--port", "-p")) -> from mkgui.base.ui.streamlit_ui import launch_ui launch_ui(opyrator, port) - -@cli.command() -def launch_api( - opyrator: str, - port: int = typer.Option(8080, "--port", "-p"), - host: str = typer.Option("0.0.0.0", "--host", "-h"), -) -> None: - """Start a HTTP API server for the opyrator. - - This will launch a FastAPI server based on the OpenAPI standard and with an automatic interactive documentation. - """ - # Add the current working directory to the sys path - # This is required to resolve the opyrator path - sys.path.append(os.getcwd()) - - from mkgui.base.api.fastapi_app import launch_api # type: ignore - - launch_api(opyrator, port, host) - - -@cli.command() -def call(opyrator: str, input_data: str) -> None: - """Execute the opyrator from command line.""" - # Add the current working directory to the sys path - # This is required to resolve the opyrator path - sys.path.append(os.getcwd()) - - try: - from mkgui.base import Opyrator - - output = Opyrator(opyrator)(input_data) - if output: - typer.echo(output.json(indent=4)) - else: - typer.echo("Nothing returned!") - except ValidationError as ex: - typer.secho(str(ex), fg=typer.colors.RED, err=True) - - if __name__ == "__main__": cli() \ No newline at end of file diff --git a/mkgui/base/ui/streamlit_ui.py b/mkgui/base/ui/streamlit_ui.py index 9fe749f..7191eb9 100644 --- a/mkgui/base/ui/streamlit_ui.py +++ b/mkgui/base/ui/streamlit_ui.py @@ -35,7 +35,7 @@ st.set_page_config( with st.spinner("Loading MockingBird GUI. Please wait..."): opyrator = Opyrator("{opyrator_path}") -render_streamlit_ui(opyrator) +render_streamlit_ui(opyrator, action="{action}") """ @@ -43,7 +43,7 @@ def launch_ui(opyrator_path: str, port: int = 8501) -> None: with NamedTemporaryFile( suffix=".py", mode="w", encoding="utf-8", delete=False ) as f: - f.write(STREAMLIT_RUNNER_SNIPPET.format(opyrator_path=opyrator_path)) + f.write(STREAMLIT_RUNNER_SNIPPET.format_map({'opyrator_path': opyrator_path, 'action': "Synthesize"})) f.seek(0) # TODO: PYTHONPATH="$PYTHONPATH:/workspace/opyrator/src" @@ -105,8 +105,6 @@ class InputUI: "definitions", {} ) - # TODO: check if state has input data - def render_ui(self, streamlit_app_root) -> None: if has_input_ui_renderer(self._input_class): # The input model has a rendering function @@ -116,10 +114,7 @@ class InputUI: ).dict() return - required_properties = self._input_class.schema(by_alias=True).get( - "required", [] - ) - print(self._schema_properties) + # print(self._schema_properties) for property_key in self._schema_properties.keys(): property = self._schema_properties[property_key] @@ -806,7 +801,7 @@ class OutputUI: streamlit.json(jsonable_encoder(output_data)) -def render_streamlit_ui(opyrator: Opyrator) -> None: +def render_streamlit_ui(opyrator: Opyrator, action: str = "Execute") -> None: title = opyrator.name # init @@ -829,7 +824,7 @@ def render_streamlit_ui(opyrator: Opyrator) -> None: with left: - execute_selected = st.button("Execute") + execute_selected = st.button(action) if execute_selected: with st.spinner("Executing operation. Please wait..."): try: