Skip to content

Commit ff960ed

Browse files
authored
Exception handler refactoring (#909)
* created new pyaedt_function_handler * replaced @aedt_exception_handler with @pyaedt_function_handler() * black check * - added @pyaedt_function_handler() to primitives methods. - fixed test_81_edb_with_dxf * - added @pyaedt_function_handler() to DataHandlers.py methods * code clean up
1 parent f027709 commit ff960ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1498
-1454
lines changed

_unittest/test_00_EDB.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ def test_80_create_rectangle_in_pad(self):
709709
edb_padstacks.close_edb()
710710

711711
def test_81_edb_with_dxf(self):
712-
edb3 = Edb(os.path.join(local_path, "example_models", "edb_test_82.dxf"), edbversion=desktop_version)
712+
dxf_file = self.local_scratch.copyfile(os.path.join(local_path, "example_models", "edb_test_82.dxf"))
713+
edb3 = Edb(dxf_file, edbversion=desktop_version)
713714
edb3.close_edb()
714715
del edb3

doc/source/Resources/Code_Guidelines.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,14 +755,14 @@ These examples demonstrate how to to write messages only to the log file:
755755
Exception Handling
756756
~~~~~~~~~~~~~~~~~~
757757
PyAEDT uses a specific decorator,
758-
``@aedt_exception_handler``, to handle exceptions caused by
758+
``@pyaedt_function_handler``, to handle exceptions caused by
759759
methods and by the AEDT API. This exception handler decorator
760760
makes PyAEDT fault tolerant to errors that can occur in any method.
761761
For example:
762762

763763
.. code:: python
764764
765-
@aedt_exception_handler
765+
@pyaedt_function_handler()
766766
def my_method(self, var):
767767
pass
768768

pyaedt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from pyaedt.generic.general_methods import settings
1313
from pyaedt.generic import constants
14-
from pyaedt.generic.general_methods import aedt_exception_handler, generate_unique_name, _retry_ntimes
14+
from pyaedt.generic.general_methods import pyaedt_function_handler, generate_unique_name, _retry_ntimes
1515
from pyaedt.generic.general_methods import is_ironpython, _pythonver, inside_desktop, convert_remote_object
1616
from pyaedt.aedt_logger import AedtLogger
1717

pyaedt/application/AEDT_File_Management.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import re
44
import shutil
55

6-
from pyaedt.generic.general_methods import aedt_exception_handler
6+
from pyaedt.generic.general_methods import pyaedt_function_handler
77

88

9-
@aedt_exception_handler
9+
@pyaedt_function_handler()
1010
def read_info_fromcsv(projdir, name):
1111
"""Read information from a CSV file and return a list.
1212
@@ -32,7 +32,7 @@ def read_info_fromcsv(projdir, name):
3232
return listmcad
3333

3434

35-
@aedt_exception_handler
35+
@pyaedt_function_handler()
3636
def clean_proj_folder(dir, name):
3737
"""Delete all project name-related folders.
3838
@@ -54,7 +54,7 @@ def clean_proj_folder(dir, name):
5454
return True
5555

5656

57-
@aedt_exception_handler
57+
@pyaedt_function_handler()
5858
def create_output_folder(ProjectDir):
5959
"""Create the output folders starting from the project directory.
6060
@@ -88,7 +88,7 @@ def create_output_folder(ProjectDir):
8888
return PicturePath, ResultsPath
8989

9090

91-
@aedt_exception_handler
91+
@pyaedt_function_handler()
9292
def change_objects_visibility(origfile, solid_list):
9393
"""Edit the project file to make only the solids that are specified visible.
9494
@@ -134,7 +134,7 @@ def change_objects_visibility(origfile, solid_list):
134134
print("change_objects_visibility: Project %s is still locked." % origfile)
135135

136136

137-
@aedt_exception_handler
137+
@pyaedt_function_handler()
138138
def change_model_orientation(origfile, bottom_dir):
139139
"""Edit the project file to change the model orientation.
140140

pyaedt/application/Analysis.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import warnings
1313
from collections import OrderedDict
1414

15-
from pyaedt.generic.general_methods import aedt_exception_handler, generate_unique_name, filter_tuple
15+
from pyaedt.generic.general_methods import pyaedt_function_handler, generate_unique_name, filter_tuple
1616
from pyaedt.generic.constants import (
1717
AXIS,
1818
PLANE,
@@ -505,7 +505,7 @@ def excitations(self):
505505
except:
506506
return []
507507

508-
@aedt_exception_handler
508+
@pyaedt_function_handler()
509509
def get_excitations_name(self):
510510
"""Get all excitation names.
511511
@@ -526,7 +526,7 @@ def get_excitations_name(self):
526526
warnings.warn("`get_excitations_name` is deprecated. Use `excitations` property instead.", DeprecationWarning)
527527
return self.excitations
528528

529-
@aedt_exception_handler
529+
@pyaedt_function_handler()
530530
def get_traces_for_plot(
531531
self,
532532
get_self_terms=True,
@@ -585,7 +585,7 @@ def get_traces_for_plot(
585585
list_output.append(value)
586586
return list_output
587587

588-
@aedt_exception_handler
588+
@pyaedt_function_handler()
589589
def analyze_all(self):
590590
"""Analyze all setups in a design.
591591
@@ -597,7 +597,7 @@ def analyze_all(self):
597597
self.odesign.AnalyzeAll()
598598
return True
599599

600-
@aedt_exception_handler
600+
@pyaedt_function_handler()
601601
def list_of_variations(self, setup_name=None, sweep_name=None):
602602
"""Retrieve a list of active variations for input setup.
603603
@@ -642,7 +642,7 @@ def list_of_variations(self, setup_name=None, sweep_name=None):
642642
except:
643643
return [""]
644644

645-
@aedt_exception_handler
645+
@pyaedt_function_handler()
646646
def export_results(self, analyze=False, export_folder=None):
647647
"""Export all available reports to a file, including sNp, profile, and convergence.
648648
@@ -775,7 +775,7 @@ def export_results(self, analyze=False, export_folder=None):
775775
self.logger.warning("Export SnP failed: no solutions found")
776776
return exported_files
777777

778-
@aedt_exception_handler
778+
@pyaedt_function_handler()
779779
def export_convergence(self, setup_name, variation_string="", file_path=None):
780780
"""Export a solution convergence to a file.
781781
@@ -806,7 +806,7 @@ def export_convergence(self, setup_name, variation_string="", file_path=None):
806806
self.logger.info("Export Convergence to %s", file_path)
807807
return file_path
808808

809-
@aedt_exception_handler
809+
@pyaedt_function_handler()
810810
def _get_native_data(self):
811811
"""Retrieve Native Components data."""
812812
boundaries = []
@@ -868,7 +868,7 @@ def variables(self):
868868
"""
869869
return [i for i in self._app.variable_manager.independent_variables]
870870

871-
@aedt_exception_handler
871+
@pyaedt_function_handler()
872872
def variations(self, setup_sweep=None):
873873
"""Variations.
874874
@@ -904,7 +904,7 @@ def variations(self, setup_sweep=None):
904904
families.append(family)
905905
return families
906906

907-
@aedt_exception_handler
907+
@pyaedt_function_handler()
908908
def get_variation_strings(self, setup_sweep=None):
909909
"""Return variation strings.
910910
@@ -1002,7 +1002,7 @@ class AxisDir(object):
10021002

10031003
(XNeg, YNeg, ZNeg, XPos, YPos, ZPos) = range(0, 6)
10041004

1005-
@aedt_exception_handler
1005+
@pyaedt_function_handler()
10061006
def get_setups(self):
10071007
"""Retrieve setups.
10081008
@@ -1019,7 +1019,7 @@ def get_setups(self):
10191019
setups = self.oanalysis.GetSetups()
10201020
return list(setups)
10211021

1022-
@aedt_exception_handler
1022+
@pyaedt_function_handler()
10231023
def get_nominal_variation(self):
10241024
"""Retrieve the nominal variation.
10251025
@@ -1030,7 +1030,7 @@ def get_nominal_variation(self):
10301030
"""
10311031
return self.available_variations.nominal
10321032

1033-
@aedt_exception_handler
1033+
@pyaedt_function_handler()
10341034
def get_sweeps(self, name):
10351035
"""Retrieve all sweeps for a setup.
10361036
@@ -1052,7 +1052,7 @@ def get_sweeps(self, name):
10521052
sweeps = self.oanalysis.GetSweeps(name)
10531053
return list(sweeps)
10541054

1055-
@aedt_exception_handler
1055+
@pyaedt_function_handler()
10561056
def export_parametric_results(self, sweepname, filename, exportunits=True):
10571057
"""Export a list of all parametric variations solved for a sweep to a CSV file.
10581058
@@ -1080,7 +1080,7 @@ def export_parametric_results(self, sweepname, filename, exportunits=True):
10801080
self.ooptimetrics.ExportParametricResults(sweepname, filename, exportunits)
10811081
return True
10821082

1083-
@aedt_exception_handler
1083+
@pyaedt_function_handler()
10841084
def analyze_from_initial_mesh(self):
10851085
"""Revert the solution to the initial mesh and re-run the solve.
10861086
@@ -1099,7 +1099,7 @@ def analyze_from_initial_mesh(self):
10991099
self.analyze_nominal()
11001100
return True
11011101

1102-
@aedt_exception_handler
1102+
@pyaedt_function_handler()
11031103
def analyse_nominal(self):
11041104
"""Solve the nominal design.
11051105
@@ -1109,7 +1109,7 @@ def analyse_nominal(self):
11091109
warnings.warn("`analyse_nominal` is deprecated. Use `analyze_nominal` instead.", DeprecationWarning)
11101110
self.analyze_nominal()
11111111

1112-
@aedt_exception_handler
1112+
@pyaedt_function_handler()
11131113
def analyze_nominal(self, num_cores=None, num_tasks=None, num_gpu=None, acf_file=None):
11141114
"""Solve the nominal design.
11151115
@@ -1137,7 +1137,7 @@ def analyze_nominal(self, num_cores=None, num_tasks=None, num_gpu=None, acf_file
11371137

11381138
return self.analyze_setup(self.analysis_setup, num_cores, num_tasks, num_gpu, acf_file)
11391139

1140-
@aedt_exception_handler
1140+
@pyaedt_function_handler()
11411141
def generate_unique_setup_name(self, setup_name=None):
11421142
"""Generate a new setup with an unique name.
11431143
@@ -1160,7 +1160,7 @@ def generate_unique_setup_name(self, setup_name=None):
11601160
index += 1
11611161
return setup_name
11621162

1163-
@aedt_exception_handler
1163+
@pyaedt_function_handler()
11641164
def create_setup(self, setupname="MySetupAuto", setuptype=None, props={}):
11651165
"""Create a setup.
11661166
@@ -1229,7 +1229,7 @@ def create_setup(self, setupname="MySetupAuto", setuptype=None, props={}):
12291229
self.setups.append(setup)
12301230
return setup
12311231

1232-
@aedt_exception_handler
1232+
@pyaedt_function_handler()
12331233
def delete_setup(self, setupname):
12341234
"""Delete a setup.
12351235
@@ -1267,7 +1267,7 @@ def delete_setup(self, setupname):
12671267
return True
12681268
return False
12691269

1270-
@aedt_exception_handler
1270+
@pyaedt_function_handler()
12711271
def edit_setup(self, setupname, properties_dict):
12721272
"""Modify a setup.
12731273
@@ -1294,7 +1294,7 @@ def edit_setup(self, setupname, properties_dict):
12941294
self.analysis_setup = setupname
12951295
return setup
12961296

1297-
@aedt_exception_handler
1297+
@pyaedt_function_handler()
12981298
def get_setup(self, setupname):
12991299
"""Get the setup from the current design.
13001300
@@ -1315,7 +1315,7 @@ def get_setup(self, setupname):
13151315
self.analysis_setup = setupname
13161316
return setup
13171317

1318-
@aedt_exception_handler
1318+
@pyaedt_function_handler()
13191319
def create_output_variable(self, variable, expression):
13201320
"""Create or modify an output variable.
13211321
@@ -1346,7 +1346,7 @@ def create_output_variable(self, variable, expression):
13461346
oModule.CreateOutputVariable(variable, expression, self.existing_analysis_sweeps[0], self.solution_type, [])
13471347
return True
13481348

1349-
@aedt_exception_handler
1349+
@pyaedt_function_handler()
13501350
def get_output_variable(self, variable):
13511351
"""Retrieve the value of the output variable.
13521352
@@ -1375,7 +1375,7 @@ def get_output_variable(self, variable):
13751375

13761376
return value
13771377

1378-
@aedt_exception_handler
1378+
@pyaedt_function_handler()
13791379
def get_object_material_properties(self, object_list=None, prop_names=None):
13801380
"""Retrieve the material properties for a list of objects and return them in a dictionary.
13811381
@@ -1417,7 +1417,7 @@ def get_object_material_properties(self, object_list=None, prop_names=None):
14171417
dict[entry][prop_name] = mat_props._props[prop_name]
14181418
return dict
14191419

1420-
@aedt_exception_handler
1420+
@pyaedt_function_handler()
14211421
def analyze_setup(self, name, num_cores=None, num_tasks=None, num_gpu=None, acf_file=None):
14221422
"""Analyze a design setup.
14231423
@@ -1506,7 +1506,7 @@ def analyze_setup(self, name, num_cores=None, num_tasks=None, num_gpu=None, acf_
15061506
self.logger.info("Design setup %s solved correctly", name)
15071507
return True
15081508

1509-
@aedt_exception_handler
1509+
@pyaedt_function_handler()
15101510
def solve_in_batch(self, filename=None, machine="local", run_in_thread=False):
15111511
"""Analyze a design setup in batch mode.
15121512
@@ -1568,7 +1568,7 @@ def thread_run():
15681568
self.logger.info("Batch job finished.")
15691569
return True
15701570

1571-
@aedt_exception_handler
1571+
@pyaedt_function_handler()
15721572
def submit_job(
15731573
self, clustername, aedt_full_exe_path=None, numnodes=1, numcores=32, wait_for_license=True, setting_file=None
15741574
):

pyaedt/application/Analysis2D.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pyaedt.application.Analysis import Analysis
44
from pyaedt.modeler.Model2D import Modeler2D
55
from pyaedt.modules.Mesh import Mesh
6-
from pyaedt.generic.general_methods import aedt_exception_handler, is_ironpython
6+
from pyaedt.generic.general_methods import pyaedt_function_handler, is_ironpython
77

88
if is_ironpython:
99
from pyaedt.modules.PostProcessor import PostProcessor
@@ -131,7 +131,7 @@ def mesh(self):
131131
"""
132132
return self._mesh
133133

134-
@aedt_exception_handler
134+
@pyaedt_function_handler()
135135
def plot(
136136
self,
137137
objects=None,
@@ -187,7 +187,7 @@ def plot(
187187
clean_files=clean_files,
188188
)
189189

190-
@aedt_exception_handler
190+
@pyaedt_function_handler()
191191
def export_mesh_stats(self, setup_name, variation_string="", mesh_path=None):
192192
"""Export mesh statistics to a file.
193193
@@ -216,7 +216,7 @@ def export_mesh_stats(self, setup_name, variation_string="", mesh_path=None):
216216
self.odesign.ExportMeshStats(setup_name, variation_string, mesh_path)
217217
return mesh_path
218218

219-
@aedt_exception_handler
219+
@pyaedt_function_handler()
220220
def assign_material(self, obj, mat):
221221
"""Assign a material to one or more objects.
222222

0 commit comments

Comments
 (0)