[+] improve typing
This commit is contained in:
parent
591c893909
commit
1dbba925f1
@ -101,6 +101,43 @@ def check_dict(
|
|||||||
value,
|
value,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def check_list(
|
||||||
|
value: Any,
|
||||||
|
VT: Type[Value],
|
||||||
|
) -> list[Value]: ...
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def check_list(
|
||||||
|
value: Any,
|
||||||
|
) -> list[Any]: ...
|
||||||
|
|
||||||
|
def check_list(
|
||||||
|
value: Any,
|
||||||
|
VT: Optional[Type[Value]] = None,
|
||||||
|
) -> list[Value] | list[Any]:
|
||||||
|
assert isinstance(value, list)
|
||||||
|
value2 = cast(list[Any], value)
|
||||||
|
|
||||||
|
assert all([
|
||||||
|
(
|
||||||
|
VT is None or
|
||||||
|
isinstance(o, VT)
|
||||||
|
)
|
||||||
|
for o in value2
|
||||||
|
])
|
||||||
|
|
||||||
|
if VT is None:
|
||||||
|
return cast(
|
||||||
|
list[Any],
|
||||||
|
value,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return cast(
|
||||||
|
list[Value],
|
||||||
|
value,
|
||||||
|
)
|
||||||
|
|
||||||
def pyproject_load(
|
def pyproject_load(
|
||||||
d: pathlib.Path,
|
d: pathlib.Path,
|
||||||
) -> PyProject:
|
) -> PyProject:
|
||||||
@ -148,18 +185,11 @@ def pyproject_load(
|
|||||||
tool_name = 'online.fxreader.pr34'.replace('.', '-')
|
tool_name = 'online.fxreader.pr34'.replace('.', '-')
|
||||||
|
|
||||||
if (
|
if (
|
||||||
'tool' in content and
|
'tool' in content
|
||||||
isinstance(
|
|
||||||
content['tool'], dict
|
|
||||||
) and
|
|
||||||
all([
|
|
||||||
isinstance(o, str)
|
|
||||||
for o in content['tool']
|
|
||||||
])
|
|
||||||
):
|
):
|
||||||
res.tool = cast(
|
res.tool = check_dict(
|
||||||
dict[str, Any],
|
content['tool'],
|
||||||
content['tool']
|
str,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -173,42 +203,52 @@ def pyproject_load(
|
|||||||
dict
|
dict
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
if 'early_features' in content['tool'][tool_name]:
|
pr34_tool = check_dict(
|
||||||
res.early_features = content['tool'][tool_name]['early_features']
|
check_dict(
|
||||||
|
content['tool'],
|
||||||
|
str,
|
||||||
|
)[tool_name],
|
||||||
|
str
|
||||||
|
)
|
||||||
|
|
||||||
if 'pip_find_links' in content['tool'][tool_name]:
|
if 'early_features' in pr34_tool:
|
||||||
|
res.early_features = pr34_tool['early_features']
|
||||||
|
|
||||||
|
if 'pip_find_links' in pr34_tool:
|
||||||
res.pip_find_links = [
|
res.pip_find_links = [
|
||||||
d.parent / pathlib.Path(o)
|
d.parent / pathlib.Path(o)
|
||||||
for o in content['tool'][tool_name]['pip_find_links']
|
for o in pr34_tool['pip_find_links']
|
||||||
]
|
]
|
||||||
|
|
||||||
if 'runtime_libdirs' in content['tool'][tool_name]:
|
if 'runtime_libdirs' in pr34_tool:
|
||||||
res.runtime_libdirs = [
|
res.runtime_libdirs = [
|
||||||
d.parent / pathlib.Path(o)
|
d.parent / pathlib.Path(o)
|
||||||
# pathlib.Path(o)
|
# pathlib.Path(o)
|
||||||
for o in content['tool'][tool_name]['runtime_libdirs']
|
for o in pr34_tool['runtime_libdirs']
|
||||||
]
|
]
|
||||||
|
|
||||||
if 'runtime_preload' in content['tool'][tool_name]:
|
if 'runtime_preload' in pr34_tool:
|
||||||
res.runtime_preload = [
|
res.runtime_preload = [
|
||||||
d.parent / pathlib.Path(o)
|
d.parent / pathlib.Path(o)
|
||||||
# pathlib.Path(o)
|
# pathlib.Path(o)
|
||||||
for o in content['tool'][tool_name]['runtime_preload']
|
for o in pr34_tool['runtime_preload']
|
||||||
]
|
]
|
||||||
|
|
||||||
if 'requirements' in content['tool'][tool_name]:
|
if 'requirements' in pr34_tool:
|
||||||
assert isinstance(content['tool'][tool_name]['requirements'], dict)
|
|
||||||
|
|
||||||
res.requirements = {
|
res.requirements = {
|
||||||
k : d.parent / pathlib.Path(v)
|
k : d.parent / pathlib.Path(v)
|
||||||
# pathlib.Path(o)
|
# pathlib.Path(o)
|
||||||
for k, v in content['tool'][tool_name]['requirements'].items()
|
for k, v in check_dict(
|
||||||
|
pr34_tool['requirements'],
|
||||||
|
str,
|
||||||
|
str
|
||||||
|
).items()
|
||||||
}
|
}
|
||||||
|
|
||||||
if 'modules' in content['tool'][tool_name]:
|
if 'modules' in pr34_tool:
|
||||||
modules = content['tool'][tool_name]['modules']
|
modules = check_list(
|
||||||
assert isinstance(modules, list)
|
pr34_tool['modules']
|
||||||
|
)
|
||||||
# res.modules = []
|
# res.modules = []
|
||||||
|
|
||||||
for o in modules:
|
for o in modules:
|
||||||
|
Loading…
Reference in New Issue
Block a user