From c814e04691546032b1a6fe2937b2a4a8382396e3 Mon Sep 17 00:00:00 2001 From: 2-REC Date: Tue, 21 Dec 2021 17:35:29 +0700 Subject: [PATCH 1/2] Check min length of plugin path --- openpype/lib/plugin_tools.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/openpype/lib/plugin_tools.py b/openpype/lib/plugin_tools.py index 2a859da7cb4..8de5f641eb0 100644 --- a/openpype/lib/plugin_tools.py +++ b/openpype/lib/plugin_tools.py @@ -227,20 +227,27 @@ def filter_pyblish_plugins(plugins): # iterate over plugins for plugin in plugins[:]: - file = os.path.normpath(inspect.getsourcefile(plugin)) - file = os.path.normpath(file) - - # host determined from path - host_from_file = file.split(os.path.sep)[-4:-3][0] - plugin_kind = file.split(os.path.sep)[-2:-1][0] - - # TODO: change after all plugins are moved one level up - if host_from_file == "openpype": - host_from_file = "global" - try: config_data = presets[host]["publish"][plugin.__name__] except KeyError: + # host determined from path + file = os.path.normpath(inspect.getsourcefile(plugin)) + file = os.path.normpath(file) + + split_path = file.split(os.path.sep) + if len(split_path) < 4: + log.warning( + 'plugin path too short to extract host {}'.format(file) + ) + continue + + host_from_file = split_path[-4:-3][0] + plugin_kind = split_path[-2:-1][0] + + # TODO: change after all plugins are moved one level up + if host_from_file == "openpype": + host_from_file = "global" + try: config_data = presets[host_from_file][plugin_kind][plugin.__name__] # noqa: E501 except KeyError: From 6d15256840d39d07b8e4c3d1e4a20f8b715027c5 Mon Sep 17 00:00:00 2001 From: 2-REC Date: Tue, 21 Dec 2021 17:38:39 +0700 Subject: [PATCH 2/2] Simplified indexing --- openpype/lib/plugin_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openpype/lib/plugin_tools.py b/openpype/lib/plugin_tools.py index 8de5f641eb0..7c66f9760de 100644 --- a/openpype/lib/plugin_tools.py +++ b/openpype/lib/plugin_tools.py @@ -241,8 +241,8 @@ def filter_pyblish_plugins(plugins): ) continue - host_from_file = split_path[-4:-3][0] - plugin_kind = split_path[-2:-1][0] + host_from_file = split_path[-4] + plugin_kind = split_path[-2] # TODO: change after all plugins are moved one level up if host_from_file == "openpype":