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

[SKiDL BUG] Using components that do not contain a defined datasheet property throws 'Key Error' #248

Open
keithgh1 opened this issue Feb 13, 2025 · 3 comments
Labels

Comments

@keithgh1
Copy link

keithgh1 commented Feb 13, 2025

Describe the bug
When custom components don't contain the datasheet property, then attempting to parse it throws an error.

To Reproduce
Steps to reproduce the behavior:

  1. Load a part that fits the description.

zif = Part('220-3342-00-0602J.kicad_sym','220-3342-00-0602J')

Expected behavior
I expected the part to load without error.

Fix

The problem exists in (

part.datasheet = props["datasheet"][2]
)

Specifically

    # Populate part fields from symbol properties. Properties will also be included below in drawing commands.
    props = {
        prop[1].lower(): prop
        for prop in part.part_defn
        if prop[0].value().lower() == "property"
    }
    part.ref_prefix = props["reference"][2]
    part.value = props["value"][2]
    part.fplist.append(props["footprint"][2])
    part.datasheet = props["datasheet"][2]
    part.draw_cmds[1].extend([props["reference"], props["value"]])

Line 462: if props datasheet[2] doesn't exist, then the script errors out.

Replace line 462 with these two lines:

part.datasheet = props.get("datasheet", ["", "", ""])
    part.datasheet = part.datasheet[2] if len(part.datasheet) > 2 else ""

I have no clue if this is the most robust or clean way of handling this, but I do know that this fixes my issue.

Desktop (please complete the following information):

  • Windows 11 Pro.
  • Jupyter Notebook 7.2.2
  • Python 3.12.7
  • SKiDL version 2.0.1

Additional context
This will likely need to be changed in all the different kicad version lib.py's. The troublesome part, downloaded from the normal part sites, is attached.

220-3342-00-0602J.zip

@keithgh1 keithgh1 added the bug label Feb 13, 2025
devbisme pushed a commit that referenced this issue Feb 15, 2025
@devbisme
Copy link
Owner

Thanks for the error report, location of the error, and the fix! I've made the corrections to the code in the development branch for KiCad 6, 7, and 8. The test suite passes, but my test data doesn't include any custom libraries with missing datasheet entries. So please try it out and see if it works for you. Also, let me know where I can get the custom library that causes this problem so I can add it to my test suite. Thanks!

@keithgh1
Copy link
Author

Hey! Thanks for the quick response! I attached the problematic library with the part to the issue, see zip!

I'll try this out in a bit.

@keithgh1
Copy link
Author

ok @devbisme I tested your change, works fine. Your change is more robust because it handles the other properties as well. Thanks for skidl -- having so much fun creating PCBs without schematics. Really speeding up the process!

Let me know if you need anything else.

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

No branches or pull requests

2 participants