Pass module name and set __file__ on module to avoid AttributeErrors saying module has no __file__ attribute

This commit is contained in:
Fabia Serra Arrizabalaga 2023-02-22 00:43:26 +01:00 committed by Jakub Trllo
parent 574f8d2c6d
commit c41a3b1cb8
2 changed files with 2 additions and 2 deletions

View file

@ -28,6 +28,7 @@ def import_filepath(filepath, module_name=None):
# Prepare module object where content of file will be parsed
module = types.ModuleType(module_name)
module.__file__ = filepath
if six.PY3:
# Use loader so module has full specs
@ -41,7 +42,6 @@ def import_filepath(filepath, module_name=None):
# Execute content and store it to module object
six.exec_(_stream.read(), module.__dict__)
module.__file__ = filepath
return module

View file

@ -304,7 +304,7 @@ def publish_plugins_discover(paths=None):
continue
try:
module = import_filepath(abspath)
module = import_filepath(abspath, mod_name)
# Store reference to original module, to avoid
# garbage collection from collecting it's global