Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
list_f_field
Browse files Browse the repository at this point in the history
  • Loading branch information
iopapamanoglou committed Sep 12, 2024
1 parent 5c28132 commit f96d5f2
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/minimal_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import typer

import faebryk.library._F as F
import faebryk.libs.library.L as L

Check failure on line 13 in examples/minimal_led.py

View workflow job for this annotation

GitHub Actions / test

Ruff (F401)

examples/minimal_led.py:13:34: F401 `faebryk.libs.library.L` imported but unused
from faebryk.core.module import Module
from faebryk.libs.brightness import TypicalLuminousIntensity
from faebryk.libs.examples.buildutil import apply_design_to_pcb
Expand Down
12 changes: 12 additions & 0 deletions src/faebryk/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ def __() -> T:
return _


def list_f_field[T, **P](n: int, con: Callable[P, T]) -> Callable[P, list[T]]:
assert isinstance(con, type)

def _(*args: P.args, **kwargs: P.kwargs) -> Callable[[], list[T]]:
def __() -> list[T]:
return [con(*args, **kwargs) for _ in range(n)]

return _d_field(__)

return _


class NodeException(FaebrykException):
def __init__(self, node: "Node", *args: object) -> None:
super().__init__(*args)
Expand Down
3 changes: 3 additions & 0 deletions src/faebryk/library/Mounting_Hole.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from faebryk.core.module import Module
from faebryk.libs.iso_metric_screw_thread import Iso262_MetricScrewThreadSizes
from faebryk.libs.library import L
from faebryk.libs.picker.picker import has_part_picked_remove

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -45,3 +46,5 @@ def footprint(self):
pin_names=[],
)
)

no_part: has_part_picked_remove
42 changes: 42 additions & 0 deletions src/faebryk/library/MultiCapacitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file is part of the faebryk project
# SPDX-License-Identifier: MIT

import logging

import faebryk.library._F as F # noqa: F401
from faebryk.libs.library import L # noqa: F401
from faebryk.libs.units import P

Check failure on line 8 in src/faebryk/library/MultiCapacitor.py

View workflow job for this annotation

GitHub Actions / test

Ruff (F401)

src/faebryk/library/MultiCapacitor.py:8:32: F401 `faebryk.libs.units.P` imported but unused
from faebryk.libs.util import times # noqa: F401

logger = logging.getLogger(__name__)


class MultiCapacitor(F.Capacitor):
"""
TODO: Docstring describing your module
"""

# ----------------------------------------
# modules, interfaces, parameters
# ----------------------------------------

# ----------------------------------------
# traits
# ----------------------------------------

def __init__(self, count: int):
self._count = count

@L.rt_field
def capacitors(self) -> list[F.Capacitor]:
return times(self._count, F.Capacitor)

def __preinit__(self):
# ------------------------------------
# connections
# ------------------------------------

# ------------------------------------
# parametrization
# ------------------------------------
pass
1 change: 1 addition & 0 deletions src/faebryk/library/_F.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
from faebryk.library.Mounting_Hole import Mounting_Hole
from faebryk.library.can_be_surge_protected import can_be_surge_protected
from faebryk.library.is_surge_protected import is_surge_protected
from faebryk.library.MultiCapacitor import MultiCapacitor
from faebryk.library.can_be_decoupled import can_be_decoupled
from faebryk.library.is_decoupled import is_decoupled
from faebryk.library.Potentiometer import Potentiometer
Expand Down
1 change: 1 addition & 0 deletions src/faebryk/libs/library/L.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
f_field,
list_field,
rt_field,
list_f_field,
)

logger = logging.getLogger(__name__)

Check failure on line 16 in src/faebryk/libs/library/L.py

View workflow job for this annotation

GitHub Actions / test

Ruff (I001)

src/faebryk/libs/library/L.py:4:1: I001 Import block is un-sorted or un-formatted

0 comments on commit f96d5f2

Please sign in to comment.