mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
modules_from_path can return crashed modules
This commit is contained in:
parent
6862284b3c
commit
20909b50cd
1 changed files with 10 additions and 2 deletions
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue