From f2ecff26888ce0906f3a3224a1b4db6e05cd36be Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 18 Mar 2021 10:16:50 +0100 Subject: [PATCH] modules_from_path always return all information with filepaths --- pype/lib/applications.py | 8 ++++---- pype/lib/python_module_tools.py | 8 +++----- pype/modules/ftrack/ftrack_server/ftrack_server.py | 5 ++--- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/pype/lib/applications.py b/pype/lib/applications.py index d20b01c3d2..f7d029e2ea 100644 --- a/pype/lib/applications.py +++ b/pype/lib/applications.py @@ -618,13 +618,13 @@ class ApplicationLaunchContext: ) continue - modules = modules_from_path(path) - for _module in modules: + modules, _crashed = modules_from_path(path) + for _filepath, module in modules: all_classes["pre"].extend( - classes_from_module(PreLaunchHook, _module) + classes_from_module(PreLaunchHook, module) ) all_classes["post"].extend( - classes_from_module(PostLaunchHook, _module) + classes_from_module(PostLaunchHook, module) ) for launch_type, classes in all_classes.items(): diff --git a/pype/lib/python_module_tools.py b/pype/lib/python_module_tools.py index 559dd04bab..44a1007889 100644 --- a/pype/lib/python_module_tools.py +++ b/pype/lib/python_module_tools.py @@ -9,7 +9,7 @@ log = logging.getLogger(__name__) PY3 = sys.version_info[0] == 3 -def modules_from_path(folder_path, return_crashed=False): +def modules_from_path(folder_path): """Get python scripts as modules from a path. Arguments: @@ -72,7 +72,7 @@ def modules_from_path(folder_path, return_crashed=False): module.__file__ = full_path - modules.append(module) + modules.append((full_path, module)) except Exception: crashed.append((full_path, sys.exc_info())) @@ -82,9 +82,7 @@ def modules_from_path(folder_path, return_crashed=False): ) continue - if return_crashed: - return modules, crashed - return modules + return modules, crashed def recursive_bases_from_class(klass): diff --git a/pype/modules/ftrack/ftrack_server/ftrack_server.py b/pype/modules/ftrack/ftrack_server/ftrack_server.py index 9d9d8c4630..1612a2f474 100644 --- a/pype/modules/ftrack/ftrack_server/ftrack_server.py +++ b/pype/modules/ftrack/ftrack_server/ftrack_server.py @@ -64,13 +64,13 @@ class FtrackServer: register_functions = [] for path in paths: # Get all modules with functions - modules, crashed = modules_from_path(path, return_crashed=True) + modules, crashed = modules_from_path(path) for filepath, exc_info in crashed: log.warning("Filepath load crashed {}.\n{}".format( filepath, traceback.format_exception(*exc_info) )) - for module in modules: + for filepath, module in modules: register_function = None for name, attr in module.__dict__.items(): if ( @@ -80,7 +80,6 @@ class FtrackServer: register_function = attr break - filepath = os.path.abspath(module.__file__) if not register_function: log.warning( "\"{}\" - Missing register method".format(filepath)