Skip to content

Commit

Permalink
Update smart_file_resolve()
Browse files Browse the repository at this point in the history
  • Loading branch information
17o2 authored and laurierloi committed Jan 19, 2023
1 parent ef69d7e commit 359cd8d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/wireviz/wv_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,17 @@ def aspect_ratio(image_src):
return 1 # Assume 1:1 when unable to read actual image size


def smart_file_resolve(filename: str, possible_paths: List[str]) -> Path:
def smart_file_resolve(filename: str, possible_paths: (str, List[str])) -> Path:
if not isinstance(possible_paths, List):
possible_paths = [possible_paths]
filename = Path(filename)
if filename.is_absolute():
if filename.exists():
return filename
else:
raise Exception(f'{filename} does not exist.')
else: # search all possible paths in decreasing order of precedence
possible_paths = [Path(path).resolve() for path in possible_paths]
possible_paths = [Path(path).resolve() for path in possible_paths if path is not None]
for possible_path in possible_paths:
resolved_path = (possible_path / filename).resolve()
if (resolved_path).exists():
Expand Down

0 comments on commit 359cd8d

Please sign in to comment.