Skip to content

Commit

Permalink
Access EntryPoints differently based on python version
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-el authored and anders-kiaer committed May 10, 2024
1 parent 6a10147 commit 148bb99
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions webviz_config/themes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from importlib.metadata import entry_points
from importlib.metadata import EntryPoint, entry_points

from .. import WebvizConfigTheme
from ._default_theme import default_theme
Expand All @@ -8,18 +8,21 @@

__all__ = ["installed_themes"]

for entry_point in (
entry_points().get("webviz_config_themes", [])
if sys.version_info < (3, 10, 0)
else entry_points( # pylint: disable=unexpected-keyword-arg
group="webviz_config_themes"
)
):

def process_entry_point(entry_point: EntryPoint):
theme = entry_point.load()

globals()[entry_point.name] = theme
__all__.append(entry_point.name)

if isinstance(theme, WebvizConfigTheme):
installed_themes[theme.theme_name] = theme


if sys.version_info < (3, 10, 0):
eps = entry_points().get("webviz_config_themes", [])
else:
eps = entry_points().select(group="webviz_config_themes")

for ep in eps:
process_entry_point(ep)

0 comments on commit 148bb99

Please sign in to comment.