3434
3535import requests
3636
37+ from colorama import just_fix_windows_console , Fore , Style
38+ just_fix_windows_console ()
39+ # init(autoreset=True)
40+ SRA = Style .RESET_ALL
41+ RED = Fore .RED
42+ BLUE = Fore .BLUE
43+
3744####################################################################################################
3845
3946# Archive: resources/ngspice-31_dll_64.zip
@@ -74,8 +81,7 @@ class CircuitTest:
7481
7582 ##############################################
7683
77- def test_spinit (self ):
78-
84+ def test_spinit (self ) -> None :
7985 from PySpice import Circuit , Simulator
8086 import PySpice .Unit as U
8187
@@ -119,46 +125,40 @@ class PySpicePostInstallation:
119125
120126 ##############################################
121127
122- def run (self ):
123-
124- parser = argparse . ArgumentParser ( description = 'Tool to perform PySpice Post Installation.' )
125-
128+ def run (self ) -> None :
129+ parser = argparse . ArgumentParser (
130+ description = 'Tool to perform PySpice Post Installation.' ,
131+ )
126132 parser .add_argument (
127133 '--ngspice-version' ,
128134 type = int , default = None ,
129135 help = 'NgSpice version to install' ,
130136 )
131-
132137 parser .add_argument (
133138 '--install-ngspice-dll' ,
134139 action = 'store_true' ,
135140 help = 'install Windows DLL' ,
136141 )
137-
138142 parser .add_argument (
139143 '--force-install-ngspice-dll' ,
140144 action = 'store_true' ,
141145 help = 'force DLL installation (for debug only)' ,
142146 )
143-
144147 parser .add_argument (
145148 '--download-ngspice-manual' ,
146149 action = 'store_true' ,
147150 help = 'download Ngspice manual' ,
148151 )
149-
150152 parser .add_argument (
151153 '--check-install' ,
152154 action = 'store_true' ,
153155 help = 'check installation' ,
154156 )
155-
156157 parser .add_argument (
157158 '--download-example' ,
158159 action = 'store_true' ,
159160 help = 'download examples' ,
160161 )
161-
162162 self ._args = parser .parse_args ()
163163
164164 count = 0
@@ -183,7 +183,7 @@ def run(self):
183183
184184 ##############################################
185185
186- def _download_file (self , url , dst_path ):
186+ def _download_file (self , url , dst_path ) -> None :
187187 print ('Get {} ... -> {}' .format (url , dst_path ))
188188 response = requests .get (url , allow_redirects = True )
189189 if response .status_code != requests .codes .ok :
@@ -194,7 +194,7 @@ def _download_file(self, url, dst_path):
194194 ##############################################
195195
196196 @property
197- def ngspice_version (self ):
197+ def ngspice_version (self ) -> str :
198198 if not hasattr (self , '_ngspice_version' ):
199199 version = self ._args .ngspice_version
200200 if version is None :
@@ -205,8 +205,7 @@ def ngspice_version(self):
205205
206206 ##############################################
207207
208- def install_ngspice_dll (self ):
209-
208+ def install_ngspice_dll (self ) -> None :
210209 if not (os .name == 'nt' or self ._args .force_install_ngspice_dll ):
211210 return
212211
@@ -274,19 +273,15 @@ def download_ngspice_manual(self):
274273
275274 ##############################################
276275
277- def check_installation (self ):
278-
276+ def check_installation (self ) -> None :
279277 """Tool to check PySpice is correctly installed.
280278
281279 """
282-
283- import ctypes .util
284-
285- print ('OS:' , sys .platform )
280+ print (f'{ RED } OS: { BLUE } { sys .platform } { SRA } ' )
286281 print ()
287282
288- print (' Environments:' )
289- for _ in (
283+ print (f' { RED } Environments:{ SRA } ' )
284+ for env in (
290285 'PATH' ,
291286 'LD_LIBRARY_PATH' ,
292287 'PYTHONPATH' ,
@@ -300,20 +295,22 @@ def check_installation(self):
300295 'SPICE_NO_DATASEG_CHECK' ,
301296 'NGSPICE_INPUT_DIR' ,
302297 ):
303- print (_ , os .environ .get (_ , 'undefined' ))
298+ _ = os .environ .get (env , 'undefined' )
299+ print (f' { env } { _ } ' )
304300 print ()
305301
306302 if 'VIRTUAL_ENV' in os .environ :
307- print (' On Virtual Environment:' )
308- for _ in (
303+ print (f' { RED } On Virtual Environment:{ SRA } ' )
304+ for env in (
309305 'VIRTUAL_ENV' ,
310306 ):
311- print (_ , os .environ .get (_ , 'undefined' ))
307+ _ = os .environ .get (env , 'undefined' )
308+ print (f' { env } { BLUE } { _ } { SRA } ' )
312309 print ()
313310
314311 if 'CONDA_PREFIX' in os .environ :
315- print (' On Anaconda:' )
316- for _ in (
312+ print (f' { RED } On Anaconda:{ SRA } ' )
313+ for env in (
317314 # not specific
318315 'CONDA_EXE' ,
319316 'CONDA_PYTHON_EXE' ,
@@ -324,124 +321,126 @@ def check_installation(self):
324321 'CONDA_PREFIX' ,
325322 # 'CONDA_PROMPT_MODIFIER',
326323 ):
327- print (_ , os .environ .get (_ , 'undefined' ))
324+ _ = os .environ .get (env , 'undefined' )
325+ print (f' { env } { _ } ' )
328326 print ()
329327
330328 try :
331- print (' Load PySpice module' )
329+ print (f' { RED } Load PySpice module{ SRA } ' )
332330 import PySpice
333- print (' loaded {} version {}' . format ( PySpice .__file__ , PySpice . __version__ ) )
331+ print (f' loaded { PySpice . __file__ } version { BLUE } { PySpice .__version__ } { SRA } ' )
334332 print ()
335333 except ModuleNotFoundError :
336- print ('PySpice module not found' )
334+ print ('{RED} PySpice module not found{SRA} ' )
337335 return
338336
339337 import PySpice .Logging .Logging as Logging
340- logger = Logging .setup_logging (logging_level = 'INFO' )
338+ logger = Logging .setup_logging () # logging_level='INFO'
341339
342340 from PySpice .Config import ConfigInstall
343341 from PySpice .Spice import NgSpice
344342 from PySpice .Spice .NgSpice import NGSPICE_SUPPORTED_VERSION
345343 from PySpice .Spice .NgSpice .Shared import NgSpiceShared
346344
347- print (' ngspice supported version:' , NGSPICE_SUPPORTED_VERSION )
345+ print (f' { RED } ngspice supported version: { BLUE } { NGSPICE_SUPPORTED_VERSION } { SRA } ' )
348346 print ()
349347
350348 ##############################################
351349
352350 message = os .linesep .join ((
353- ' NgSpiceShared configuration is' ,
354- ' NgSpiceShared.NGSPICE_PATH = {0 .NGSPICE_PATH}' ,
355- ' NgSpiceShared.LIBRARY_PATH = {0 .LIBRARY_PATH}' ,
351+ f' { RED } NgSpiceShared configuration is{ SRA } ' ,
352+ f ' NgSpiceShared.NGSPICE_PATH = { NgSpiceShared .NGSPICE_PATH } ' ,
353+ f ' NgSpiceShared.LIBRARY_PATH = { NgSpiceShared .LIBRARY_PATH } ' ,
356354 ))
357- print (message . format ( NgSpiceShared ) )
355+ print (message )
358356 print ()
359357
360358 ##############################################
361359
362360 cwd = Path (os .curdir ).resolve ()
363- print (' Working directory:' , cwd )
361+ print (f' { RED } Working directory:{ SRA } ' , cwd )
364362 print ()
365363
366- locale_ngspice = cwd .joinpath ('ngspice-{}' . format ( NGSPICE_SUPPORTED_VERSION ) )
364+ locale_ngspice = cwd .joinpath (f 'ngspice-{ NGSPICE_SUPPORTED_VERSION } ' )
367365 if locale_ngspice .exists () and locale_ngspice .is_dir ():
368- print (' Found local ngspice:' )
369- for root , _ , filenames in os .walk (locale_ngspice , followlinks = True ):
366+ print (f' { RED } Found local ngspice:{ SRA } ' )
367+ for root , _ , filenames in locale_ngspice .walk (follow_symlinks = True ):
370368 for filename in filenames :
371- print (root , filename )
369+ print (f' { root } { filename } ' )
372370 print ()
373371
374-
375372 ngspice_module_path = Path (NgSpice .__file__ ).parent
376- print (' NgSpice:' , ngspice_module_path )
377- for root , _ , filenames in os .walk (ngspice_module_path ):
373+ print (f' { RED } NgSpice:{ SRA } { ngspice_module_path } ' )
374+ for root , _ , filenames in ngspice_module_path .walk ():
378375 for filename in filenames :
379- print (root , filename )
376+ print (f' { root } { filename } ' )
380377 print ()
381378
382379 ##############################################
383380
384381 if ConfigInstall .OS .on_windows :
385- print ( 'OS is Windows')
382+ os_ = ' Windows'
386383 library = NgSpiceShared .LIBRARY_PATH
387384 elif ConfigInstall .OS .on_osx :
388- print ( 'OS is OSX')
385+ os_ = ' OSX'
389386 library = 'ngspice'
390387 elif ConfigInstall .OS .on_linux :
391- print ( 'OS is Linux')
388+ os_ = ' Linux'
392389 library = 'ngspice'
393390 else :
394391 raise NotImplementedError
395392
396- library_path = ctypes .util .find_library (library )
397- print ('Found in library search path: {}' .format (library_path ))
393+ print (f'{ RED } OS is { BLUE } { os_ } { SRA } ' )
394+ print (f'{ RED } Search: { BLUE } { library } { SRA } ' )
395+ library_path = NgSpiceShared .find_library (library )
396+ print (f'{ RED } Found in library search path: { BLUE } { library_path } { SRA } ' )
398397
399398 ##############################################
400399
401- print ('\n Load NgSpiceShared' )
400+ print ()
401+ print (f'{ RED } Load NgSpiceShared{ SRA } ' )
402402 ngspice = NgSpiceShared .new_instance (verbose = True )
403403
404404 if ConfigInstall .OS .on_linux :
405405 # For Linux see DLOPEN(3)
406406 # Apparently there is no simple way to get the path of the loaded library ...
407407 # But we can look in the process maps
408408 pid = os .getpid ()
409- maps_path = '/proc/{}/maps' . format ( pid )
410- with open (maps_path ) as fh :
409+ maps_path = f '/proc/{ pid } /maps'
410+ with open (maps_path , encoding = 'utf8' ) as fh :
411411 for line in fh :
412412 if '.so' in line and 'ngspice' in line :
413413 parts = [x for x in line .split () if x ]
414414 path = parts [- 1 ]
415- print (' loaded {}' . format ( path ) )
415+ print (f' { RED } loaded { BLUE } { path } { SRA } ' )
416416 break
417417 print ()
418418
419419 if ngspice .spinit_not_found :
420- print ('WARNING: spinit was not found' )
420+ print ('{RED} WARNING: spinit was not found{SRA} ' )
421421 print ()
422422
423423 message = os .linesep .join ((
424- ' Ngspice version is {0 .ngspice_version}' ,
425- ' has xspice: {0 .has_xspice}' ,
426- ' has cider {0 .has_cider}' ,
424+ f' { RED } Ngspice version is { BLUE } { ngspice .ngspice_version } { SRA } ' ,
425+ f ' has xspice: { ngspice .has_xspice } ' ,
426+ f ' has cider { ngspice .has_cider } ' ,
427427 ))
428- print (message . format ( ngspice ) )
428+ print (message )
429429 print ()
430430
431431 command = 'version -f'
432- print ('> ' + command )
432+ print (f' { RED } > { command } { SRA } ' )
433433 print (ngspice .exec_command (command ))
434434 print ()
435435
436436 circuit_test = CircuitTest ()
437437 circuit_test .test_spinit ()
438438
439- print (' PySpice should work as expected' )
439+ print (f' { RED } PySpice should work as expected{ SRA } ' )
440440
441441 ##############################################
442442
443- def download_example (self ):
444-
443+ def download_example (self ) -> None :
445444 import PySpice
446445 version = PySpice .__version__
447446
@@ -466,6 +465,6 @@ def download_example(self):
466465
467466####################################################################################################
468467
469- def main ():
468+ def main () -> None :
470469 _ = PySpicePostInstallation ()
471470 return _ .run ()
0 commit comments