Skip to content

Commit

Permalink
Split the YAML loading and parsing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
17o2 authored and laurierloi committed Jan 19, 2023
1 parent f325b69 commit 471a6c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions src/wireviz/wireviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pathlib import Path
import sys
from typing import Any, Tuple
from typing import Any, Dict, Tuple

import yaml

Expand All @@ -15,11 +15,11 @@
from wireviz.wv_helper import expand, get_single_key_and_value, is_arrow, open_file_read


def parse(yaml_input: str, file_out: (str, Path) = None, return_types: (None, str, Tuple[str]) = ('gv','html','png','svg','tsv')) -> Any:
def parse_text(yaml_str: str, file_out: (str, Path) = None, return_types: (None, str, Tuple[str]) = ('gv','html','png','svg','tsv')) -> Any:
"""
Parses yaml input string and does the high-level harness conversion
Parses a YAML input string and does the high-level harness conversion
:param yaml_input: a string containing the yaml input data
:param yaml_input: a string containing the YAML input data
:param file_out:
:param return_types: if None, then returns None; if the value is a string, then a
corresponding data format will be returned; if the value is a tuple of strings,
Expand All @@ -29,8 +29,23 @@ def parse(yaml_input: str, file_out: (str, Path) = None, return_types: (None, st
- "svg" - will return the SVG data
- "harness" - will return the `Harness` instance
"""
yaml_data = yaml.safe_load(yaml_str)
return parse(yaml_data=yaml_data, file_out=file_out, return_types=return_types )

yaml_data = yaml.safe_load(yaml_input)
def parse(yaml_data: Dict, file_out: (str, Path) = None, return_types: (None, str, Tuple[str]) = ('gv','html','png','svg','tsv')) -> Any:
"""
Parses a YAML dictionary and does the high-level harness conversion
:param yaml_data: a dictionary containing the YAML data
:param file_out:
:param return_types: if None, then returns None; if the value is a string, then a
corresponding data format will be returned; if the value is a tuple of strings,
then for every valid format in the `return_types` tuple, another return type
will be generated and returned in the same order; currently supports:
- "png" - will return the PNG data
- "svg" - will return the SVG data
- "harness" - will return the `Harness` instance
"""


# define variables =========================================================
Expand Down
2 changes: 1 addition & 1 deletion src/wireviz/wv_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def wireviz(file, format, prepend, output_file, version):

yaml_input = prepend_input + yaml_input

wv.parse(yaml_input, file_out=file_out, return_types=return_types)
wv.parse_text(yaml_input, file_out=file_out, return_types=return_types)

print()

Expand Down

0 comments on commit 471a6c3

Please sign in to comment.