Skip to content

Commit

Permalink
Add spinner for StrictYAML
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Jan 25, 2023
1 parent c175f7e commit 83ef298
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
11 changes: 6 additions & 5 deletions chrisomatic/cli/typer.py
Original file line number Diff line number Diff line change
@@ -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)


Expand Down Expand Up @@ -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:
Expand Down
22 changes: 15 additions & 7 deletions chrisomatic/spec/deserialize.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <Jennings.Zhang@childrens.harvard.edu>"]
license = "MIT"
Expand Down

0 comments on commit 83ef298

Please sign in to comment.