forked from PySpice-org/PySpice
-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
ngspice includes an example library in ngspice-44.2/examples/p-to-n-examples/TLC555.LIB which raises syntax errors when I try to open it in SKiDL like so:
~/.../SpiceLib/lib (development) $ ipython
Python 3.12.8 (main, Dec 29 2024, 08:05:02) [GCC 11.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.24.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from skidl import *
In [2]: lib = SchLib("TLC555.LIB", tool=SPICE)
Syntax error at ':'
Parse error in Spice library /home/devb/projects/KiCad/tools/skidl/tests/test_data/SpiceLib/lib/TLC555.LIB
Syntax Error
Failed to parse /home/devb/projects/KiCad/tools/skidl/tests/test_data/SpiceLib/lib/TLC555.LIB: cannot access local variable 'spice_file' where it is not associated with a value
Syntax error at ':'
Parse error in Spice library /home/devb/projects/KiCad/tools/skidl/tests/examples/skidl_spice_test/../../test_data/SpiceLib/lib/TLC555.LIB
Syntax Error
---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
Cell In[2], line 1
----> 1 lib = SchLib("TLC555.LIB", tool=SPICE)
File ~/projects/KiCad/tools/skidl/src/skidl/schlib.py:135, in SchLib.__init__(self, filename, tool, lib_section, use_cache, use_pickle, **attribs)
130 self._cache[lib_pickle_abs_fn] = self
132 # Otherwise, load from a schematic part library file.
133 else:
134 # Use the tool name to find the function for loading the library.
--> 135 tool_modules[tool].load_sch_lib(
136 self,
137 abs_filename,
138 # skidl.lib_search_paths[tool],
139 lib_section=lib_section,
140 )
141 self.filename = filename
142 # Cache a reference to the library.
File ~/projects/KiCad/tools/skidl/src/skidl/tools/spice/spice.py:118, in load_sch_lib(self, filename, lib_search_paths_, lib_section)
116 # Get the unique set of files referenced by the subcircuits in the Spice library.
117 for subcirc in spice_lib.subcircuits:
--> 118 path = getattr(spice_lib[subcirc], "path", None)
119 if not path:
120 path = spice_lib[subcirc] # this is pyspice 1.5 behavior
File ~/projects/KiCad/tools/PySpice/PySpice/Spice/Library/Library.py:243, in SpiceLibrary.__getitem__(self, name)
240 raise KeyError(name)
242 # Create SpiceInclude with recursion enabled if requested
--> 243 spice_include = SpiceInclude(path, recurse=self._recurse)
245 try:
246 # Try to get the item directly from this SpiceInclude
247 return spice_include[name]
File ~/projects/KiCad/tools/PySpice/PySpice/Spice/Library/SpiceInclude.py:311, in SpiceInclude.__init__(self, path, rewrite_yaml, recurse, section)
308 self.load_yaml()
309 # self.dump()
310 else:
--> 311 self.parse()
312 self.write_yaml()
313 if self._recurse:
File ~/projects/KiCad/tools/PySpice/PySpice/Spice/Library/SpiceInclude.py:465, in SpiceInclude.parse(self)
463 # Convert include paths to absolute paths if they are relative
464 self._inner_includes = []
--> 465 for include_path in spice_file.includes:
466 path = Path(str(include_path))
467 # If path is not absolute, make it absolute using self.path's parent directory
UnboundLocalError: cannot access local variable 'spice_file' where it is not associated with a value
In [3]:
~
I removed the PARAMS: from the library and the syntax error stopped, but were replaced by syntax errors about the & and , characters that appear in some IF statements in the library.
I'm using the latest version of PySpice in the development branch with commits up to 4/17/2025.
Metadata
Metadata
Assignees
Labels
No labels