Skip to content

Commit

Permalink
Add Choice schema. Pull forward dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
amykyta3 committed Jun 9, 2023
1 parent 9b2d6fd commit 8527296
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
},
python_requires='>=3.6',
install_requires=[
"systemrdl-compiler >= 1.25.3",
"peakrdl-html >= 2.10.0",
"peakrdl-ipxact >= 3.4.0",
"peakrdl-regblock >= 0.11.0",
"peakrdl-systemrdl >= 0.2.0",
"systemrdl-compiler >= 1.26.0",
"peakrdl-html >= 2.10.1",
"peakrdl-ipxact >= 3.4.1",
"peakrdl-regblock >= 0.14.0",
"peakrdl-systemrdl >= 0.3.0",
"peakrdl-uvm >= 2.3.0",
"tomli;python_version<'3.11'"
],
Expand Down
14 changes: 14 additions & 0 deletions src/peakrdl/config/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,17 @@ def extract(self, data: Any, path: str, err_ctx: str) -> Any:
raise SchemaException(f"{err_ctx}: {str(e)}") from e

return cls

class Choice(String):
"""
Schema that matches against a specific set of allowed strings
"""
def __init__(self, choices: List[str]) -> None:
super().__init__()
self.choices = choices

def extract(self, data: Any, path: str, err_ctx: str) -> Any:
s = super().extract(data, path, err_ctx)
if s not in self.choices:
raise SchemaException(f"{err_ctx}: Value '{s}' is not a valid choice. Must be one of: {','.join(self.choices)}")
return s
16 changes: 5 additions & 11 deletions src/peakrdl/process_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,9 @@ def process_input(rdlc: 'RDLCompiler', importers: 'Sequence[Importer]', input_fi


def elaborate(rdlc: 'RDLCompiler', parameters: Dict[str, Any], options: 'argparse.Namespace') -> 'AddrmapNode':
try:
root = rdlc.elaborate(
top_def_name=options.top_def_name,
inst_name=options.inst_name,
parameters=parameters
)
except (ValueError, TypeError) as e:
# Parameter issues raise ValueError or TypeError
# TODO: Fix exception types once they become specialized in the compiler
rdlc.msg.fatal(e.args[0])

root = rdlc.elaborate(
top_def_name=options.top_def_name,
inst_name=options.inst_name,
parameters=parameters
)
return root.top

0 comments on commit 8527296

Please sign in to comment.