diff --git a/glad/plugin.py b/glad/plugin.py index b7d233ce..a8f4cc1e 100644 --- a/glad/plugin.py +++ b/glad/plugin.py @@ -1,11 +1,22 @@ import logging -import pkg_resources +import inspect +try: + from importlib.metadata import entry_points +except ImportError: + try: + from importlib_metadata import entry_points + except ImportError: + import pkg_resources + + def entry_points(group=None): + return pkg_resources.iter_entry_points(group=group, name=None) import glad.specification from glad.generator.c import CGenerator from glad.generator.rust import RustGenerator from glad.parse import Specification + logger = logging.getLogger(__name__) @@ -16,33 +27,28 @@ DEFAULT_GENERATORS = dict( c=CGenerator, rust=RustGenerator - # TODO fix those - # d=DGenerator, - # volt=VoltGenerator ) - DEFAULT_SPECIFICATIONS = dict() -import inspect for name, cls in inspect.getmembers(glad.specification, inspect.isclass): if issubclass(cls, Specification) and cls is not Specification: DEFAULT_SPECIFICATIONS[cls.NAME] = cls -def find_generators(default=DEFAULT_GENERATORS, entry_point=GENERATOR_ENTRY_POINT): - generators = dict(default) +def find_generators(default=None, entry_point=GENERATOR_ENTRY_POINT): + generators = dict(DEFAULT_GENERATORS if default is None else default) - for entry_point in pkg_resources.iter_entry_points(group=entry_point, name=None): + for entry_point in entry_points(group=entry_point): generators[entry_point.name] = entry_point.load() logger.debug('loaded language %s: %s', entry_point.name, generators[entry_point.name]) return generators -def find_specifications(default=DEFAULT_SPECIFICATIONS, entry_point=SPECIFICATION_ENTRY_POINT): - specifications = dict(default) +def find_specifications(default=None, entry_point=SPECIFICATION_ENTRY_POINT): + specifications = dict(DEFAULT_SPECIFICATIONS if default is None else default) - for entry_point in pkg_resources.iter_entry_points(group=entry_point, name=None): + for entry_point in entry_points(group=entry_point): specifications[entry_point.name] = entry_point.load() logger.debug('loaded specification %s: %s', entry_point.name, specifications[entry_point.name]) diff --git a/setup.py b/setup.py index a4405b67..c687805f 100644 --- a/setup.py +++ b/setup.py @@ -57,13 +57,11 @@ 'License :: OSI Approved :: MIT License', 'Natural Language :: English', 'Operating System :: OS Independent', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', 'Topic :: Games/Entertainment', 'Topic :: Multimedia :: Graphics', 'Topic :: Multimedia :: Graphics :: 3D Rendering',