devbisme / skidl

SKiDL is a module that extends Python with the ability to design electronic circuits.
https://devbisme.github.io/skidl/
MIT License
1.04k stars 118 forks source link

[SKiDL BUG] 1.2.0 doesn't work with the previous files #190

Closed HubertHQH closed 1 year ago

HubertHQH commented 1 year ago

Describe the bug SKidl 1.2.0 doesn't work with the previous py files. With the old skidl, the py file can run and generate netlist successfully.

Traceback (most recent call last):
  File "D:\pythonProject1\testgensch.py", line 4, in <module>
    q = Part("Device", "Q_PNP_CBE", dest=TEMPLATE)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\skidl\part.py", line 191, in __init__
    lib = SchLib(filename=libname, tool=tool)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\skidl\schlib.py", line 88, in __init__
    tool_modules[tool].load_sch_lib(
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\skidl\tools\kicad\kicad.py", line 80, in load_sch_lib
    f, _ = find_and_open_file(
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\skidl\utilities.py", line 793, in find_and_open_file
    return urllib.request.urlopen(link), link
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 519, in open
    response = self._open(req, data)
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 541, in _open
    return self._call_chain(self.handle_open, 'unknown',
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 1419, in unknown_open
    raise URLError('unknown url type: %s' % type)
urllib.error.URLError: <urlopen error unknown url type: d>

Process finished with exit code 1

To Reproduce Steps to reproduce the behavior:

  1. Install the latest Skidl 1.2.0
  2. Set environment variable: "KICAD_SYMBOL_DIR=D:\Program Files\KiCad\6.0\share\kicad\symbols"
  3. Run the following code:
from skidl import *

# Define components
in_terminal = Net('IN')
out_terminal = Net('OUT')
gnd = Net('GND')
regulator = Part('Regulator_Linear', 'LM1117-3.3', footprint = 'Package_TO_SOT_THT:TO-220-3_Vertical')
cap1 = Part('Device', 'C', value='10uF', footprint = 'Resistor_SMD:R_0805_2012Metric')
cap2 = Part('Device', 'C', value='1uF', footprint = 'Resistor_SMD:R_0805_2012Metric')

# Connect components
in_terminal += regulator['VI']
out_terminal += regulator['VO']
gnd += regulator['GND']
cap1[1] += in_terminal
cap1[2] += gnd
cap2[1] += out_terminal
cap2[2] += gnd

# Set regulator parameters
regulator.value = 'LM1117MP-3.3'

# Generate netlist
generate_netlist()
  1. See error

Expected behavior Netlist is generated correctly without error.

Desktop :

Additional context I also tried the example file in readme and get the same issue. But both files work with the previous version Skidl. Suspect this is environment setting issues or related to KiCad symbol version? Previous Skidl only works with Kicad 6 symbols but not K7. Any idea?

devbisme commented 1 year ago

Thanks for the report! There was an issue with search reported a few days ago that involved the is_url function. Try the development branch and see if that corrects your problem:

pip install git+https://github.com/devbisme/skidl.git@development
HubertHQH commented 1 year ago

Thanks Dave! The development branch addresses my issue. But when I try to generate_schematic(), there's another exception. This is a separate issue. I will dig deeper.

Traceback (most recent call last):
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\skidl\skidlbaseobj.py", line 47, in __getattr__
    return self.__getattribute__("fields")[key]
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
KeyError: 'x'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\pythonProject1\schematic.py", line 25, in <module>
    generate_schematic()
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\skidl\circuit.py", line 1040, in generate_schematic
    tool_modules[tool].gen_schematic(self, **kwargs)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\skidl\schematics\gen_schematic.py", line 619, in gen_schematic
    preprocess_circuit(circuit, **options)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\skidl\schematics\gen_schematic.py", line 169, in preprocess_circuit
    initialize(part)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\skidl\schematics\gen_schematic.py", line 73, in initialize
    pin.pt = Point(pin.x, pin.y)
                   ^^^^^
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\skidl\skidlbaseobj.py", line 49, in __getattr__
    raise AttributeError
AttributeError

Process finished with exit code 1
devbisme commented 1 year ago

Are you trying to create a schematic? Are you trying to create a schematic while using KiCad 6 or 7 symbols? That won't work. Schematic creation currently only works with KiCad 5 symbol libraries.

HubertHQH commented 1 year ago

Aha, it's KiCad 5 symbol related. Now everything is fine. Thanks Dave!