Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bikey-Wagon Learnings #14

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Bikey-Wagon Learnings #14

wants to merge 6 commits into from

Conversation

mawildoer
Copy link
Contributor

@mawildoer mawildoer commented Aug 16, 2024

Commit per change

Checklist

Please read and execute the following:

  • My code follows the coding guidelines of this project
  • My PR title is following the contribution guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (if applicable)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I ran Black to format my code

Code of Conduct

By submitting this issue, you agree to follow our Code of Conduct:

@mawildoer mawildoer force-pushed the mawildoer/rough-edges-2 branch 2 times, most recently from bd7c815 to 408c46d Compare September 5, 2024 00:08
@mawildoer mawildoer changed the title Rough edges 2 Bikey-Wagon Learnings Sep 5, 2024
@mawildoer mawildoer marked this pull request as ready for review September 5, 2024 00:24
@mawildoer
Copy link
Contributor Author

Ready to merge

Copy link
Contributor

@iopapamanoglou iopapamanoglou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks for the most part good.
I guess the NetTie was made before fab ll?

interface_type: type[T] = Electrical,
) -> None:
super().__init__()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init in fab ll is purely for argument passing
split into init and preinit

    def __init__(
        self,
        width: Size,
        interface_type: type[T] = Electrical,
    ) -> None:
        super().__init__()
        self._interface_type = interface_type
        self._width = width

   def __preinit__(self): ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait though, if __preinit__ is called before __init__ then how can I access _width during my static configuration?

Copy link
Contributor

@iopapamanoglou iopapamanoglou Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order is init, annotations, d_fields, rt_fields, preinit, postinit
I can see where the confusion comes from.
The pre/post refers to pre/post base class construction

Comment on lines +39 to +51
self.add(F.can_attach_to_footprint_symmetrically())
self.add(F.has_designator_prefix_defined("H"))
# TODO: "removed" isn't really true, but seems to work
self.add(has_part_picked_remove())

# TODO: generate the kicad footprint instead of loading it
self.add(
F.has_footprint_defined(
KicadFootprint(
f"NetTie:NetTie-2_SMD_Pad{width_mm:.1f}mm", pin_names=["1", "2"]
)
)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static traits should be in the class body

attach_to_footprint: F.can_attach_to_footprint_symmetrically
designator_prefix = L.f_field(F.has_designator_prefix_defined)("H")

@L.rt_field
def footprint(self):
    width_mm = NetTie.Size(self._width).value
    return F.has_footprint_defined(
                KicadFootprint(
                    f"NetTie:NetTie-2_SMD_Pad{width_mm:.1f}mm", pin_names=["1", "2"]
                )
            )

super().__init__()

# dynamically construct the interfaces
self.unnamed = self.add([interface_type(), interface_type()], "unnamed")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do the self.unnamed =, it's done by self.add automatically

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use times:

self.add(times(2, self._interface_type), "unnamed")

Comment on lines +10 to +11
from faebryk.library.Electrical import Electrical
from faebryk.library.KicadFootprint import KicadFootprint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid direct imports from faebryk.library, use F.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pulling this into my project for now and separating the PRs.
Here's another draft for it specifically: #39


def __init__(
self,
width: Size,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the width be a parameter instead of constructor argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, but then I'd need to defer construction until later to make the footprint trait work.
Until that's all working this seems simpler and clearer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need delayed construction, because you are not constructing anything. Adding a trait is always possible.
You can use is_implemented in the trait to check whether the width is 'ready' for making a footprint.

Copy link
Contributor

@iopapamanoglou iopapamanoglou Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

width: TBD[Quantity]

...

@L.rt_field
def footprint(self):
   class _(F.has_footprint):
      @staticmethod
      def get_footprint():
          value = self.width.get_most_narrow()
          assert isinstance(value, Constant)
          width_mm = value ...
          return F.KicadFootprint(f"NetTie:NetTie-2_SMD_Pad{width_mm:.1f}mm", pin_names=["1", "2"])

      @staticmethod
      def is_implemented(_self):
          return isinstance(self.width.get_most_narrow(), Constant)

   return _()

"""

def __init__(
self, data: Sequence[T] | None = None, hasher: Callable[[T], Hashable] = id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data: Iterable[T]

Comment on lines +899 to +900
self._deref = {hasher(d[0]): d[0] for d in data} if data else {}
self._data = {hasher(d[0]): d[1] for d in data} if data else {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment in FuncSet about multidict / hash uniqueness

def __contains__(self, item: T):
return self._hasher(item) in self._deref

def __iter__(self) -> Iterable[T]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think iter returns Iterator[T], not sure tho

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thank you added tests!
I'd add one for non default hash func that has collisions: e.g `lambda x: id(x) % 10'

Comment on lines 19 to 20
offer_missing_install("dash_cytoscape")
offer_missing_install("dash")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment in visualize.
Having a poetry dep group for this and then check if its there and if not print: install via poetry ... might be cleaner

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this one's a little weird. Not sure I love the offer_missing pattern for the deps at all.

Separately, we should shoot for a vanilla pip/pipx install working by default, not poetry. Let's detangle that where when we come by it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaik currently everything works with a pip only setup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants