From 83ef298c6bbcd726ec6cdde4c28223ee2121e465 Mon Sep 17 00:00:00 2001 From: Jennings Zhang Date: Wed, 25 Jan 2023 05:12:13 -0500 Subject: [PATCH] Add spinner for StrictYAML --- chrisomatic/cli/typer.py | 11 ++++++----- chrisomatic/spec/deserialize.py | 22 +++++++++++++++------- pyproject.toml | 2 +- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/chrisomatic/cli/typer.py b/chrisomatic/cli/typer.py index 618662f..da0a45e 100644 --- a/chrisomatic/cli/typer.py +++ b/chrisomatic/cli/typer.py @@ -1,17 +1,17 @@ import asyncio -import typer import sys from pathlib import Path +import typer from rich.console import Console from strictyaml import YAMLValidationError -from chrisomatic.spec.deserialize import deserialize_config + from chrisomatic.cli import Gstr_title from chrisomatic.cli.agenda import agenda as apply_from_config from chrisomatic.framework.outcome import Outcome +from chrisomatic.spec.deserialize import deserialize_config from chrisomatic.spec.given import ValidationError - app = typer.Typer(add_completion=False) @@ -41,13 +41,14 @@ def apply( input_config = file.read_text() filename = str(file) + console = Console(force_terminal=(True if tty else None)) + try: - config = deserialize_config(input_config, filename) + config = deserialize_config(input_config, filename, console) except (ValidationError, YAMLValidationError) as e: print(e) raise typer.Abort() - console = Console(force_terminal=(True if tty else None)) console.print(Gstr_title) final_result = asyncio.run(apply_from_config(config, console)) if final_result.summary[Outcome.FAILED] > 0: diff --git a/chrisomatic/spec/deserialize.py b/chrisomatic/spec/deserialize.py index 46779c3..2d6c897 100644 --- a/chrisomatic/spec/deserialize.py +++ b/chrisomatic/spec/deserialize.py @@ -1,13 +1,21 @@ -from chrisomatic.spec.schema import schema +import serde +import strictyaml +from rich.console import Console +from rich.status import Status + from chrisomatic.spec.given import GivenConfig -from serde import from_dict -from strictyaml import load +from chrisomatic.spec.schema import schema -def deserialize_config(input_config: str, filename: str): - return _load_from_yaml(input_config, filename) +def deserialize_config(input_config: str, filename: str, console: Console) -> GivenConfig: + if input_config.count('\n') < 100: + return _load_from_yaml(input_config, filename) + text = f"Loading [green]\"{filename}\"[/green] using " \ + "[italic]StrictYAML[/italic], might take a while..." + with Status(status=text, spinner='dots10', console=console): + return _load_from_yaml(input_config, filename) def _load_from_yaml(input_config: str, filename: str) -> GivenConfig: - parsed_yaml = load(input_config, schema=schema, label=filename) - return from_dict(GivenConfig, parsed_yaml.data) + parsed_yaml = strictyaml.load(input_config, schema=schema, label=filename) + return serde.from_dict(GivenConfig, parsed_yaml.data) diff --git a/pyproject.toml b/pyproject.toml index 60610cc..cc29414 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "chrisomatic" -version = "0.4.0" +version = "0.4.1" description = "ChRIS backend provisioner with Powerpointlessness" authors = ["Jennings Zhang "] license = "MIT"