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

Commit

Permalink
fix it_nand; no ruff dbg on fab cli; fix picker_lib
Browse files Browse the repository at this point in the history
  • Loading branch information
iopapamanoglou committed Nov 6, 2024
1 parent c4517bd commit 7fcd85b
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 7 deletions.
5 changes: 4 additions & 1 deletion examples/iterative_design_nand.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import typer

import faebryk.library._F as F
from faebryk.core.graph import GraphFunctions
from faebryk.core.module import Module
from faebryk.libs.brightness import TypicalLuminousIntensity
from faebryk.libs.examples.buildutil import apply_design_to_pcb
Expand Down Expand Up @@ -119,7 +120,9 @@ def App():
app.add(c)

# parametrizing
for _, t in app.get_graph().nodes_with_trait(F.ElectricLogic.has_pulls):
for _, t in GraphFunctions(app.get_graph()).nodes_with_trait(
F.ElectricLogic.has_pulls
):
for pull_resistor in (r for r in t.get_pulls() if r):
pull_resistor.resistance.merge(F.Range.from_center_rel(100 * P.kohm, 0.05))
power_source.power.voltage.merge(3 * P.V)
Expand Down
10 changes: 9 additions & 1 deletion src/faebryk/core/moduleinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
)
from faebryk.core.node import CNode, Node
from faebryk.core.trait import Trait
from faebryk.library.can_specialize import can_specialize
from faebryk.libs.util import cast_assert, once

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -355,7 +356,14 @@ def is_connected_to(self, other: "ModuleInterface"):
def specialize[T: ModuleInterface](self, special: T) -> T:
logger.debug(f"Specializing MIF {self} with {special}")

assert isinstance(special, type(self))
extra = set()
# allow non-base specialization if explicitly allowed
if special.has_trait(can_specialize):
extra = set(special.get_trait(can_specialize).get_specializable_types())

assert isinstance(special, type(self)) or any(
issubclass(t, type(self)) for t in extra
)

# This is doing the heavy lifting
self.connect(special)
Expand Down
2 changes: 1 addition & 1 deletion src/faebryk/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def __preinit__(self, *args, **kwargs) -> None: ...
def __postinit__(self, *args, **kwargs) -> None: ...

def __post_init__(self, *args, **kwargs):
if not self._is_setup:
if not getattr(self, "_is_setup", False):
raise Exception(
"Node constructor hasn't been called."
"Did you forget to call super().__init__()?"
Expand Down
2 changes: 2 additions & 0 deletions src/faebryk/library/ElectricLogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class PushPull(Enum):
def pulled(self):
return ElectricLogic.can_be_pulled_defined(self.signal, self.reference)

specializable_types = L.f_field(F.can_specialize_defined)([F.Logic])

# ----------------------------------------
# functions
# ----------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/faebryk/library/_F.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from faebryk.library.is_esphome_bus import is_esphome_bus
from faebryk.library.has_construction_dependency import has_construction_dependency
from faebryk.library.has_single_electric_reference import has_single_electric_reference
from faebryk.library.can_specialize_defined import can_specialize_defined
from faebryk.library.Power import Power
from faebryk.library.Signal import Signal
from faebryk.library.has_footprint import has_footprint
Expand All @@ -33,6 +34,7 @@
from faebryk.library.has_linked_pad import has_linked_pad
from faebryk.library.has_reference import has_reference
from faebryk.library.can_bridge import can_bridge
from faebryk.library.can_specialize import can_specialize
from faebryk.library.has_descriptive_properties import has_descriptive_properties
from faebryk.library.has_datasheet import has_datasheet
from faebryk.library.has_designator import has_designator
Expand Down
30 changes: 30 additions & 0 deletions src/faebryk/library/can_specialize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file is part of the faebryk project
# SPDX-License-Identifier: MIT

import logging
from abc import abstractmethod
from typing import TYPE_CHECKING, Iterable

from faebryk.core.trait import Trait

if TYPE_CHECKING:
from faebryk.core.module import Module
from faebryk.core.moduleinterface import ModuleInterface

logger = logging.getLogger(__name__)


class can_specialize(Trait):
"""
Marks that a module can specialize other modules next to its bases.
"""

@abstractmethod
def get_specializable_types(
self,
) -> Iterable[type["Module"] | type["ModuleInterface"]]:
"""
Returns a list of types that can be specialized by this module (in addition to
its own type and the types of its bases).
"""
pass
24 changes: 24 additions & 0 deletions src/faebryk/library/can_specialize_defined.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file is part of the faebryk project
# SPDX-License-Identifier: MIT

import logging
from typing import Iterable, Sequence

from faebryk.core.module import Module
from faebryk.core.moduleinterface import ModuleInterface
from faebryk.library.can_specialize import can_specialize

logger = logging.getLogger(__name__)


class can_specialize_defined(can_specialize.impl()):
def __init__(
self, specializable_types: Sequence[type["Module"] | type["ModuleInterface"]]
):
super().__init__()
self._specializable_types = specializable_types

def get_specializable_types(
self,
) -> Iterable[type["Module"] | type["ModuleInterface"]]:
return self._specializable_types
2 changes: 1 addition & 1 deletion src/faebryk/libs/picker/jlcpcb/picker_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def f(x: str) -> F.Constant:
return f


def enum_to_str[T: Enum](x: Parameter[T], force: bool = True) -> set[str]:
def enum_to_str(x: Parameter, force: bool = True) -> set[str]:
val = x.get_most_narrow()
if isinstance(val, F.Constant):
val = F.Set([val])
Expand Down
4 changes: 1 addition & 3 deletions src/faebryk/libs/pycodegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,4 @@ def format_and_write(code: str, path: Path):
code = black.format_file_contents(code, fast=True, mode=black.FileMode())
path.write_text(code)

print("Ruff----")
subprocess.run(["ruff", "check", "--fix", path], check=True)
print("--------")
subprocess.check_output(["ruff", "check", "--fix", path])

0 comments on commit 7fcd85b

Please sign in to comment.