Skip to content

Commit

Permalink
Add support for multiple prepended files
Browse files Browse the repository at this point in the history
  • Loading branch information
formatc1702 committed Oct 16, 2021
1 parent 5aaea65 commit 08b5124
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/wireviz/wireviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

import yaml

Expand Down
29 changes: 16 additions & 13 deletions src/wireviz/wv_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
@click.option(
"-p",
"--prepend",
default=None,
default=[],
multiple=True,
type=Path,
help="YAML file to prepend to the input file (optional).",
)
Expand Down Expand Up @@ -97,20 +98,19 @@ def wireviz(file, format, prepend, output_dir, output_name, version):
else output_formats[0]
)

image_paths = []
# check prepend file
if prepend:
prepend = Path(prepend)
if not prepend.exists():
raise Exception(f"File does not exist:\n{prepend}")
print("Prepend file:", prepend)

with open_file_read(prepend) as file_handle:
prepend_input = file_handle.read() + "\n"
prepend_dir = prepend.parent
if len(prepend) > 0:
prepend_input = ""
for prepend_file in prepend:
prepend_file = Path(prepend_file)
if not prepend_file.exists():
raise Exception(f"File does not exist:\n{prepend_file}")
print("Prepend file:", prepend_file)

with open_file_read(prepend_file) as file_handle:
prepend_input += file_handle.read() + "\n"
else:
prepend_input = ""
prepend_dir = None

# run WireVIz on each input file
for file in filepaths:
Expand All @@ -132,13 +132,16 @@ def wireviz(file, format, prepend, output_dir, output_name, version):
file_dir = file.parent

yaml_input = prepend_input + yaml_input
image_paths = {file_dir}
for p in prepend:
image_paths.add(Path(p).parent)

wv.parse(
yaml_input,
output_formats=output_formats,
output_dir=_output_dir,
output_name=_output_name,
image_paths=[file_dir, prepend_dir],
image_paths=list(image_paths),
)

print()
Expand Down

0 comments on commit 08b5124

Please sign in to comment.