Skip to content

Commit

Permalink
glad: switches from pkg_resources to importlib.metadata
Browse files Browse the repository at this point in the history
closes: Dav1dde#389
  • Loading branch information
Dav1dde committed Oct 28, 2022
1 parent 525eddb commit d7f961e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
30 changes: 18 additions & 12 deletions glad/plugin.py
Original file line number Diff line number Diff line change
@@ -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__)


Expand All @@ -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])

Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit d7f961e

Please sign in to comment.