nunobrum / spicelib

Python library to interact with spice simulators such as LTSpice, QSPICE, NGSpice and others.
GNU General Public License v3.0
35 stars 10 forks source link

Library search for asc_editor and spice_editor can be improved by looking at the simulator path #69

Closed hb020 closed 3 months ago

hb020 commented 3 months ago

Right now, I see these search paths:

AscEditor._lib_file_find():
os.path.expanduser("~/AppData/Local/LTspice/lib/sub"),
os.path.expanduser("~/Documents/LtspiceXVII/lib/sub"),
os.path.expanduser("~/AppData/Local/Programs/ADI/LTspice/lib.zip"),

AscEditor._asy_file_find():
os.path.expanduser("~/AppData/Local/LTspice/lib/sym"),
os.path.expanduser("~/Documents/LtspiceXVII/lib/sym"),

SpiceCircuit.get_subcircuit():
os.path.join(os.path.expanduser('~'), "Documents/LTspiceXVII/lib/sub", lib)

asc_to_qsch.convert_asc_to_qsch():
os.path.expanduser("~/AppData/Local/LTspice/lib/sym"),
os.path.expanduser("~/Documents/LtspiceXVII/lib/sym"),

3 issues show up: 1) not all paths are used everywhere 2) this is mainly guess work, while we know the path of the spice executable. The latter could be especially helpful when we have installations with wine, where these specific search paths are guaranteed to point nowhere (requiring the user to use SpiceCircuit.add_library_search_paths() or SpiceEditor.LibSearchPaths.append()), or potentially worse: point to a potentially outdated MacOS version without complaining. 3) I would suggest not using ~/AppData/Local/Programs/ADI/LTspice/lib.zip, as that points to the default installation, not the updated files that are normally in one of the paths mentioned above.

I propose to tweak these searches to base the search on where the simulator really is installed. Will provide a PR.

hb020 commented 3 months ago

Just to trace the paths I found:

~/Local Settings/Application Data/LTspice/lib
~/AppData/Local/LTspice/lib
~/Documents/LtspiceXVII/lib

Under wine, ~ should mean the part the simulator's executable path preceding and including /drive_c/ + /users/${USER}/

Under windows or when using the native MacOS simulator, we can just use os.path.expanduser()

nunobrum commented 3 months ago

The paths are not the same everywhere and there is a reason for that. In one case we are looking for symbols, another we are looking for libraries, and another for other .asc files.

hb020 commented 3 months ago

Yes, /sub, /sym endings are needed of course. Didn't make that explicit. The main point is that the number of paths to search is not identical everywhere. Working on a POC to automate lib path searches, and to make it easier for the people under wine.

hb020 commented 3 months ago

Proposition:

The situation right now

Simulators

Editors

AscEditor (for LTspice):

QschEditor (for Qspice):

asc_to_qsch (for LTspice to Qspice conversion):

SpiceCircuit/SpiceEditor (for LTspice, but potentially others):

Conclusions

Propositions

See branch library-searching-69

nunobrum commented 3 months ago

branch library-searching-69 was merged into trunk. Thanks to @hb020