Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command line entrypoint for editor #594

Merged
merged 1 commit into from
May 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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