From 20909b50cd69ceec24856a3e58e1e9db5621702a Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 18 Mar 2021 09:43:37 +0100 Subject: [PATCH] modules_from_path can return crashed modules --- pype/lib/python_module_tools.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pype/lib/python_module_tools.py b/pype/lib/python_module_tools.py index b5400c9981..559dd04bab 100644 --- a/pype/lib/python_module_tools.py +++ b/pype/lib/python_module_tools.py @@ -9,15 +9,20 @@ log = logging.getLogger(__name__) PY3 = sys.version_info[0] == 3 -def modules_from_path(folder_path): +def modules_from_path(folder_path, return_crashed=False): """Get python scripts as modules from a path. Arguments: path (str): Path to folder containing python scripts. + return_crasher (bool): Crashed module paths with exception info + will be returned too. Returns: - List of modules. + list, tuple: List of modules when `return_crashed` is False else tuple + with list of modules at first place and tuple of path and exception + info at second place. """ + crashed = [] modules = [] # Just skip and return empty list if path is not set if not folder_path: @@ -70,12 +75,15 @@ def modules_from_path(folder_path): modules.append(module) except Exception: + crashed.append((full_path, sys.exc_info())) log.warning( "Failed to load path: \"{0}\"".format(full_path), exc_info=True ) continue + if return_crashed: + return modules, crashed return modules