1
0
mirror of synced 2024-11-25 02:34:24 +01:00

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:
jvoisin 2018-06-04 00:14:24 +02:00
parent e71eff4814
commit 4ebf9754f8

View File

@ -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__)
continue for name in glob.glob(os.path.join(current_dir, '*.py')):
elif name == 'libmat2.abstract': if name in ('abstract.py', '__init__.py'):
continue continue
importlib.import_module(name) basename = os.path.basename(name)
name, _ = os.path.splitext(basename)
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!"""