Merge pull request #1651 from freqtrade/fix/importerror_strats

Catch ModuleNotFoundError when importing external code
This commit is contained in:
Misagh 2019-03-12 16:37:30 +01:00 committed by GitHub
commit 954963b40e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,7 +31,11 @@ class IResolver(object):
# Generate spec based on absolute path # Generate spec based on absolute path
spec = importlib.util.spec_from_file_location('unknown', str(module_path)) spec = importlib.util.spec_from_file_location('unknown', str(module_path))
module = importlib.util.module_from_spec(spec) module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module) # type: ignore # importlib does not use typehints try:
spec.loader.exec_module(module) # type: ignore # importlib does not use typehints
except ModuleNotFoundError as err:
# Catch errors in case a specific module is not installed
logger.info(f"Could not import {module_path} due to '{err}'")
valid_objects_gen = ( valid_objects_gen = (
obj for name, obj in inspect.getmembers(module, inspect.isclass) obj for name, obj in inspect.getmembers(module, inspect.isclass)