drop py3.6. Misc housekeeping
This commit is contained in:
@@ -1,38 +1,19 @@
|
||||
from typing import TYPE_CHECKING, Dict, Type, List, Any
|
||||
from typing import TYPE_CHECKING, Dict, Type
|
||||
import functools
|
||||
import sys
|
||||
|
||||
from peakrdl.plugins.exporter import ExporterSubcommandPlugin #pylint: disable=import-error
|
||||
from peakrdl.config import schema #pylint: disable=import-error
|
||||
from peakrdl.plugins.exporter import ExporterSubcommandPlugin
|
||||
from peakrdl.config import schema
|
||||
from peakrdl.plugins.entry_points import get_entry_points
|
||||
|
||||
from .exporter import RegblockExporter
|
||||
from .cpuif import CpuifBase, apb3, apb4, axi4lite, passthrough, avalon
|
||||
from .udps import ALL_UDPS
|
||||
from . import entry_points
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import argparse
|
||||
from systemrdl.node import AddrmapNode
|
||||
|
||||
|
||||
class Choice(schema.String):
|
||||
"""
|
||||
Schema that matches against a specific set of allowed strings
|
||||
|
||||
Base PeakRDL does not have this schema yet. Polyfill here for now until it
|
||||
is added and widely available.
|
||||
"""
|
||||
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 schema.SchemaException(f"{err_ctx}: Value '{s}' is not a valid choice. Must be one of: {','.join(self.choices)}")
|
||||
return s
|
||||
|
||||
|
||||
class Exporter(ExporterSubcommandPlugin):
|
||||
short_desc = "Generate a SystemVerilog control/status register (CSR) block"
|
||||
|
||||
@@ -40,7 +21,7 @@ class Exporter(ExporterSubcommandPlugin):
|
||||
|
||||
cfg_schema = {
|
||||
"cpuifs": {"*": schema.PythonObjectImport()},
|
||||
"default_reset": Choice(["rst", "rst_n", "arst", "arst_n"]),
|
||||
"default_reset": schema.Choice(["rst", "rst_n", "arst", "arst_n"]),
|
||||
}
|
||||
|
||||
@functools.lru_cache()
|
||||
@@ -60,7 +41,7 @@ class Exporter(ExporterSubcommandPlugin):
|
||||
}
|
||||
|
||||
# Load any cpuifs specified via entry points
|
||||
for ep, dist in entry_points.get_entry_points("peakrdl_regblock.cpuif"):
|
||||
for ep, dist in get_entry_points("peakrdl_regblock.cpuif"):
|
||||
name = ep.name
|
||||
cpuif = ep.load()
|
||||
if name in cpuifs:
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
import sys
|
||||
from typing import List, Tuple, TYPE_CHECKING, Optional
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from importlib.metadata import EntryPoint, Distribution
|
||||
|
||||
if sys.version_info >= (3,10,0):
|
||||
from importlib import metadata
|
||||
|
||||
def _get_entry_points(group_name: str) -> List[Tuple['EntryPoint', Optional['Distribution']]]:
|
||||
eps = []
|
||||
for ep in metadata.entry_points().select(group=group_name):
|
||||
eps.append((ep, ep.dist))
|
||||
return eps
|
||||
|
||||
def _get_name_from_dist(dist: 'Distribution') -> str:
|
||||
return dist.name
|
||||
|
||||
elif sys.version_info >= (3,8,0): # pragma: no cover
|
||||
from importlib import metadata
|
||||
|
||||
def _get_entry_points(group_name: str) -> List[Tuple['EntryPoint', Optional['Distribution']]]:
|
||||
eps = [] # type: List[Tuple[EntryPoint, Optional[Distribution]]]
|
||||
dist_names = set()
|
||||
for dist in metadata.distributions():
|
||||
# Due to a bug in importlib.metadata's distributions iterator, in
|
||||
# some cases editable installs will cause duplicate dist entries.
|
||||
# Filter this out.
|
||||
dist_name = get_name_from_dist(dist)
|
||||
if dist_name in dist_names:
|
||||
continue
|
||||
dist_names.add(dist_name)
|
||||
|
||||
for ep in dist.entry_points:
|
||||
if ep.group == group_name:
|
||||
eps.append((ep, dist))
|
||||
return eps
|
||||
|
||||
def _get_name_from_dist(dist: 'Distribution') -> str:
|
||||
return dist.metadata["Name"]
|
||||
|
||||
else: # pragma: no cover
|
||||
import pkg_resources
|
||||
|
||||
def _get_entry_points(group_name: str) -> List[Tuple['EntryPoint', Optional['Distribution']]]:
|
||||
eps = []
|
||||
for ep in pkg_resources.iter_entry_points(group_name):
|
||||
eps.append((ep, ep.dist))
|
||||
return eps # type: ignore
|
||||
|
||||
def _get_name_from_dist(dist: 'Distribution') -> str:
|
||||
return dist.project_name # type: ignore
|
||||
|
||||
|
||||
def get_entry_points(group_name: str) -> List[Tuple['EntryPoint', Optional['Distribution']]]:
|
||||
return _get_entry_points(group_name)
|
||||
|
||||
def get_name_from_dist(dist: 'Distribution') -> str:
|
||||
return _get_name_from_dist(dist)
|
||||
Reference in New Issue
Block a user