mirror of
https://git.sr.ht/~kivikakk/niar
synced 2024-12-23 00:02:24 +00:00
project: add isinstance_list, fix up errors.
This commit is contained in:
parent
cad501dda2
commit
99273cb385
|
@ -19,6 +19,7 @@ class Prop:
|
||||||
description: str,
|
description: str,
|
||||||
required: bool,
|
required: bool,
|
||||||
isinstance: Optional[type] = None,
|
isinstance: Optional[type] = None,
|
||||||
|
isinstance_list: Optional[type] = None,
|
||||||
issubclass: Optional[type] = None,
|
issubclass: Optional[type] = None,
|
||||||
issubclass_list: Optional[type] = None,
|
issubclass_list: Optional[type] = None,
|
||||||
):
|
):
|
||||||
|
@ -26,13 +27,17 @@ class Prop:
|
||||||
self.description = description
|
self.description = description
|
||||||
self.required = required
|
self.required = required
|
||||||
self.isinstance = isinstance
|
self.isinstance = isinstance
|
||||||
|
self.isinstance_list = isinstance_list
|
||||||
self.issubclass = issubclass
|
self.issubclass = issubclass
|
||||||
self.issubclass_list = issubclass_list
|
self.issubclass_list = issubclass_list
|
||||||
|
|
||||||
def validate(self, project):
|
def validate(self, project):
|
||||||
assert not (
|
assert len(list(filter(None, [
|
||||||
self.issubclass and self.issubclass_list
|
self.isinstance,
|
||||||
), "may only define one of issubclass and issubclass_list"
|
self.isinstance_list,
|
||||||
|
self.issubclass,
|
||||||
|
self.issubclass_list,
|
||||||
|
]))) == 1, "must define exactly one of the is... parameters"
|
||||||
|
|
||||||
if self.required:
|
if self.required:
|
||||||
assert hasattr(project, self.name), (
|
assert hasattr(project, self.name), (
|
||||||
|
@ -49,6 +54,14 @@ class Prop:
|
||||||
f"{self.name!r} ({self.description}) should an instance of "
|
f"{self.name!r} ({self.description}) should an instance of "
|
||||||
f"{self.isinstance!r}, but is {attr!r}"
|
f"{self.isinstance!r}, but is {attr!r}"
|
||||||
)
|
)
|
||||||
|
if self.isinstance_list:
|
||||||
|
assert isinstance(attr, list)
|
||||||
|
for elem in attr:
|
||||||
|
assert isinstance(elem, self.isinstance_list), (
|
||||||
|
f"{project.__module__}.{project.__class__.__qualname__} property "
|
||||||
|
f"{self.name!r} ({self.description}) should a list of instances of "
|
||||||
|
f"{self.isinstanc_list!r}, but has element {elem!r}"
|
||||||
|
)
|
||||||
if self.issubclass:
|
if self.issubclass:
|
||||||
assert issubclass(attr, self.issubclass), (
|
assert issubclass(attr, self.issubclass), (
|
||||||
f"{project.__module__}.{project.__class__.__qualname__} property "
|
f"{project.__module__}.{project.__class__.__qualname__} property "
|
||||||
|
@ -61,7 +74,7 @@ class Prop:
|
||||||
assert issubclass(elem, self.issubclass_list), (
|
assert issubclass(elem, self.issubclass_list), (
|
||||||
f"{project.__module__}.{project.__class__.__qualname__} property "
|
f"{project.__module__}.{project.__class__.__qualname__} property "
|
||||||
f"{self.name!r} ({self.description}) should be a list of subclasses of "
|
f"{self.name!r} ({self.description}) should be a list of subclasses of "
|
||||||
f"{self.issubclass!r}, but has element {attr!r}"
|
f"{self.issubclass_list!r}, but has element {elem!r}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,6 +111,12 @@ class Project:
|
||||||
required=False,
|
required=False,
|
||||||
issubclass_list=CxxrtlPlatform,
|
issubclass_list=CxxrtlPlatform,
|
||||||
),
|
),
|
||||||
|
Prop(
|
||||||
|
"externals",
|
||||||
|
description="a list of Verilog and RTLIL project paths to include in the build",
|
||||||
|
required=False,
|
||||||
|
isinstance_list=str,
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init_subclass__(cls):
|
def __init_subclass__(cls):
|
||||||
|
|
Loading…
Reference in a new issue