23
23
# SOFTWARE.
24
24
25
25
import math
26
- import os
27
26
from pathlib import Path
28
27
import secrets
29
28
import warnings
@@ -488,7 +487,7 @@ def create_model_from_touchstone(self, input_file, model_name=None, show_bitmap=
488
487
489
488
Parameters
490
489
----------
491
- input_file : str
490
+ input_file : str or :class:`pathlib.Path`
492
491
Full path to the Touchstone file.
493
492
model_name : str, optional
494
493
Name of the model. The default is ``None``.
@@ -508,12 +507,12 @@ def create_model_from_touchstone(self, input_file, model_name=None, show_bitmap=
508
507
"""
509
508
510
509
if not model_name :
511
- model_name = os . path . splitext ( os . path . basename (input_file ))[ 0 ]
510
+ model_name = Path ( Path (input_file ). name ). stem
512
511
if "." in model_name :
513
512
model_name = model_name .replace ("." , "_" )
514
513
if model_name in list (self .omodel_manager .GetNames ()):
515
514
model_name = generate_unique_name (model_name , n = 2 )
516
- num_terminal = int (os . path . splitext (input_file )[ 1 ] .lower ().strip (".sp" ))
515
+ num_terminal = int (Path (input_file ). suffix .lower ().strip (".sp" ))
517
516
518
517
port_names = []
519
518
with open_file (input_file , "r" ) as f :
@@ -527,8 +526,8 @@ def create_model_from_touchstone(self, input_file, model_name=None, show_bitmap=
527
526
image_subcircuit_path = ""
528
527
bmp_file_name = ""
529
528
if show_bitmap :
530
- image_subcircuit_path = os . path . join (self ._app .desktop_install_dir , "syslib" , "Bitmaps" , "nport.bmp" )
531
- bmp_file_name = os . path . basename (image_subcircuit_path )
529
+ image_subcircuit_path = Path (self ._app .desktop_install_dir ) / "syslib" / "Bitmaps" / "nport.bmp"
530
+ bmp_file_name = Path (image_subcircuit_path ). name
532
531
533
532
if not port_names :
534
533
port_names = ["Port" + str (i + 1 ) for i in range (num_terminal )]
@@ -547,13 +546,13 @@ def create_model_from_touchstone(self, input_file, model_name=None, show_bitmap=
547
546
"Description:=" ,
548
547
"" ,
549
548
"ImageFile:=" ,
550
- image_subcircuit_path ,
549
+ str ( image_subcircuit_path ) ,
551
550
"SymbolPinConfiguration:=" ,
552
551
0 ,
553
552
["NAME:PortInfoBlk" ],
554
553
["NAME:PortOrderBlk" ],
555
554
"filename:=" ,
556
- input_file ,
555
+ str ( input_file ) ,
557
556
"numberofports:=" ,
558
557
num_terminal ,
559
558
"sssfilename:=" ,
@@ -662,7 +661,7 @@ def create_model_from_touchstone(self, input_file, model_name=None, show_bitmap=
662
661
"InfoHelpFile:=" ,
663
662
"" ,
664
663
"IconFile:=" ,
665
- bmp_file_name ,
664
+ str ( bmp_file_name ) ,
666
665
"Library:=" ,
667
666
"" ,
668
667
"OriginalLocation:=" ,
@@ -765,7 +764,7 @@ def create_model_from_nexxim_state_space(self, input_file, num_terminal, model_n
765
764
"""
766
765
767
766
if not model_name :
768
- model_name = os . path . splitext ( os . path . basename (input_file ))[ 0 ]
767
+ model_name = Path ( Path (input_file ). name ). stem
769
768
if "." in model_name :
770
769
model_name = model_name .replace ("." , "_" )
771
770
if model_name in list (self .omodel_manager .GetNames ()):
@@ -1681,18 +1680,18 @@ def __init__(self, component_manager):
1681
1680
def _index_components (self , library_path = None ):
1682
1681
if library_path :
1683
1682
sys_files = recursive_glob (library_path , "*.aclb" )
1684
- root = os . path . normpath (library_path ).split ( os . path . sep )[ - 1 ]
1683
+ root = Path (library_path ).name
1685
1684
else :
1686
- sys_files = recursive_glob (os . path . join (self ._app .syslib , self ._component_manager .design_libray ) , "*.aclb" )
1687
- root = os . path . normpath (self ._app .syslib ).split ( os . path . sep )[ - 1 ]
1685
+ sys_files = recursive_glob (Path (self ._app .syslib ) / self ._component_manager .design_libray , "*.aclb" )
1686
+ root = Path (self ._app .syslib ).name
1688
1687
for file in sys_files :
1689
1688
comps1 = load_keyword_in_aedt_file (file , "DefInfo" )
1690
1689
comps2 = load_keyword_in_aedt_file (file , "CompInfo" )
1691
1690
comps = comps1 .get ("DefInfo" , {})
1692
1691
comps .update (comps2 .get ("CompInfo" , {}))
1693
1692
for compname , comp_value in comps .items ():
1694
- root_name , ext = os . path . splitext ( os . path . normpath (file ))
1695
- full_path = root_name . split ( os . path . sep )
1693
+ root_name = str ( Path (file ). with_suffix ( "" ))
1694
+ full_path = list ( Path ( root_name ). parts )
1696
1695
id = full_path .index (root ) + 1
1697
1696
if self ._component_manager .design_libray in full_path [id :]:
1698
1697
id += 1
0 commit comments