Skip to content

Commit

Permalink
Fix entry point discovery for older versions of python
Browse files Browse the repository at this point in the history
  • Loading branch information
amykyta3 committed Aug 1, 2022
1 parent e23c04a commit 7ed5b6d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# PeakRDL

PeakRDL is a free and open-source control & status register (CSR) toolchain.
This projects provides a command-line tool that unifies many aspects of register
This project provides a command-line tool that unifies many aspects of register
automation centered around the SystemRDL register description language.

## Documentation
Expand Down
2 changes: 1 addition & 1 deletion src/peakrdl/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.0"
__version__ = "0.3.0"
19 changes: 19 additions & 0 deletions src/peakrdl/plugins/entry_points.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# type: ignore
import sys

if sys.version_info >= (3,10,0):
from importlib import metadata

def get_entry_points(group_name):
return metadata.entry_points().select(group=group_name)

elif sys.version_info >= (3,8,0):
from importlib import metadata

def get_entry_points(group_name):
return metadata.entry_points().get(group_name, tuple())

else:
import pkg_resources
def get_entry_points(group_name):
return pkg_resources.iter_entry_points(group_name)
6 changes: 2 additions & 4 deletions src/peakrdl/plugins/exporter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import TYPE_CHECKING, Any, List
from importlib import metadata

from .import entry_points
from ..subcommand import ExporterSubcommand

if TYPE_CHECKING:
Expand Down Expand Up @@ -79,10 +79,8 @@ def get_exporter_plugins() -> List[ExporterSubcommandPluginWrapper]:
},
)
"""
eps = metadata.entry_points().select(group='peakrdl.exporters')

exporters = []
for ep in eps:
for ep in entry_points.get_entry_points("peakrdl.exporters"): # type: ignore
exporter = ExporterSubcommandPluginWrapper(ep.name, ep.load())
exporters.append(exporter)

Expand Down
6 changes: 2 additions & 4 deletions src/peakrdl/plugins/importer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import TYPE_CHECKING, Any, List
from importlib import metadata

from . import entry_points
from ..importer import Importer

if TYPE_CHECKING:
Expand Down Expand Up @@ -79,10 +79,8 @@ def get_importer_plugins() -> List[Importer]:
},
)
"""
eps = metadata.entry_points().select(group='peakrdl.importers')

importers = []
for ep in eps:
for ep in entry_points.get_entry_points("peakrdl.importers"): # type: ignore
importer = ImporterPluginWrapper(ep.name, ep.load())
importers.append(importer)

Expand Down

0 comments on commit 7ed5b6d

Please sign in to comment.