Skip to content

Commit 1a6216a

Browse files
Fixme: improve ngspice library path
1 parent 966fc03 commit 1a6216a

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

PySpice/Spice/NgSpice/Shared.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def new_instance(cls, ngspice_id=0, send_data=False):
334334

335335
##############################################
336336

337-
def __init__(self, ngspice_id=0, send_data=False):
337+
def __init__(self, ngspice_id=0, send_data=False, verbose=False):
338338

339339
""" Set the *send_data* flag if you want to enable the output callback.
340340
@@ -346,14 +346,28 @@ def __init__(self, ngspice_id=0, send_data=False):
346346
self._stdout = []
347347
self._stderr = []
348348

349-
self._load_library()
349+
self._library_path = None
350+
self._load_library(verbose)
350351
self._init_ngspice(send_data)
351352

352353
self._is_running = False
353354

354355
##############################################
355356

356-
def _load_library(self):
357+
@property
358+
def library_path(self):
359+
if self._library_path is None:
360+
if not self._ngspice_id:
361+
library_prefix = ''
362+
else:
363+
library_prefix = '{}'.format(self._ngspice_id)
364+
library_path = self.LIBRARY_PATH.format(library_prefix)
365+
self._library_path = library_path
366+
return self._library_path
367+
368+
##############################################
369+
370+
def _load_library(self, verbose):
357371

358372
if ConfigInstall.OS.on_windows:
359373
# https://sourceforge.net/p/ngspice/discussion/133842/thread/1cece652/#4e32/5ab8/9027
@@ -366,13 +380,11 @@ def _load_library(self):
366380
with open(api_path) as f:
367381
ffi.cdef(f.read())
368382

369-
if not self._ngspice_id:
370-
library_prefix = ''
371-
else:
372-
library_prefix = '{}'.format(self._ngspice_id)
373-
library_path = self.LIBRARY_PATH.format(library_prefix)
374-
self._logger.debug('Load {}'.format(library_path))
375-
self._ngspice_shared = ffi.dlopen(library_path)
383+
message = 'Load library {}'.format(self.library_path)
384+
self._logger.debug(message)
385+
if verbose:
386+
print(message)
387+
self._ngspice_shared = ffi.dlopen(self.library_path)
376388

377389
# Note: cannot yet execute command
378390

0 commit comments

Comments
 (0)