fake files

This commit is contained in:
Emmanuel Garette 2021-04-12 16:57:57 +02:00
parent f4471c4875
commit cda68e88a2
1 changed files with 15 additions and 0 deletions

View File

@ -26,12 +26,27 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from .variable import CONVERT_OPTION from .variable import CONVERT_OPTION
import importlib.resources import importlib.resources
from os.path import dirname, join
from ..utils import load_modules from ..utils import load_modules
ANNOTATORS = None ANNOTATORS = None
if not 'files' in dir(importlib.resources):
# old python version
class fake_files:
def __init__(self, package):
self.mod = []
dir_package = dirname(importlib.resources._get_package(package).__file__)
for mod in importlib.resources.contents(package):
self.mod.append(join(dir_package, mod))
def iterdir(self):
return self.mod
importlib.resources.files = fake_files
def get_level(module): def get_level(module):
return module.level return module.level