Import the dynamic import system
The dynamic import should now work when MAT2 is installed system-wide, either via the distribution's packaging system, or via pip.
This commit is contained in:
parent
e71eff4814
commit
4ebf9754f8
@ -1,22 +1,24 @@
|
|||||||
|
import glob
|
||||||
import os
|
import os
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import importlib
|
import importlib
|
||||||
import pkgutil
|
|
||||||
from typing import TypeVar, List
|
from typing import TypeVar, List
|
||||||
|
|
||||||
from . import abstract, unsupported_extensions
|
from . import abstract, unsupported_extensions
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar('T', bound='abstract.AbstractParser')
|
T = TypeVar('T', bound='abstract.AbstractParser')
|
||||||
|
|
||||||
# This loads every parser in a dynamic way
|
def __load_all_parsers():
|
||||||
for module_loader, name, ispkg in pkgutil.walk_packages('.libmat2'):
|
""" Loads every parser in a dynamic way """
|
||||||
if not name.startswith('libmat2.'):
|
current_dir = os.path.dirname(__file__)
|
||||||
|
for name in glob.glob(os.path.join(current_dir, '*.py')):
|
||||||
|
if name in ('abstract.py', '__init__.py'):
|
||||||
continue
|
continue
|
||||||
elif name == 'libmat2.abstract':
|
basename = os.path.basename(name)
|
||||||
continue
|
name, _ = os.path.splitext(basename)
|
||||||
importlib.import_module(name)
|
importlib.import_module('.' + name, package='libmat2')
|
||||||
|
|
||||||
|
__load_all_parsers()
|
||||||
|
|
||||||
def _get_parsers() -> List[T]:
|
def _get_parsers() -> List[T]:
|
||||||
""" Get all our parsers!"""
|
""" Get all our parsers!"""
|
||||||
|
Loading…
Reference in New Issue
Block a user