Automatically include input file directory in list to resolve image paths

This commit is contained in:
Daniel Rojas 2021-10-16 14:44:07 +02:00
parent b46d26319a
commit 5aaea651b1

View File

@ -70,6 +70,8 @@ def parse(
Required parameter if inp is not a path. Required parameter if inp is not a path.
image_paths (Path | str | List, optional): image_paths (Path | str | List, optional):
Paths to use when resolving any image paths included in the data. Paths to use when resolving any image paths included in the data.
Note: If inp is a path to a YAML file,
its parent directory will automatically be included in the list.
Returns: Returns:
Depending on the return_types parameter, may return: Depending on the return_types parameter, may return:
@ -90,6 +92,12 @@ def parse(
output_name = _get_output_name(yaml_file, output_name) output_name = _get_output_name(yaml_file, output_name)
output_file = output_dir / output_name output_file = output_dir / output_name
if yaml_file:
# if reading from file, ensure that input file's parent directory is included in image_paths
default_image_path = yaml_file.parent.resolve()
if not default_image_path in [Path(x).resolve() for x in image_paths]:
image_paths.append(default_image_path)
# define variables ========================================================= # define variables =========================================================
# containers for parsed component data and connection sets # containers for parsed component data and connection sets
template_connectors = {} template_connectors = {}