ManderaGeneral / generalimport

Handle all your optional dependencies with a single call!
https://pypi.org/project/generalimport/
Apache License 2.0
16 stars 1 forks source link

See if we can use find_spec instead since it's falling back on legacy now #15

Closed Mandera closed 2 years ago

Mandera commented 2 years ago

https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.create_module

Existing importers just to study

from _distutils_hack import DistutilsMetaFinder
from pkg_resources.extern import VendorImporter
from setuptools.extern import VendorImporter
from setuptools._vendor.importlib_metadata import MetadataPathFinder

Minimal new Importer structure

class Importer:
    def find_spec(self, fullname, path=None, target=None):
        return importlib.util.spec_from_loader(fullname, self)

    def create_module(self, spec):
        pass

    def exec_module(self, module):
        pass
Mandera commented 2 years ago

Worked smoothly! Feels a bit faster as well: d108fb30abddb61d9b79a7c677c3daf12fb15b80