Skip to content

Commit

Permalink
update after latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zsailer committed Aug 29, 2022
1 parent 7a41459 commit 0101fcb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
22 changes: 18 additions & 4 deletions jupyter_events/cli.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import json
import pathlib

import click
from jsonschema import ValidationError
from rich.console import Console
from rich.json import JSON
from rich.markup import escape
from rich.padding import Padding
from rich.style import Style

from jupyter_events.schema import EventSchema
from jupyter_events.schema import EventSchema, EventSchemaLoadingError

console = Console()


@click.group()
def main():
"""A simple CLI tool to quickly validate JSON schemas against
Jupyter Event's custom validator.
You can see Jupyter Event's meta-schema here:
https://raw.githubusercontent.com/jupyter/jupyter_events/main/jupyter_events/schemas/event-metaschema.yml
"""
pass


Expand All @@ -24,21 +33,26 @@ def validate(schema):
SCHEMA can be a JSON/YAML string or filepath to a schema.
"""
console.rule("Validating the following schema")
console.rule("Validating the following schema", style=Style(color="blue"))
# Soft load the schema without validating.
_schema = EventSchema._load_schema(schema)
try:
_schema = EventSchema._load_schema(schema)
except EventSchemaLoadingError:
schema_path = pathlib.Path(schema)
_schema = EventSchema._load_schema(schema_path)
# Print what was found.
schema_json = JSON(json.dumps(_schema))
console.print(Padding(schema_json, (1, 0, 1, 4)))
# Now validate this schema against the meta-schema.
console.rule("Results")
try:
EventSchema(_schema)
console.rule("Results", style=Style(color="green"))
out = Padding(
"[green]\u2714[white] Nice work! This schema is valid.", (1, 0, 1, 0)
)
console.print(out)
except ValidationError as err:
console.rule("Results", style=Style(color="red"))
console.print("[red]\u274c [white]The schema failed to validate.\n")
console.print("We found the following error with your schema:")
out = escape(str(err))
Expand Down
5 changes: 3 additions & 2 deletions jupyter_events/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ def add_listener(
Parameters
----------
modified: bool
If True (default), listens to the data after it has been mutated/modified
by the list of modifiers.
schema_id: str
$id of the schema
version: str
The schema version
listener: Callable
A callable function/method that executes when the named event occurs.
"""
Expand Down

0 comments on commit 0101fcb

Please sign in to comment.