Skip to content
Snippets Groups Projects
Commit 612dce53 authored by Cédric Krier's avatar Cédric Krier :atom:
Browse files

Use entry point load method to load module

This uses the same method as in find_path since 2306ca8df7ee.

Closes #12884
parent 96a8b0e7
No related branches found
No related tags found
No related merge requests found
Pipeline #75355 passed
......@@ -5,6 +5,5 @@
import itertools
import logging
import os
import sys
from collections import defaultdict
from glob import iglob
......@@ -9,6 +8,5 @@
from collections import defaultdict
from glob import iglob
from importlib.machinery import SOURCE_SUFFIXES, FileFinder, SourceFileLoader
from sql import Table
from sql.functions import CurrentTimestamp
......@@ -54,28 +52,7 @@
if name not in EGG_MODULES:
raise
ep = EGG_MODULES[name]
# Can not use ep.load because modules are declared in an importable
# path and it can not import submodule.
path = os.path.join(
ep.dist.location, *ep.module_name.split('.')[:-1])
if not os.path.isdir(path):
# Find module in path
for path in sys.path:
path = os.path.join(
path, *ep.module_name.split('.')[:-1])
if os.path.isdir(os.path.join(path, name)):
break
else:
# When testing modules from setuptools location is the
# module directory
path = os.path.dirname(ep.dist.location)
spec = FileFinder(
path, (SourceFileLoader, SOURCE_SUFFIXES)
).find_spec(fullname)
if spec.loader:
module = spec.loader.load_module()
else:
raise
module = ep.load()
return module
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment