dist: Switch build_apps from pkg_resources to importlib.metadata

This commit is contained in:
rdb 2023-10-15 13:47:08 +02:00
parent 39e4e4167c
commit 36bcfe7705

View File

@ -54,10 +54,16 @@ def _register_python_loaders():
_register_python_loaders.done = True
registry = p3d.LoaderFileTypeRegistry.getGlobalPtr()
from importlib.metadata import entry_points
import pkg_resources
for entry_point in pkg_resources.iter_entry_points('panda3d.loaders'):
eps = entry_points()
if isinstance(eps, dict): # Python 3.8 and 3.9
loaders = eps.get('panda3d.loaders', ())
else:
loaders = eps.select(group='panda3d.loaders')
registry = p3d.LoaderFileTypeRegistry.get_global_ptr()
for entry_point in loaders:
registry.register_deferred_type(entry_point)
@ -1698,7 +1704,7 @@ class bdist_apps(setuptools.Command):
setattr(self, opt, None)
def finalize_options(self):
import pkg_resources
from importlib.metadata import entry_points
# We need to massage the inputs a bit in case they came from a
# setup.cfg file.
@ -1712,11 +1718,17 @@ class bdist_apps(setuptools.Command):
self.signing_certificate = os.path.abspath(self.signing_certificate)
self.signing_private_key = os.path.abspath(self.signing_private_key)
eps = entry_points()
if isinstance(eps, dict): # Python 3.8 and 3.9
installer_eps = eps.get('panda3d.bdist_apps.installers', ())
else:
installer_eps = eps.select(group='panda3d.bdist_apps.installers')
tmp = self.DEFAULT_INSTALLER_FUNCS.copy()
tmp.update(self.installer_functions)
tmp.update({
entrypoint.name: entrypoint.load()
for entrypoint in pkg_resources.iter_entry_points('panda3d.bdist_apps.installers')
for entrypoint in installer_eps
})
self.installer_functions = tmp