From 9987261fc1eb11df396ae5e0fb4c1830c1a48756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Fredrik=20Ki=C3=A6r?= <31612826+anders-kiaer@users.noreply.github.com> Date: Sun, 29 May 2022 21:24:43 +0200 Subject: [PATCH] Add commandline entrypoint for `webviz-config-editor` (#594) --- CHANGELOG.md | 3 +++ webviz_config/command_line.py | 45 ++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c6ecc98..17ed32a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [UNRELEASED] - YYYY-MM-DD +### Added +- [#594](https://github.com/equinor/webviz-config/pull/594) - Added early testing of graphical user interface (GUI) for editing and creating Webviz configuration files. Run `webviz editor` to start the GUI. + ### Fixed - [#588](https://github.com/equinor/webviz-config/pull/588) - Added compatibility with upstream dependency `bleach >= 5`. diff --git a/webviz_config/command_line.py b/webviz_config/command_line.py index c679df99..80bb01ed 100644 --- a/webviz_config/command_line.py +++ b/webviz_config/command_line.py @@ -1,7 +1,10 @@ import sys import json +import shutil +import logging import argparse import pathlib +import subprocess from ._build_webviz import build_webviz from ._deployment import main_radix_deployment @@ -11,7 +14,7 @@ from ._user_preferences import set_user_preferences, get_user_preference -def main() -> None: +def main() -> None: # pylint: disable=too-many-statements parser = argparse.ArgumentParser( prog=("Creates a Webviz Dash app from a configuration setup") @@ -229,6 +232,46 @@ def entrypoint_schema(args: argparse.Namespace) -> None: parser_schema.set_defaults(func=entrypoint_schema) + # Add "editor" parser: + + parser_editor = subparsers.add_parser( + "editor", + help="Create and edit Webviz configuration files", + ) + + # parser_editor.add_argument( + # "--path", + # type=pathlib.Path, + # help="Path to already existing Webviz configuration file.", + # ) + + def entrypoint_editor( # pylint: disable=unused-argument + args: argparse.Namespace, + ) -> None: + + if sys.version_info < (3, 8): + raise RuntimeError("Webviz editor requires at least Python 3.8") + + path_wce_executable = shutil.which("webviz-config-editor") + if path_wce_executable is None: + raise RuntimeError( + "webviz-config-editor executable not found. You can download this from " + "release assets (https://github.com/equinor/webviz-config-editor/releases)." + ) + + logging.warning( + "Note that Webviz editor is in beta and early testing. " + "Problems/bugs likely to occur." + ) + + command = [path_wce_executable] # + ([] if args.path is None else [args.path]) + try: + subprocess.run(command, check=True, capture_output=True) + except subprocess.CalledProcessError: + subprocess.run(command + ["--no-sandbox"], check=True) + + parser_editor.set_defaults(func=entrypoint_editor) + # Do the argument parsing: args = parser.parse_args()