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

Commit

Permalink
move around util import
Browse files Browse the repository at this point in the history
  • Loading branch information
iopapamanoglou committed Aug 27, 2024
1 parent c66b86c commit c89546e
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 43 deletions.
2 changes: 2 additions & 0 deletions src/faebryk/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,5 @@ def get_trait[V: "Trait"](self, trait: Type[V]) -> V:
raise TraitNotFound(self, trait)

return cast_assert(trait, impl)

# Graph stuff ----------------------------------------------------------------------
6 changes: 4 additions & 2 deletions src/faebryk/exporters/esphome/esphome.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import yaml

from faebryk.core.graphinterface import Graph, Parameter
from faebryk.core.util import get_all_nodes_with_trait
from faebryk.core.graphinterface import Graph
from faebryk.core.parameter import Parameter
from faebryk.library.Constant import Constant
from faebryk.library.has_esphome_config import has_esphome_config

Expand Down Expand Up @@ -54,6 +54,8 @@ def merge_dicts(*dicts: dict) -> dict:


def make_esphome_config(G: Graph) -> dict:
from faebryk.core.util import get_all_nodes_with_trait

esphome_components = get_all_nodes_with_trait(G, has_esphome_config)

esphome_config = merge_dicts(*[t.get_config() for _, t in esphome_components])
Expand Down
8 changes: 3 additions & 5 deletions src/faebryk/exporters/netlist/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@

from faebryk.core.graphinterface import Graph
from faebryk.core.module import Module
from faebryk.core.util import (
get_all_nodes_with_trait,
get_children,
get_connected_mifs,
)
from faebryk.exporters.netlist.netlist import T2Netlist
from faebryk.library.Electrical import Electrical
from faebryk.library.Footprint import Footprint
Expand Down Expand Up @@ -112,6 +107,8 @@ def get_kicad_obj(self):


def add_or_get_net(interface: Electrical):
from faebryk.core.util import get_connected_mifs

mifs = get_connected_mifs(interface.connected)
nets = {
p[0]
Expand All @@ -128,6 +125,7 @@ def add_or_get_net(interface: Electrical):


def attach_nets_and_kicad_info(g: Graph):
from faebryk.core.util import get_all_nodes_with_trait, get_children
# g has to be closed

Gclosed = g
Expand Down
2 changes: 1 addition & 1 deletion src/faebryk/exporters/netlist/netlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from dataclasses import dataclass

from faebryk.core.graphinterface import Graph
from faebryk.core.util import get_all_nodes_of_type, get_all_nodes_with_trait
from faebryk.library.has_footprint import has_footprint
from faebryk.library.has_overriden_name import has_overriden_name

Expand Down Expand Up @@ -38,6 +37,7 @@ class Vertex:


def make_t2_netlist_from_graph(G: Graph) -> T2Netlist:
from faebryk.core.util import get_all_nodes_of_type, get_all_nodes_with_trait
from faebryk.exporters.netlist.graph import can_represent_kicad_footprint
from faebryk.library.Net import Net as FNet

Expand Down
2 changes: 1 addition & 1 deletion src/faebryk/exporters/parameters/parameters_to_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

from faebryk.core.module import Module
from faebryk.core.parameter import Parameter
from faebryk.core.util import get_all_modules, get_children

logger = logging.getLogger(__name__)


def export_parameters_to_file(module: Module, path: Path):
"""Write all parameters of the given module to a file."""
from faebryk.core.util import get_all_modules, get_children

# {module_name: [{param_name: param_value}, {param_name: param_value},...]}
parameters = dict[str, list[dict[str, Parameter]]]()
Expand Down
8 changes: 3 additions & 5 deletions src/faebryk/exporters/pcb/kicad/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
from faebryk.core.module import Module
from faebryk.core.moduleinterface import ModuleInterface
from faebryk.core.node import Node
from faebryk.core.util import (
get_all_nodes_with_trait,
get_all_nodes_with_traits,
get_children,
)
from faebryk.libs.geometry.basic import Geometry
from faebryk.libs.kicad.fileformats import (
UUID,
Expand Down Expand Up @@ -230,6 +225,7 @@ def attach(self):
footprints = {
(f.propertys["Reference"].value, f.name): f for f in self.pcb.footprints
}
from faebryk.core.util import get_all_nodes_with_trait, get_children

for node, fpt in get_all_nodes_with_trait(self.graph, F.has_footprint):
if not node.has_trait(F.has_overriden_name):
Expand Down Expand Up @@ -701,6 +697,8 @@ def insert_zone(self, net: Net, layers: str | list[str], polygon: list[Point2D])

# Positioning ----------------------------------------------------------------------
def move_footprints(self):
from faebryk.core.util import get_all_nodes_with_traits

# position modules with defined positions
pos_mods = get_all_nodes_with_traits(
self.graph, (F.has_pcb_position, self.has_linked_kicad_footprint)
Expand Down
2 changes: 1 addition & 1 deletion src/faebryk/exporters/pcb/layout/typehierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from faebryk.core.module import Module
from faebryk.core.node import Node
from faebryk.core.util import get_node_direct_children
from faebryk.exporters.pcb.layout.layout import Layout
from faebryk.libs.util import NotNone, find_or, flatten, groupby

Expand All @@ -27,6 +26,7 @@ def apply(self, *node: Node):
"""
Tip: Make sure at least one parent of node has an absolute position defined
"""
from faebryk.core.util import get_node_direct_children

# Find the layout for each node and group by matched level
levels = groupby(
Expand Down
7 changes: 3 additions & 4 deletions src/faebryk/exporters/pcb/routing/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

import networkx as nx

from faebryk.core.util import (
get_all_nodes_of_type,
get_net,
)
from faebryk.exporters.pcb.kicad.transformer import PCB_Transformer
from faebryk.exporters.pcb.routing.grid import (
Coord,
Expand Down Expand Up @@ -129,6 +125,7 @@ def draw_circle(self, coord: OutCoord, size=0.5, layer="User.9"):
)

def route_all(self):
from faebryk.core.util import get_all_nodes_of_type
from faebryk.library.Net import Net as FNet

nets = get_all_nodes_of_type(self.transformer.graph, FNet)
Expand Down Expand Up @@ -239,6 +236,8 @@ def route_net(self, net: Net):
)

def route_if_net(self, mif):
from faebryk.core.util import get_net

net = get_net(mif)
assert net is not None
self.route_net(net)
Expand Down
23 changes: 14 additions & 9 deletions src/faebryk/exporters/pcb/routing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@

import logging
from dataclasses import dataclass
from typing import Iterable, Sequence
from typing import TYPE_CHECKING, Iterable, Sequence

from faebryk.core.module import Module
from faebryk.core.moduleinterface import ModuleInterface
from faebryk.core.node import Node
from faebryk.core.util import (
get_all_nodes,
get_connected_mifs,
get_net,
get_parent_of_type,
)
from faebryk.exporters.pcb.kicad.transformer import PCB_Transformer
from faebryk.library.Electrical import Electrical
from faebryk.library.Net import Net
from faebryk.library.Pad import Pad
from faebryk.libs.geometry.basic import Geometry

if TYPE_CHECKING:
from faebryk.exporters.pcb.kicad.transformer import PCB_Transformer

# logging settings
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -119,7 +115,7 @@ def net(self):
return net


def apply_route_in_pcb(route: Route, transformer: PCB_Transformer):
def apply_route_in_pcb(route: Route, transformer: "PCB_Transformer"):
pcb_net = transformer.get_net(route.net)

logger.debug(f"Insert tracks for net {pcb_net.name}, {pcb_net.number}, {route}")
Expand Down Expand Up @@ -180,6 +176,11 @@ def get_internal_nets_of_node(
For Nets returns all connected mifs
"""

from faebryk.core.util import (
get_all_nodes,
get_connected_mifs,
get_net,
)
from faebryk.libs.util import groupby

if isinstance(node, Net):
Expand All @@ -192,6 +193,8 @@ def get_internal_nets_of_node(


def get_pads_pos_of_mifs(mifs: Sequence[Electrical]):
from faebryk.exporters.pcb.kicad.transformer import PCB_Transformer

return {
pad_pos[0]: pad_pos[1]
for mif in mifs
Expand All @@ -215,6 +218,8 @@ def group_pads_that_are_connected_already(


def get_routes_of_pad(pad: Pad):
from faebryk.core.util import get_parent_of_type

return {
route
for mif in pad.pcb.get_direct_connections()
Expand Down
13 changes: 10 additions & 3 deletions src/faebryk/library/Mounting_Hole.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ def __preinit__(self):
# Only 3.2mm supported for now
self.diameter.merge(F.Constant(3.2 * P.mm))

footprint = L.f_field(F.has_footprint_defined)(
F.KicadFootprint("MountingHole:MountingHole_3.2mm_M3_Pad", pin_names=[])
)
# footprint = L.f_field(F.has_footprint_defined)(
# F.KicadFootprint("MountingHole:MountingHole_3.2mm_M3_Pad", pin_names=[])
# )

# TODO make back to f_field, rt_field because of imports
@L.rt_field
def footprint(self):
return F.has_footprint_defined(
F.KicadFootprint("MountingHole:MountingHole_3.2mm_M3_Pad", pin_names=[])
)
12 changes: 6 additions & 6 deletions src/faebryk/library/_F.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
# flake8: noqa: E501

from faebryk.library.has_pcb_position import has_pcb_position
from faebryk.library.Constant import Constant
from faebryk.library.Operation import Operation
from faebryk.library.TBD import TBD
from faebryk.library.Range import Range
from faebryk.library.TBD import TBD
from faebryk.library.Constant import Constant
from faebryk.library.has_overriden_name import has_overriden_name
from faebryk.library.has_capacitance import has_capacitance
from faebryk.library.has_footprint import has_footprint
Expand All @@ -46,9 +46,9 @@
from faebryk.library.has_pcb_position_defined_relative import has_pcb_position_defined_relative
from faebryk.library.has_pcb_position_defined import has_pcb_position_defined
from faebryk.library.has_pcb_position_defined_relative_to_parent import has_pcb_position_defined_relative_to_parent
from faebryk.library.Logic import Logic
from faebryk.library.Electrical import Electrical
from faebryk.library.ANY import ANY
from faebryk.library.Logic import Logic
from faebryk.library.Set import Set
from faebryk.library.has_overriden_name_defined import has_overriden_name_defined
from faebryk.library.has_defined_capacitance import has_defined_capacitance
Expand All @@ -73,10 +73,10 @@
from faebryk.library.has_footprint_requirement_defined import has_footprint_requirement_defined
from faebryk.library.has_multi_picker import has_multi_picker
from faebryk.library.is_representable_by_single_value_defined import is_representable_by_single_value_defined
from faebryk.library.LogicOps import LogicOps
from faebryk.library.has_pin_association_heuristic import has_pin_association_heuristic
from faebryk.library.SPI import SPI
from faebryk.library.DifferentialPair import DifferentialPair
from faebryk.library.LogicOps import LogicOps
from faebryk.library.has_footprint_impl import has_footprint_impl
from faebryk.library.can_attach_to_footprint import can_attach_to_footprint
from faebryk.library.has_kicad_footprint import has_kicad_footprint
Expand All @@ -90,19 +90,19 @@
from faebryk.library.Pad import Pad
from faebryk.library.GDT import GDT
from faebryk.library.Button import Button
from faebryk.library.LogicGate import LogicGate
from faebryk.library.has_pin_association_heuristic_lookup_table import has_pin_association_heuristic_lookup_table
from faebryk.library.RS485 import RS485
from faebryk.library.Ethernet import Ethernet
from faebryk.library.LogicGate import LogicGate
from faebryk.library.has_footprint_defined import has_footprint_defined
from faebryk.library.Net import Net
from faebryk.library.has_equal_pins import has_equal_pins
from faebryk.library.has_kicad_manual_footprint import has_kicad_manual_footprint
from faebryk.library.can_attach_via_pinmap_pinlist import can_attach_via_pinmap_pinlist
from faebryk.library.LogicGates import LogicGates
from faebryk.library.MOSFET import MOSFET
from faebryk.library.Diode import Diode
from faebryk.library.BJT import BJT
from faebryk.library.LogicGates import LogicGates
from faebryk.library.can_attach_to_footprint_via_pinmap import can_attach_to_footprint_via_pinmap
from faebryk.library.can_attach_to_footprint_symmetrically import can_attach_to_footprint_symmetrically
from faebryk.library.has_pcb_routing_strategy_via_to_layer import has_pcb_routing_strategy_via_to_layer
Expand Down
3 changes: 2 additions & 1 deletion src/faebryk/libs/app/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from faebryk.core.module import Module
from faebryk.core.parameter import Parameter
from faebryk.core.util import get_all_modules, get_children
from faebryk.library.ANY import ANY
from faebryk.library.TBD import TBD

Expand All @@ -19,6 +18,8 @@ def replace_tbd_with_any(module: Module, recursive: bool, loglvl: int | None = N
:param module: The module to replace TBD instances in.
:param recursive: If True, replace TBD instances in submodules as well.
"""
from faebryk.core.util import get_all_modules, get_children

lvl = logger.getEffectiveLevel()
if loglvl is not None:
logger.setLevel(loglvl)
Expand Down
19 changes: 14 additions & 5 deletions src/faebryk/libs/picker/picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
from faebryk.core.module import Module
from faebryk.core.moduleinterface import ModuleInterface
from faebryk.core.parameter import Parameter
from faebryk.core.util import (
get_all_modules,
get_children,
pretty_params,
)
from faebryk.libs.util import NotNone, flatten

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -92,6 +87,8 @@ def get_all_children(self):

class PickErrorParams(PickError):
def __init__(self, module: Module, options: list[PickerOption]):
from faebryk.core.util import pretty_params

self.options = options

MAX = 5
Expand Down Expand Up @@ -142,6 +139,8 @@ def get_part(self) -> Part:


def pick_module_by_params(module: Module, options: Iterable[PickerOption]):
from faebryk.core.util import get_children

if module.has_trait(has_part_picked):
logger.debug(f"Ignoring already picked module: {module}")
return
Expand Down Expand Up @@ -185,6 +184,8 @@ def pick_module_by_params(module: Module, options: Iterable[PickerOption]):


def _get_mif_top_level_modules(mif: ModuleInterface) -> set[Module]:
from faebryk.core.util import get_children

return get_children(mif, direct_only=True, types=Module) | {
m
for nmif in get_children(mif, direct_only=True, types=ModuleInterface)
Expand All @@ -200,10 +201,14 @@ def __init__(self):
@classmethod
def from_module(cls, module: Module) -> "PickerProgress":
self = cls()
from faebryk.core.util import get_all_modules

self.progress.update(self.task, total=len(get_all_modules(module)))
return self

def advance(self, module: Module):
from faebryk.core.util import get_all_modules

self.progress.advance(self.task, len(get_all_modules(module)))

@contextmanager
Expand All @@ -226,6 +231,8 @@ def pick_part_recursively(module: Module):

# check if lowest children are picked
def get_not_picked(m: Module):
from faebryk.core.util import get_children

ms = m.get_most_special()

# check if parent is picked
Expand Down Expand Up @@ -259,6 +266,8 @@ def get_not_picked(m: Module):


def _pick_part_recursively(module: Module, progress: PickerProgress | None = None):
from faebryk.core.util import get_children

assert isinstance(module, Module)

# pick only for most specialized module
Expand Down

0 comments on commit c89546e

Please sign in to comment.