[SKiDL BUG] search_footprints results in `FileNotFoundError: [Errno 2] No such file or directory:`
Describe the bug
Search footprints, with a properly configured path doesn't work - resulting in an exception, seemingly due to improper parsing of the path in footprint_search_paths (running on macOS)
To Reproduce Steps to reproduce the behavior:
- set
footprint_search_paths['kicad8'] = '/Applications/KiCad/KiCad.app/Contents/SharedSupport/footprints/' - search_footprints('cap')
- FileNotFoundError: [Errno 2] No such file or directory: 'A'
Expected behavior Return a list of footprints matching "cap"
Desktop (please complete the following information):
- OS macOS 14.5
- Python version 3.12.3
- SKiDL version [e.g. 22] 1.2.3
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
Cell In[18], line 2
1 footprint_search_paths['kicad8'] = '/Applications/KiCad/KiCad.app/Contents/SharedSupport/footprints/'
----> 2 search_footprints('cap')
File /opt/homebrew/lib/python3.11/site-packages/skidl/part_query.py:379, in search_footprints(terms, tool)
374 """
375 Print a list of footprints with the regex term within their description/tags.
376 """
378 footprints = []
--> 379 for fp in search_footprints_iter(terms, tool):
380 if fp[0] == "LIB":
381 print(" " * 79, "\rSearching {} ...".format(fp[1]), sep="", end="\r")
File /opt/homebrew/lib/python3.11/site-packages/skidl/part_query.py:304, in search_footprints_iter(terms, tool)
302 footprint_cache.clear()
303 for path in skidl.footprint_search_paths[tool]:
--> 304 footprint_cache.load(path)
306 # Get the number of footprint libraries to be searched..
307 num_fp_libs = len(footprint_cache)
File /opt/homebrew/lib/python3.11/site-packages/skidl/part_query.py:268, in FootprintCache.load(self, path)
263 continue
265 # Get a list of all the footprint module files in the top-level of the library URI.
266 filenames = [
267 fn
--> 268 for fn in os.listdir(uri)
269 if os.path.isfile(os.path.join(uri, fn))
270 and fn.lower().endswith(".kicad_mod")
271 ]
273 # Create an entry in the cache for this nickname. (This will overwrite
274 # any previous nickname entry, so make sure to scan fp-lib-tables in order of
275 # increasing priority.) Each entry contains the path to the directory containing
276 # the footprint module and a dictionary of the modules keyed by the module name
277 # with an associated value containing the module file contents (which starts off
278 # as None).
279 self[nickname] = {
280 "path": uri,
281 "modules": {os.path.splitext(fn)[0]: None for fn in filenames},
282 }
FileNotFoundError: [Errno 2] No such file or directory: 'A'
footprint_search_paths['kicad8'] should be a list of paths where footprint files can be found, not a string for a single path:
footprint_search_paths['kicad8'] = ['/Applications/KiCad/KiCad.app/Contents/SharedSupport/footprints/']
I see. The reason I thought it was simply a string is because the default value is not a list:
❯ python3
Python 3.12.3 (main, Apr 9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from skidl import *
WARNING: KICAD8_SYMBOL_DIR environment variable is missing, so the default KiCad symbol libraries won't be searched. @ [/Users/blark/src/lab/skidl/<frozen importlib._bootstrap_external>:995=>/Users/blark/src/lab/skidl/<frozen importlib._bootstrap>:488]
WARNING: KICAD6_SYMBOL_DIR environment variable is missing, so the default KiCad symbol libraries won't be searched. @ [/Users/blark/src/lab/skidl/<frozen importlib._bootstrap_external>:995=>/Users/blark/src/lab/skidl/<frozen importlib._bootstrap>:488]
WARNING: KICAD7_SYMBOL_DIR environment variable is missing, so the default KiCad symbol libraries won't be searched. @ [/Users/blark/src/lab/skidl/<frozen importlib._bootstrap_external>:995=>/Users/blark/src/lab/skidl/<frozen importlib._bootstrap>:488]
WARNING: KICAD_SYMBOL_DIR environment variable is missing, so the default KiCad symbol libraries won't be searched. @ [/Users/blark/src/lab/skidl/<frozen importlib._bootstrap_external>:995=>/Users/blark/src/lab/skidl/<frozen importlib._bootstrap>:488]
>>> footprint_search_paths
{'kicad8': '/Users/blark/Library/Preferences/kicad', 'kicad6': '/Users/blark/Library/Preferences/kicad', 'kicad7': '/Users/blark/Library/Preferences/kicad', 'spice': '', 'kicad5': '/Users/blark/Library/Preferences/kicad', 'skidl': ''}
Hmm.
Did it work once you changed it to a list? If so, then there's a mistake in my initialization of the defaults.
I just checked and the footprint_search_paths entries are incorrectly initialized to strings instead of lists of strings. So I'll have to change that.
I finally changed the initialization of the footprint_search_paths to lists instead of strings. It's in the development branch. Apologies for the massive delay in fixing this.