Skip to content

Commit

Permalink
Change parse() function's arguments`
Browse files Browse the repository at this point in the history
Input to `parse()` used to be `yaml_input` for the actual YAML, and `file_in` for the YAML file path.
THe latter was only used to resolve relative image paths, not for reading the actual file that was passed.
Therefore, `file_in` was changed to `base_path`; this argument receives the *directory* of the original YAML file, which is more intuitive for the actual use case.
  • Loading branch information
formatc1702 committed Dec 6, 2020
1 parent 2d7770a commit 6a42a30
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/wireviz/wireviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
from wireviz.wv_helper import expand, open_file_read


def parse(yaml_input: str, file_in: (str, Path) = None, file_out: (str, Path) = None, return_types: (None, str, Tuple[str]) = None) -> Any:
def parse(yaml_input: str, base_path: (str, Path) = None, file_out: (str, Path) = None, return_types: (None, str, Tuple[str]) = None) -> Any:
"""
Parses yaml input string and does the high-level harness conversion
:param yaml_input: a string containing the yaml input data
:param file_out:
:param base_path: base path used to resolve any relative paths to image files
:param file_out: filename of the generated output
: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
Expand All @@ -47,7 +48,7 @@ def parse(yaml_input: str, file_in: (str, Path) = None, file_out: (str, Path) =
if attribs.get('image'):
image_path = attribs['image']['src']
if not Path(image_path).is_absolute(): # resolve relative image path
image_path = (Path(file_in).parent / image_path).resolve()
image_path = (Path(base_path) / image_path).resolve()
attribs['image']['src'] = image_path

if sec == 'connectors':
Expand Down Expand Up @@ -210,7 +211,7 @@ def parse_file(yaml_file: str, file_out: (str, Path) = None) -> None:
file_out = fn
file_out = os.path.abspath(file_out)

parse(yaml_input, file_in=Path(yaml_file).resolve(), file_out=file_out)
parse(yaml_input, base_path=Path(yaml_file).parent, file_out=file_out)


def parse_cmdline():
Expand Down Expand Up @@ -252,7 +253,7 @@ def main():
file_out = args.output_file
file_out = os.path.abspath(file_out)

parse(yaml_input, file_in=Path(args.input_file).resolve(), file_out=file_out)
parse(yaml_input, base_path=Path(args.input_file).parent, file_out=file_out)


if __name__ == '__main__':
Expand Down

0 comments on commit 6a42a30

Please sign in to comment.