question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ORM-like definition of new parts

See original GitHub issue

Description

At the moment, I have to go into the KiCad library editor to create a new part. The net connections and net list are generated using skidl, but skidl is still utterly dependent on existing part libraries generated using KiCad.

I would like to see a ‘model’ or library that creates the part itself in python. We see similar models when we look as sqlalchemy classes which define and correspond to tables. In sqlalchemy, most users will create a models.py file which will entirely contain the SQL structure and my proposal is to implement a similar feature in skidl.

Motivation

This is OK, but it would be much more pythonic - and readable! - to create models using python syntax and use that to instantiate my part. Schematic part creation is great for those who have an existing library, but to use skidl for the workflow, it makes sense to have a ‘from scratch’ skidl option.

Current Part Generation

Using the example ‘pic10f220-i/ot’ from the documentation. The PIC10 has to be created using the schematic editor and skidl has to be configured to find that library and import it. The part definition is then entirely based on the KiCad part definition.

import skidl
pic10 = Part(lib='microchip_pic10mcu', name='pic10f220-i/ot')

Proposed Part Generation

The proposed ORM-like structure would likely consist of a custom library-like file and then the use-case (though it wouldn’t have to be separated).

my_custom_parts.py

import skidl

class Pic10(BasePart):
    name = 'pic10f220-i/ot'
    pins = [
        Pin(num=1, name='ICSPDAT/AN0/GP0', funct=skidl.Pin.BIDIRECTIONAL),
        Pin(num=2, name='VSS', funct=skidl.Pin.POWER-IN),
        Pin(num=3, name='ICSPCLK/AN1/GP1', funct=skidl.Pin.BIDIRECTIONAL),
        Pin(num=4, name='T0CKI/FOSC4/GP2', funct=skidl.Pin.BIDIRECTIONAL),
        Pin(num=5, name='VDD', funct=skidl.Pin.POWER-IN),
        Pin(num=6, name='Vpp/~MCLR~/GP3', funct=skidl.Pin.INPUT)
    ]
    # more stuff could be added, but wouldn't have to be - manufacturer, part number, etc

my_circuit.py

pic10 = Part(basepart=Pic10)

Additional Features

Assuming that the proposed feature is implemented, it would also be nice to have a ‘lib_to_skidl.py’ script similar in functionality to the existing ‘netlist_to_skidl.py’ that exists now.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
slightlynybbledcommented, Feb 20, 2017

Hey, thanks for working on this. So, I believe that I have a prototype working, but I am having trouble finding the contribution guidelines. Could you link those from the readme?

Examples of part models:

class Resistor(PartModel):
    name = 'resistor'
    ref_prefix = 'R'

    pins = [
        Pin(num=1, name='pin1', funct=Pin.PASSIVE),
        Pin(num=2, name='pin2', funct=Pin.PASSIVE),
    ]

    manufacturer = 'Yageo'
    part_number = 'RC0402JR-0710KL'


class Capacitor(PartModel):
    name = 'capacitor'
    ref_prefix = 'C'

    pins = [
        Pin(num=1, name='pin1', funct=Pin.PASSIVE),
        Pin(num=2, name='pin2', funct=Pin.PASSIVE),
    ]
0reactions
Pequecommented, Sep 9, 2018

Just as an idea, it could be nice if you could use dicts instead of Pin() and simple strings for funct (maybe it looks more “pythonic” that way):

class Pic10(BasePart):
    name = 'pic10f220-i/ot'
    pins = [
        dict(num=1, name='ICSPDAT/AN0/GP0', funct='bidirectional'),
        dict(num=2, name='VSS', funct='power-in'),
        dict(num=3, name='ICSPCLK/AN1/GP1', funct='bidirectional'),
        # ...
    ]

Also, it would be great if you could create an instance of that part with:

pic10 = Pic10()

Instead of:

pic10 = Part(basepart=Pic10)
Read more comments on GitHub >

github_iconTop Results From Across the Web

New Parts Definition | Law Insider
New Parts means any Parts that (i) are not produced for Xxxx by Sypris as of the Effective Date, (ii) are not Existing...
Read more >
Explain ORM like I'm five - DEV Community ‍ ‍
Nested data structures are a pain to load and save to the database. That's the primary reason ORMs exist. They auto generate code...
Read more >
ORM like functions · Issue #407 · facebookarchive/php-graph ...
I'm on this. It breaks SOLID principe, especially the Single Responsability Principe (SRP), it gives too much responsabilities to the GraphObject , which...
Read more >
MIS 333K Exam #2 Flashcards - Quizlet
What are the benefits of using an ORM (like Entity Frameworks) and what are the ... Models are the most important part and...
Read more >
What's new in v4 - upper/db
The sqlbuilder package is now part of upper/db 's core ... Session interface, meaning that you won't have to import any extra package...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found