diff --git a/src/wireviz/wireviz.py b/src/wireviz/wireviz.py index 3c8d0a82..0d4e4593 100755 --- a/src/wireviz/wireviz.py +++ b/src/wireviz/wireviz.py @@ -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 @@ -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': @@ -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(): @@ -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__':