Skip to content

Commit

Permalink
BUG FIX: Remove Python plugin import error handling. (#1019)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
joeykleingers authored Jul 15, 2024
1 parent ed04c3a commit b9d4744
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit b9d4744

Please sign in to comment.