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

Bugfix: Picker: Attach params on ID or MFR pick #109

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/faebryk/libs/picker/jlcpcb/jlcpcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,17 @@ def attach(
f"Failed to parse parameters for component {self.partno}: {params_str}"
)

for name, value in zip([m.param_name for m in mapping], params):
getattr(module, name).override(value)
# Override module parameters with picked component parameters
# sort by type to avoid merge conflicts
module_params: list[tuple[Parameter, Parameter]] = [
(getattr(module, name), value)
for name, value in zip([m.param_name for m in mapping], params)
]
types_sort = [F.ANY, F.TBD, F.Constant, F.Range, F.Set, F.Operation]
for p, value in sorted(
module_params, key=lambda x: types_sort.index(type(x[0].get_most_narrow()))
):
p.override(value)

module.add(
F.has_descriptive_properties_defined(
Expand Down
19 changes: 17 additions & 2 deletions src/faebryk/libs/picker/jlcpcb/picker_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import faebryk.library._F as F
from faebryk.core.module import Module
from faebryk.core.parameter import Parameter
from faebryk.libs.e_series import E_SERIES_VALUES
from faebryk.libs.picker.jlcpcb.jlcpcb import (
Component,
Expand Down Expand Up @@ -216,6 +217,10 @@ def f(x: str) -> F.Constant[T]:
}


def try_get_param_mapping(module: Module) -> list[MappingParameterDB]:
return _MAPPINGS_BY_TYPE.get(type(module), [])


# Generic pickers ----------------------------------------------------------------------


Expand Down Expand Up @@ -261,7 +266,14 @@ def find_and_attach_by_lcsc_id(module: Module):
f"Part with LCSC part number {lcsc_pn} has insufficient stock", module
)

part.attach(module, [])
try:
part.attach(module, try_get_param_mapping(module), allow_TBD=True)
except Parameter.MergeException as e:
# TODO might be better to raise an error that makes the picker give up
# but this works for now, just not extremely efficient
raise PickError(
f"Could not attach part with LCSC part number {lcsc_pn}: {e}", module
) from e


def find_component_by_mfr(mfr: str, mfr_pn: str) -> Component:
Expand Down Expand Up @@ -323,11 +335,14 @@ def find_and_attach_by_mfr(module: Module):

for part in parts:
try:
part.attach(module, [])
part.attach(module, try_get_param_mapping(module), allow_TBD=True)
return
except ValueError as e:
logger.warning(f"Failed to attach component: {e}")
continue
except Parameter.MergeException:
# TODO not very efficient
pass

raise PickError(
f"Could not attach any part with manufacturer part number {mfr_pn}", module
Expand Down