Skip to content

Commit d1f34fd

Browse files
author
Hans Kallekleiv
authored
Resolve path to lists of pathlib objects (#153)
1 parent d5069e8 commit d1f34fd

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

webviz_config/_config_parser.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pathlib
44
import inspect
55
import importlib
6+
import typing
67

78
import yaml
89

@@ -109,17 +110,25 @@ def _call_signature(
109110

110111
if expected_type == pathlib.Path:
111112
kwargs[arg] = (config_folder / pathlib.Path(kwargs[arg])).resolve()
112-
113-
if not isinstance(kwargs[arg], expected_type):
114-
raise ParserError(
115-
f"{terminal_colors.RED}{terminal_colors.BOLD}"
116-
f"The value provided for argument `{arg}` "
117-
f"given to container `{container_name}` is "
118-
f"of type `{type(kwargs[arg]).__name__}`. "
119-
f"Expected type "
120-
f"`{argspec.annotations[arg].__name__}`."
121-
f"{terminal_colors.END}"
122-
)
113+
elif expected_type == typing.List[pathlib.Path]:
114+
kwargs[arg] = [
115+
(config_folder / pathlib.Path(patharg)).resolve()
116+
for patharg in kwargs[arg]
117+
]
118+
try:
119+
if not isinstance(kwargs[arg], expected_type):
120+
raise ParserError(
121+
f"{terminal_colors.RED}{terminal_colors.BOLD}"
122+
f"The value provided for argument `{arg}` "
123+
f"given to container `{container_name}` is "
124+
f"of type `{type(kwargs[arg]).__name__}`. "
125+
f"Expected type "
126+
f"`{argspec.annotations[arg].__name__}`."
127+
f"{terminal_colors.END}"
128+
)
129+
# Typechecking typing classes does not work in python 3.7
130+
except TypeError:
131+
pass
123132

124133
special_args = ""
125134
if "app" in argspec.args:

0 commit comments

Comments
 (0)