Skip to content

Commit

Permalink
Add commandline entrypoint for webviz-config-editor (equinor#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer authored May 29, 2022
1 parent f7f38e5 commit 9987261
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
45 changes: 44 additions & 1 deletion webviz_config/command_line.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 9987261

Please sign in to comment.