From a319ba4336860a362e4f9299e00ab9398276aab2 Mon Sep 17 00:00:00 2001 From: Jared Duffey Date: Wed, 3 Apr 2024 13:19:46 -0400 Subject: [PATCH] Added try except blocks around each filter import in ExamplePlugin * If one filter has a syntax error it now does not prevent the rest of the plugin from loading. Most useful for plugin development Signed-off-by: Jared Duffey --- .../python/plugins/ExamplePlugin/Plugin.py | 34 ++++++++++++++---- .../python/plugins/ExamplePlugin/__init__.py | 35 ++++++++++++++----- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/wrapping/python/plugins/ExamplePlugin/Plugin.py b/wrapping/python/plugins/ExamplePlugin/Plugin.py index e22f969ead..e68edda334 100644 --- a/wrapping/python/plugins/ExamplePlugin/Plugin.py +++ b/wrapping/python/plugins/ExamplePlugin/Plugin.py @@ -3,11 +3,33 @@ Insert documentation here. """ -from ExamplePlugin.ExampleFilter1 import ExampleFilter1 -from ExamplePlugin.ExampleFilter2 import ExampleFilter2 -from ExamplePlugin.CreateArray import CreateArrayFilter -from ExamplePlugin.InitializeData import InitializeDataPythonFilter -from ExamplePlugin.TemplateFilter import TemplateFilter +_filters = [] + +try: + from ExamplePlugin.ExampleFilter1 import ExampleFilter1 + _filters.append(ExampleFilter1) +except ImportError: + pass +try: + from ExamplePlugin.ExampleFilter2 import ExampleFilter2 + _filters.append(ExampleFilter2) +except ImportError: + pass +try: + from ExamplePlugin.CreateArray import CreateArrayFilter + _filters.append(CreateArrayFilter) +except ImportError: + pass +try: + from ExamplePlugin.InitializeData import InitializeDataPythonFilter + _filters.append(InitializeDataPythonFilter) +except ImportError: + pass +try: + from ExamplePlugin.TemplateFilter import TemplateFilter + _filters.append(TemplateFilter) +except ImportError: + pass # FILTER_INCLUDE_INSERT @@ -30,4 +52,4 @@ def vendor(self) -> str: return 'Description' def get_filters(self): - return [ExampleFilter1,ExampleFilter2,CreateArrayFilter,InitializeDataPythonFilter,TemplateFilter] # FILTER_NAME_INSERT + return _filters # FILTER_NAME_INSERT diff --git a/wrapping/python/plugins/ExamplePlugin/__init__.py b/wrapping/python/plugins/ExamplePlugin/__init__.py index 8117594a4e..b47890133c 100644 --- a/wrapping/python/plugins/ExamplePlugin/__init__.py +++ b/wrapping/python/plugins/ExamplePlugin/__init__.py @@ -1,15 +1,34 @@ from ExamplePlugin.Plugin import ExamplePlugin -from ExamplePlugin.ExampleFilter1 import ExampleFilter1 -from ExamplePlugin.ExampleFilter2 import ExampleFilter2 -from ExamplePlugin.CreateArray import CreateArrayFilter -from ExamplePlugin.InitializeData import InitializeDataPythonFilter -from ExamplePlugin.TemplateFilter import TemplateFilter +__all__ = ['ExamplePlugin', 'get_plugin'] + +try: + from ExamplePlugin.ExampleFilter1 import ExampleFilter1 + __all__.append('ExampleFilter1') +except ImportError: + pass +try: + from ExamplePlugin.ExampleFilter2 import ExampleFilter2 + __all__.append('ExampleFilter2') +except ImportError: + pass +try: + from ExamplePlugin.CreateArray import CreateArrayFilter + __all__.append('CreateArrayFilter') +except ImportError: + pass +try: + from ExamplePlugin.InitializeData import InitializeDataPythonFilter + __all__.append('InitializeDataPythonFilter') +except ImportError: + pass +try: + from ExamplePlugin.TemplateFilter import TemplateFilter + __all__.append('TemplateFilter') +except ImportError: + pass # FILTER_INCLUDE_INSERT def get_plugin(): return ExamplePlugin() - -__all__ = ['ExamplePlugin','ExampleFilter1', 'ExampleFilter2', 'CreateArrayFilter', 'InitializeDataPythonFilter', 'TemplateFilter', 'get_plugin'] # FILTER_NAME_INSERT -