Skip to content

Commit

Permalink
REFACTOR!: Remove function handler (#563)
Browse files Browse the repository at this point in the history
* WIP: Remove pyedb function handler

* WIP: Fix pre-commit

* MISC: Auto fixes from pre-commit.com hooks

For more information, see https://pre-commit.ci

* TESTS: Refact material tests

* TESTS: Fix material tests

* FIX: Create package ref

* TESTS: Update create package ref test

* FIX: Add profile to work without layer outline

* MISC: Auto fixes from pre-commit.com hooks

For more information, see https://pre-commit.ci

* REFACTOR: Fix to use component instead of bbox

* MISC: Auto fixes from pre-commit.com hooks

For more information, see https://pre-commit.ci

* WIP: Fix typos

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: svandenb-dev <74993647+svandenb-dev@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 14, 2024
1 parent 8e420bb commit f9ac656
Show file tree
Hide file tree
Showing 59 changed files with 75 additions and 848 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ repos:
- id: debug-statements
- id: trailing-whitespace
files: '(src|doc|tests)/.*'
exclude: 'tests/example_models/*'
exclude: 'tests/example_models'

# # validate GitHub workflow files
# - repo: https://github.com/python-jsonschema/check-jsonschema
Expand Down
20 changes: 0 additions & 20 deletions doc/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,6 @@ These examples show how to write messages only to the log file:
self.logger.info("This is an info message.")
Handle exceptions
~~~~~~~~~~~~~~~~~
PyEDB uses a specific decorator, ``@pyedb_function_handler()``,
to handle exceptions caused by methods and by the AEDT API.
This exception handler decorator makes PyEDB fault tolerant
to errors that can occur in any method.

For example:

.. code:: python
@pyedb_function_handler()
def my_method(self, var):
pass
Every method can return a value of ``True`` when successful or
``False`` when failed. When a failure occurs, the error
handler returns information about the error in both the console and
log file.

Hard-coded values
~~~~~~~~~~~~~~~~~~
Do not write hard-coded values to the registry. Instead, use the Configuration service.
Expand Down
21 changes: 0 additions & 21 deletions doc/source/getting_started/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,6 @@ These examples demonstrate how to write messages only to the log file:
self.logger.warning("This is a warning message.")
self.logger.info("This is an info message.")
Handle exceptions
~~~~~~~~~~~~~~~~~
PyEDB uses a specific decorator, ``@pyedb_function_handler()``,
to handle exceptions caused by methods and by the AEDT API.
This exception handler decorator makes PyEDB fault tolerant
to errors that can occur in any method.

For example:

.. code:: python
@pyedb_function_handler()
def my_method(self, var):
pass
Every method can return a value of ``True`` when successful or
``False`` when failed. When a failure occurs, the error
handler returns information about the error in both the console and
log file.

Hard-coded values
~~~~~~~~~~~~~~~~~~
Do not write hard-coded values to the registry. Instead, use the Configuration service.
Expand Down
5 changes: 0 additions & 5 deletions src/pyedb/configuration/cfg_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@
# SOFTWARE.


from pyedb.generic.general_methods import pyedb_function_handler


class CfgBase:
@property
def protected_attributes(self):
return []

@pyedb_function_handler
def get_attributes(self, exclude=None):
attrs = {i: j for i, j in self.__dict__.items() if i not in self.protected_attributes}
if exclude is not None:
Expand All @@ -39,7 +35,6 @@ def get_attributes(self, exclude=None):
attrs = {i: j for i, j in attrs.items() if j is not None}
return attrs

@pyedb_function_handler
def set_attributes(self, pedb_object):
attrs = self.get_attributes()
for attr, value in attrs.items():
Expand Down
2 changes: 0 additions & 2 deletions src/pyedb/configuration/cfg_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# SOFTWARE.

from pyedb.configuration.cfg_common import CfgBase
from pyedb.generic.general_methods import pyedb_function_handler


class CfgPortProperties(CfgBase):
Expand Down Expand Up @@ -76,7 +75,6 @@ def __init__(self, pedb, data):
self._pedb = pedb
self.components = [CfgComponent(**comp) for comp in data]

@pyedb_function_handler
def apply(self):
comps_in_db = self._pedb.components
for comp in self.components:
Expand Down
2 changes: 0 additions & 2 deletions src/pyedb/configuration/cfg_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# SOFTWARE.

from pyedb.configuration.cfg_common import CfgBase
from pyedb.generic.general_methods import pyedb_function_handler


class CfgCutout(CfgBase):
Expand Down Expand Up @@ -56,7 +55,6 @@ def __init__(self, pedb, data):
self._pedb = pedb
self.op_cutout = CfgCutout(**data["cutout"]) if "cutout" in data else None

@pyedb_function_handler
def apply(self):
"""Imports operation information from JSON."""
if self.op_cutout:
Expand Down
2 changes: 0 additions & 2 deletions src/pyedb/configuration/cfg_package_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

from pyedb.configuration.cfg_common import CfgBase
from pyedb.dotnet.edb_core.definition.package_def import PackageDef
from pyedb.generic.general_methods import pyedb_function_handler


class CfgPackage(CfgBase):
Expand Down Expand Up @@ -104,7 +103,6 @@ def apply(self):
for _, i in comp_list.items():
i.package_def = pkg.name

@pyedb_function_handler
def get_data_from_db(self):
package_definitions = []

Expand Down
10 changes: 0 additions & 10 deletions src/pyedb/configuration/cfg_ports_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from pyedb.generic.general_methods import pyedb_function_handler


class CfgCircuitElement:
@property
def pedb(self):
"""Edb."""
return self._pdata._pedb

@pyedb_function_handler
def __init__(self, pdata, **kwargs):
self._pdata = pdata
self._data = kwargs
Expand All @@ -40,7 +37,6 @@ def __init__(self, pdata, **kwargs):
self.pos_term_info = kwargs.get("positive_terminal", None) # {"pin" : "A1"}
self.neg_term_info = kwargs.get("negative_terminal", None)

@pyedb_function_handler
def _create_terminals(self):
"""Create step 1. Collect positive and negative terminals."""
pos_term_info = self.pos_term_info
Expand Down Expand Up @@ -105,7 +101,6 @@ def _create_terminals(self):
j.create_terminal(i) if not j.terminal else j.terminal for i, j in pin_group.items()
][0]

@pyedb_function_handler
def _get_pins(self, terminal_type, terminal_value):
terminal_value = terminal_value if isinstance(terminal_value, list) else [terminal_value]

Expand All @@ -125,7 +120,6 @@ def get_pin_obj(pin_name):
pins.update({f"{self.reference_designator}_{terminal_value[0]}_{i}": j for i, j in temp.items()})
return pins

@pyedb_function_handler
def _create_pin_group(self, pins, is_ref=False):
if is_ref:
pg_name = f"pg_{self.name}_{self.reference_designator}_ref"
Expand All @@ -141,11 +135,9 @@ class CfgPort(CfgCircuitElement):

CFG_PORT_TYPE = {"circuit": [str], "coax": [str]}

@pyedb_function_handler
def __init__(self, pdata, **kwargs):
super().__init__(pdata, **kwargs)

@pyedb_function_handler
def create(self):
"""Create port."""
self._create_terminals()
Expand All @@ -165,13 +157,11 @@ def create(self):
class CfgSources(CfgCircuitElement):
CFG_SOURCE_TYPE = {"current": [int, float], "voltage": [int, float]}

@pyedb_function_handler
def __init__(self, pdata, **kwargs):
super().__init__(pdata, **kwargs)

self.magnitude = kwargs.get("magnitude", 0.001)

@pyedb_function_handler
def create(self):
"""Create sources."""
self._create_terminals()
Expand Down
7 changes: 0 additions & 7 deletions src/pyedb/configuration/cfg_stackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# SOFTWARE.

from pyedb.configuration.cfg_common import CfgBase
from pyedb.generic.general_methods import pyedb_function_handler


class CfgMaterial(CfgBase):
Expand Down Expand Up @@ -54,7 +53,6 @@ def __init__(self, pedb, data):
self.materials = [CfgMaterial(**mat) for mat in data.get("materials", [])]
self.layers = [CfgLayer(**lay) for lay in data.get("layers", [])]

@pyedb_function_handler
def apply(self):
"""Apply configuration settings to the current design"""
if len(self.materials):
Expand All @@ -77,7 +75,6 @@ def __create_stackup(self):
attrs = l_attrs.get_attributes()
self._pedb.stackup.add_layer_bottom(**attrs)

@pyedb_function_handler
def __apply_layers(self):
"""Apply layer settings to the current design"""
layers = list()
Expand Down Expand Up @@ -120,7 +117,6 @@ def __apply_layers(self):
elif l.type == "signal":
prev_layer_clone = self._pedb.stackup.layers[l.name]

@pyedb_function_handler
def __apply_materials(self):
"""Apply material settings to the current design"""
materials_in_db = {i.lower(): i for i, _ in self._pedb.materials.materials.items()}
Expand All @@ -131,7 +127,6 @@ def __apply_materials(self):
attrs = mat_in_cfg.get_attributes()
mat = self._pedb.materials.add_material(**attrs)

@pyedb_function_handler
def __get_materials_from_db(self):
materials = []
for name, p in self._pedb.materials.materials.items():
Expand All @@ -141,7 +136,6 @@ def __get_materials_from_db(self):
materials.append(mat)
return materials

@pyedb_function_handler
def __get_layers_from_db(self):
layers = []
for name, obj in self._pedb.stackup.all_layers.items():
Expand All @@ -153,7 +147,6 @@ def __get_layers_from_db(self):
layers.append(layer)
return layers

@pyedb_function_handler
def get_data_from_db(self):
"""Get configuration data from layout.
Expand Down
6 changes: 0 additions & 6 deletions src/pyedb/configuration/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

from pyedb.configuration.cfg_data import CfgData
from pyedb.dotnet.edb_core.definition.package_def import PackageDef
from pyedb.generic.general_methods import pyedb_function_handler


class Configuration:
Expand All @@ -42,7 +41,6 @@ def __init__(self, pedb):
self._spice_model_library = ""
self.cfg_data = CfgData(self._pedb)

@pyedb_function_handler
def load(self, config_file, append=True, apply_file=False, output_file=None, open_at_the_end=True):
"""Import configuration settings from a configure file.
Expand Down Expand Up @@ -103,7 +101,6 @@ def load(self, config_file, append=True, apply_file=False, output_file=None, ope
self._pedb.open_edb()
return self.cfg_data

@pyedb_function_handler()
def run(self):
"""Apply configuration settings to the current design"""

Expand Down Expand Up @@ -157,7 +154,6 @@ def run(self):

return True

@pyedb_function_handler
def _load_stackup(self):
"""Imports stackup information from json."""
data = self.data["stackup"]
Expand Down Expand Up @@ -214,7 +210,6 @@ def _load_stackup(self):
elif l["type"] == "signal":
prev_layer_clone = self._pedb.stackup.layers[l["name"]]

@pyedb_function_handler
def _load_package_def(self):
"""Imports package definition information from JSON."""
comps = self._pedb.components.components
Expand Down Expand Up @@ -277,7 +272,6 @@ def get_data_from_db(self, **kwargs):

return data

@pyedb_function_handler
def export(self, file_path, stackup=True, package_definitions=True):
"""Export the configuration data from layout to a file.
Expand Down
Loading

0 comments on commit f9ac656

Please sign in to comment.