From b9d474475d0c63992e8cc1fd134818795f152a4f Mon Sep 17 00:00:00 2001 From: Joey Kleingers Date: Mon, 15 Jul 2024 16:23:37 -0400 Subject: [PATCH] BUG FIX: Remove Python plugin import error handling. (#1019) Remove Python plugin error handling, and use relative imports everywhere. This allows import errors to percolate up to C++ and/or the NX GUI. Signed-off-by: Joey Kleingers --- .../utils/PythonPluginInitTemplate.py | 2 +- .../utils/PythonPluginTemplateFile.hpp | 28 ++---- .../src/NXDataAnalysisToolkit/Plugin.py | 91 ++++++------------- .../src/NXDataAnalysisToolkit/__init__.py | 91 ++++++------------- 4 files changed, 61 insertions(+), 151 deletions(-) diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/utils/PythonPluginInitTemplate.py b/src/Plugins/SimplnxCore/src/SimplnxCore/utils/PythonPluginInitTemplate.py index d0a232247e..0768af9937 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/utils/PythonPluginInitTemplate.py +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/utils/PythonPluginInitTemplate.py @@ -2,7 +2,7 @@ """ Insert documentation here for #PLUGIN_NAME# """ -from #PLUGIN_NAME#.Plugin import #PLUGIN_NAME# +from .Plugin import #PLUGIN_NAME# __all__ = ['#PLUGIN_NAME#', 'get_plugin'] diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/utils/PythonPluginTemplateFile.hpp b/src/Plugins/SimplnxCore/src/SimplnxCore/utils/PythonPluginTemplateFile.hpp index a039db556b..ada37ef998 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/utils/PythonPluginTemplateFile.hpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/utils/PythonPluginTemplateFile.hpp @@ -117,11 +117,8 @@ inline Result<> InsertFilterNameInPluginFiles(const std::filesystem::path& plugi if(line == lastMarkerLine && insertToken) { outFile << "# FILTER_START: " << filterName << "\n" - << "try:\n" - << " from " << pluginName << "." << filterName << " import " << filterName << "\n" - << " __all__.append('" << filterName << "')\n" - << "except ImportError:\n" - << " pass\n" + << "from ." << filterName << " import " << filterName << "\n" + << "__all__.append('" << filterName << "')\n" << "# FILTER_END: " << filterName << "\n\n"; } outFile << line << '\n'; // Write the line out to the file @@ -161,11 +158,8 @@ inline Result<> InsertFilterNameInPluginFiles(const std::filesystem::path& plugi if(line == lastMarkerLine && insertToken) { outFile << "# FILTER_START: " << filterName << "\n" - << "try:\n" - << " from " << pluginName << "." << filterName << " import " << filterName << "\n" - << " _filters.append(" << filterName << ")\n" - << "except ImportError:\n" - << " pass\n" + << "from ." << filterName << " import " << filterName << "\n" + << "_filters.append(" << filterName << ")\n" << "# FILTER_END: " << filterName << "\n\n"; } outFile << line << '\n'; // Write the line out to the file @@ -305,11 +299,8 @@ inline std::string GeneratePythonPlugin(const std::string& pluginName, const std for(const auto& name : filterList) { ss << "# FILTER_START: " << name << "\n" - << "try:\n" - << " from " << pluginName << "." << name << " import " << name << "\n" - << " _filters.append(" << name << ")\n" - << "except ImportError:\n" - << " pass\n" + << "from ." << name << " import " << name << "\n" + << "_filters.append(" << name << ")\n" << "# FILTER_END: " << name << "\n\n"; } content = StringUtilities::replace(content, "#PLUGIN_IMPORT_CODE#", ss.str()); @@ -413,11 +404,8 @@ inline Result<> WritePythonPluginFiles(const std::filesystem::path& outputDirect for(const auto& name : filterList) { ss << "# FILTER_START: " << name << "\n" - << "try:\n" - << " from " << pluginName << "." << name << " import " << name << "\n" - << " __all__.append('" << name << "')\n" - << "except ImportError:\n" - << " pass\n" + << "from ." << name << " import " << name << "\n" + << "__all__.append('" << name << "')\n" << "# FILTER_END: " << name << "\n\n"; } content = StringUtilities::replace(content, "#PLUGIN_IMPORT_CODE#", ss.str()); diff --git a/wrapping/python/plugins/NXDataAnalysisToolkit/src/NXDataAnalysisToolkit/Plugin.py b/wrapping/python/plugins/NXDataAnalysisToolkit/src/NXDataAnalysisToolkit/Plugin.py index 40e2851335..a5e9c3e625 100644 --- a/wrapping/python/plugins/NXDataAnalysisToolkit/src/NXDataAnalysisToolkit/Plugin.py +++ b/wrapping/python/plugins/NXDataAnalysisToolkit/src/NXDataAnalysisToolkit/Plugin.py @@ -13,107 +13,68 @@ _filters = [] # FILTER_START: CalculateHistogramFilter -try: - from NXDataAnalysisToolkit.CalculateHistogramFilter import CalculateHistogramFilter - _filters.append(CalculateHistogramFilter) -except ImportError: - pass +from .CalculateHistogramFilter import CalculateHistogramFilter +_filters.append(CalculateHistogramFilter) # FILTER_END: CalculateHistogramFilter # FILTER_START: InterpolateGridDataFilter -try: - from NXDataAnalysisToolkit.InterpolateGridDataFilter import InterpolateGridDataFilter - _filters.append(InterpolateGridDataFilter) -except ImportError: - pass +from .InterpolateGridDataFilter import InterpolateGridDataFilter +_filters.append(InterpolateGridDataFilter) # FILTER_END: InterpolateGridDataFilter # FILTER_START: CliReaderFilter -try: - from NXDataAnalysisToolkit.CliReaderFilter import CliReaderFilter - _filters.append(CliReaderFilter) -except ImportError: - pass +from .CliReaderFilter import CliReaderFilter +_filters.append(CliReaderFilter) # FILTER_END: CliReaderFilter # FILTER_START: ContourDetectionFilter -try: - from NXDataAnalysisToolkit.ContourDetectionFilter import ContourDetectionFilter - _filters.append(ContourDetectionFilter) -except ImportError: - pass +from .ContourDetectionFilter import ContourDetectionFilter +_filters.append(ContourDetectionFilter) # FILTER_END: ContourDetectionFilter # FILTER_START: NPSortArray -try: - from NXDataAnalysisToolkit.NPSortArray import NPSortArray - _filters.append(NPSortArray) -except ImportError: - pass +from .NPSortArray import NPSortArray +_filters.append(NPSortArray) # FILTER_END: NPSortArray # FILTER_START: ReadPeregrineHDF5File -try: - from NXDataAnalysisToolkit.ReadPeregrineHDF5File import ReadPeregrineHDF5File - _filters.append(ReadPeregrineHDF5File) -except ImportError: - pass +from .ReadPeregrineHDF5File import ReadPeregrineHDF5File +_filters.append(ReadPeregrineHDF5File) # FILTER_END: ReadPeregrineHDF5File # FILTER_START: WriteAbaqusFile -try: - from DataAnalysisToolkit.WriteAbaqusFile import WriteAbaqusFile - _filters.append(WriteAbaqusFile) -except ImportError: - pass +from .WriteAbaqusFile import WriteAbaqusFile +_filters.append(WriteAbaqusFile) # FILTER_END: WriteAbaqusFile # FILTER_START: WriteAnsysFile -try: - from DataAnalysisToolkit.WriteAnsysFile import WriteAnsysFile - _filters.append(WriteAnsysFile) -except ImportError: - pass +from .WriteAnsysFile import WriteAnsysFile +_filters.append(WriteAnsysFile) # FILTER_END: WriteAnsysFile # FILTER_START: WriteMedFile -try: - from DataAnalysisToolkit.WriteMedFile import WriteMedFile - _filters.append(WriteMedFile) -except ImportError: - pass +from .WriteMedFile import WriteMedFile +_filters.append(WriteMedFile) # FILTER_END: WriteMedFile # FILTER_START: WriteGmshFile -try: - from DataAnalysisToolkit.WriteGmshFile import WriteGmshFile - _filters.append(WriteGmshFile) -except ImportError: - pass +from .WriteGmshFile import WriteGmshFile +_filters.append(WriteGmshFile) # FILTER_END: WriteGmshFile # FILTER_START: WriteTetGenFile -try: - from DataAnalysisToolkit.WriteTetGenFile import WriteTetGenFile - _filters.append(WriteTetGenFile) -except ImportError: - pass +from .WriteTetGenFile import WriteTetGenFile +_filters.append(WriteTetGenFile) # FILTER_END: WriteTetGenFile # FILTER_START: WriteVtuFile -try: - from DataAnalysisToolkit.WriteVtuFile import WriteVtuFile - _filters.append(WriteVtuFile) -except ImportError: - pass +from .WriteVtuFile import WriteVtuFile +_filters.append(WriteVtuFile) # FILTER_END: WriteVtuFile # FILTER_START: ReadMeshFile -try: - from DataAnalysisToolkit.ReadMeshFile import ReadMeshFile - _filters.append(ReadMeshFile) -except ImportError: - pass +from .ReadMeshFile import ReadMeshFile +_filters.append(ReadMeshFile) # FILTER_END: ReadMeshFile import simplnx as nx diff --git a/wrapping/python/plugins/NXDataAnalysisToolkit/src/NXDataAnalysisToolkit/__init__.py b/wrapping/python/plugins/NXDataAnalysisToolkit/src/NXDataAnalysisToolkit/__init__.py index e02bde4431..2701ca0fd3 100644 --- a/wrapping/python/plugins/NXDataAnalysisToolkit/src/NXDataAnalysisToolkit/__init__.py +++ b/wrapping/python/plugins/NXDataAnalysisToolkit/src/NXDataAnalysisToolkit/__init__.py @@ -7,107 +7,68 @@ """ # FILTER_START: CalculateHistogramFilter -try: - from .CalculateHistogramFilter import CalculateHistogramFilter - __all__.append('CalculateHistogramFilter') -except ImportError: - pass +from .CalculateHistogramFilter import CalculateHistogramFilter +__all__.append('CalculateHistogramFilter') # FILTER_END: CalculateHistogramFilter # FILTER_START: InterpolateGridDataFilter -try: - from .InterpolateGridDataFilter import InterpolateGridDataFilter - __all__.append('InterpolateGridDataFilter') -except ImportError: - pass +from .InterpolateGridDataFilter import InterpolateGridDataFilter +__all__.append('InterpolateGridDataFilter') # FILTER_END: InterpolateGridDataFilter # FILTER_START: CliReaderFilter -try: - from .CliReaderFilter import CliReaderFilter - __all__.append('CliReaderFilter') -except ImportError: - pass +from .CliReaderFilter import CliReaderFilter +__all__.append('CliReaderFilter') # FILTER_END: CliReaderFilter # FILTER_START: ContourDetectionFilter -try: - from .ContourDetectionFilter import ContourDetectionFilter - __all__.append('ContourDetectionFilter') -except ImportError: - pass +from .ContourDetectionFilter import ContourDetectionFilter +__all__.append('ContourDetectionFilter') # FILTER_END: ContourDetectionFilter # FILTER_START: NPSortArray -try: - from .NPSortArray import NPSortArray - __all__.append('NPSortArray') -except ImportError: - pass +from .NPSortArray import NPSortArray +__all__.append('NPSortArray') # FILTER_END: NPSortArray # FILTER_START: ReadPeregrineHDF5File -try: - from .ReadPeregrineHDF5File import ReadPeregrineHDF5File - __all__.append('ReadPeregrineHDF5File') -except ImportError: - pass +from .ReadPeregrineHDF5File import ReadPeregrineHDF5File +__all__.append('ReadPeregrineHDF5File') # FILTER_END: ReadPeregrineHDF5File # FILTER_START: WriteAbaqusFile -try: - from .WriteAbaqusFile import WriteAbaqusFile - __all__.append('WriteAbaqusFile') -except ImportError: - pass +from .WriteAbaqusFile import WriteAbaqusFile +__all__.append('WriteAbaqusFile') # FILTER_END: WriteAbaqusFile # FILTER_START: WriteAnsysFile -try: - from .WriteAnsysFile import WriteAnsysFile - __all__.append('WriteAnsysFile') -except ImportError: - pass +from .WriteAnsysFile import WriteAnsysFile +__all__.append('WriteAnsysFile') # FILTER_END: WriteAnsysFile # FILTER_START: WriteMedFile -try: - from .WriteMedFile import WriteMedFile - __all__.append('WriteMedFile') -except ImportError: - pass +from .WriteMedFile import WriteMedFile +__all__.append('WriteMedFile') # FILTER_END: WriteMedFile # FILTER_START: WriteGmshFile -try: - from .WriteGmshFile import WriteGmshFile - __all__.append('WriteGmshFile') -except ImportError: - pass +from .WriteGmshFile import WriteGmshFile +__all__.append('WriteGmshFile') # FILTER_END: WriteGmshFile # FILTER_START: WriteTetGenFile -try: - from .WriteTetGenFile import WriteTetGenFile - __all__.append('WriteTetGenFile') -except ImportError: - pass +from .WriteTetGenFile import WriteTetGenFile +__all__.append('WriteTetGenFile') # FILTER_END: WriteTetGenFile # FILTER_START: WriteVtuFile -try: - from .WriteVtuFile import WriteVtuFile - __all__.append('WriteVtuFile') -except ImportError: - pass +from .WriteVtuFile import WriteVtuFile +__all__.append('WriteVtuFile') # FILTER_END: WriteVtuFile # FILTER_START: ReadMeshFile -try: - from .ReadMeshFile import ReadMeshFile - __all__.append('ReadMeshFile') -except ImportError: - pass +from .ReadMeshFile import ReadMeshFile +__all__.append('ReadMeshFile') # FILTER_END: ReadMeshFile def get_plugin():