mypy: Amend import_module_from_source, to pass with strict-optional.
Including additional error-reporting.
This commit is contained in:
parent
486f1d2f48
commit
88ae9d04ee
|
@ -36,7 +36,10 @@ def import_module_from_source(path, name=None):
|
||||||
import importlib.util
|
import importlib.util
|
||||||
spec = importlib.util.spec_from_file_location(name, path)
|
spec = importlib.util.spec_from_file_location(name, path)
|
||||||
module = importlib.util.module_from_spec(spec)
|
module = importlib.util.module_from_spec(spec)
|
||||||
spec.loader.exec_module(module)
|
loader = spec.loader
|
||||||
|
if loader is None:
|
||||||
|
return None
|
||||||
|
loader.exec_module(module)
|
||||||
|
|
||||||
return module
|
return module
|
||||||
|
|
||||||
|
@ -123,7 +126,11 @@ def main():
|
||||||
bot_name = args.bot
|
bot_name = args.bot
|
||||||
if args.provision:
|
if args.provision:
|
||||||
provision_bot(os.path.dirname(bot_path), args.force)
|
provision_bot(os.path.dirname(bot_path), args.force)
|
||||||
|
|
||||||
lib_module = import_module_from_source(bot_path, bot_name)
|
lib_module = import_module_from_source(bot_path, bot_name)
|
||||||
|
if lib_module is None:
|
||||||
|
print("ERROR: Could not load bot module. Exiting now.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if not args.quiet:
|
if not args.quiet:
|
||||||
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
|
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
|
||||||
|
|
|
@ -40,6 +40,8 @@ def main():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lib_module = import_module_from_source(bot_path, bot_name)
|
lib_module = import_module_from_source(bot_path, bot_name)
|
||||||
|
if lib_module is None:
|
||||||
|
raise IOError
|
||||||
except IOError:
|
except IOError:
|
||||||
print("Could not find and import bot '{}'".format(bot_name))
|
print("Could not find and import bot '{}'".format(bot_name))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
Loading…
Reference in a new issue