26
26
27
27
import io
28
28
import math
29
- import os
30
29
from pathlib import Path
31
30
import re
32
31
import shutil
@@ -453,7 +452,7 @@ def get_ibis_model_from_file(self, input_file, is_ami=False):
453
452
454
453
Parameters
455
454
----------
456
- input_file : str
455
+ input_file : str or :class:`pathlib.Path`
457
456
Path of the IBIS file.
458
457
is_ami : bool, optional
459
458
Whether the file to import is an IBIS AMI file. The
@@ -465,9 +464,9 @@ def get_ibis_model_from_file(self, input_file, is_ami=False):
465
464
IBIS object exposing all data from the IBIS file.
466
465
"""
467
466
if is_ami :
468
- reader = ibis_reader .AMIReader (input_file , self )
467
+ reader = ibis_reader .AMIReader (str ( input_file ) , self )
469
468
else :
470
- reader = ibis_reader .IbisReader (input_file , self )
469
+ reader = ibis_reader .IbisReader (str ( input_file ) , self )
471
470
reader .parse_ibis_file ()
472
471
return reader .ibis_model
473
472
@@ -862,7 +861,7 @@ def export_fullwave_spice(
862
861
Name of the setup if it is a design. The default is ``None``.
863
862
is_solution_file : bool, optional
864
863
Whether it is an imported solution file. The default is ``False``.
865
- filename : str, optional
864
+ filename : str or :class:`pathlib.Path` , optional
866
865
Full path and name for exporting the HSpice file.
867
866
The default is ``None``, in which case the file is exported to the working directory.
868
867
passivity : bool, optional
@@ -891,13 +890,14 @@ def export_fullwave_spice(
891
890
if not design :
892
891
design = self .design_name
893
892
if not filename :
894
- filename = os . path . join (self .working_directory , self .design_name + " .sp")
893
+ filename = Path (self .working_directory ) / f" { self .design_name } .sp"
895
894
if is_solution_file :
896
895
setup = design
897
896
design = ""
898
897
else :
899
898
if not setup :
900
899
setup = self .nominal_sweep
900
+ file_path = Path (filename )
901
901
self .onetwork_data_explorer .ExportFullWaveSpice (
902
902
design ,
903
903
is_solution_file ,
@@ -945,11 +945,11 @@ def export_fullwave_spice(
945
945
"SYZDataInAutoMode:=" ,
946
946
False ,
947
947
"ExportDirectory:=" ,
948
- os . path . dirname ( filename ) + "\\ " ,
948
+ str ( file_path . parent ) + "\\ " ,
949
949
"ExportSpiceFileName:=" ,
950
- os . path . basename ( filename ) ,
950
+ file_path . name ,
951
951
"FullwaveSpiceFileName:=" ,
952
- os . path . basename ( filename ) ,
952
+ file_path . name ,
953
953
"UseMultipleCores:=" ,
954
954
True ,
955
955
"NumberOfCores:=" ,
@@ -1247,7 +1247,7 @@ def assign_voltage_frequency_dependent_excitation_to_ports(self, ports, input_fi
1247
1247
----------
1248
1248
ports : list
1249
1249
List of circuit ports to assign to the frequency dependent excitation.
1250
- input_file : str
1250
+ input_file : str or :class:`pathlib.Path`
1251
1251
Path to the frequency dependent file.
1252
1252
1253
1253
Returns
@@ -1259,7 +1259,7 @@ def assign_voltage_frequency_dependent_excitation_to_ports(self, ports, input_fi
1259
1259
----------
1260
1260
>>> oDesign.UpdateSources
1261
1261
"""
1262
- if not os . path . exists (input_file ) or os . path . splitext (input_file )[ 1 ] != ".fds" :
1262
+ if not Path ( input_file ). exists () or Path (input_file ). suffix != ".fds" :
1263
1263
self .logger .error ("Introduced file is not correct. Check path and format." )
1264
1264
return False
1265
1265
@@ -1348,9 +1348,9 @@ def set_differential_pair(
1348
1348
arg .append ("Pair:=" )
1349
1349
arg .append (arg1 )
1350
1350
1351
- tmpfile1 = os . path . join (self .working_directory , generate_unique_name ("tmp" ) )
1352
- self .odesign .SaveDiffPairsToFile (tmpfile1 )
1353
- with open_file (tmpfile1 , "r" ) as fh :
1351
+ tmpfile1 = Path (self .working_directory ) / generate_unique_name ("tmp" )
1352
+ self .odesign .SaveDiffPairsToFile (str ( tmpfile1 ) )
1353
+ with open_file (str ( tmpfile1 ) , "r" ) as fh :
1354
1354
lines = fh .read ().splitlines ()
1355
1355
1356
1356
old_arg = []
@@ -1381,7 +1381,7 @@ def set_differential_pair(
1381
1381
arg .append (arg2 )
1382
1382
1383
1383
try :
1384
- os . remove (tmpfile1 )
1384
+ Path (tmpfile1 ). unlink ( )
1385
1385
except Exception : # pragma: no cover
1386
1386
self .logger .warning ("ERROR: Cannot remove temp files." )
1387
1387
@@ -1400,7 +1400,7 @@ def load_diff_pairs_from_file(self, input_file):
1400
1400
1401
1401
Parameters
1402
1402
----------
1403
- input_file : str
1403
+ input_file : str or :class:`pathlib.Path`
1404
1404
Full qualified name of the file containing the differential pairs definition.
1405
1405
1406
1406
Returns
@@ -1412,19 +1412,19 @@ def load_diff_pairs_from_file(self, input_file):
1412
1412
----------
1413
1413
>>> oDesign.LoadDiffPairsFromFile
1414
1414
"""
1415
- if not os . path . isfile (input_file ): # pragma: no cover
1415
+ if not Path (input_file ). is_file ( ): # pragma: no cover
1416
1416
raise ValueError (f"{ input_file } : The specified file could not be found." )
1417
1417
1418
1418
try :
1419
- new_file = os . path . join ( os . path . dirname ( input_file ), generate_unique_name ("temp" ) + ".txt" )
1419
+ new_file = Path ( input_file ). parent / str ( generate_unique_name ("temp" ) + ".txt" )
1420
1420
with open_file (input_file , "r" ) as file :
1421
1421
filedata = file .read ().splitlines ()
1422
1422
with io .open (new_file , "w" , newline = "\n " ) as fh :
1423
1423
for line in filedata :
1424
1424
fh .write (line + "\n " )
1425
1425
1426
- self .odesign .LoadDiffPairsFromFile (new_file )
1427
- os . remove ( new_file )
1426
+ self .odesign .LoadDiffPairsFromFile (str ( new_file ) )
1427
+ new_file . unlink ( )
1428
1428
except Exception : # pragma: no cover
1429
1429
return False
1430
1430
return True
@@ -1437,7 +1437,7 @@ def save_diff_pairs_to_file(self, output_file):
1437
1437
1438
1438
Parameters
1439
1439
----------
1440
- output_file : str
1440
+ output_file : str or :class:`pathlib.Path`
1441
1441
Full qualified name of the file to save the differential pairs definition to.
1442
1442
1443
1443
Returns
@@ -1449,17 +1449,17 @@ def save_diff_pairs_to_file(self, output_file):
1449
1449
----------
1450
1450
>>> oDesign.SaveDiffPairsToFile
1451
1451
"""
1452
- self .odesign .SaveDiffPairsToFile (output_file )
1452
+ self .odesign .SaveDiffPairsToFile (str ( output_file ) )
1453
1453
1454
- return os . path . isfile (output_file )
1454
+ return Path (output_file ). is_file ( )
1455
1455
1456
1456
@pyaedt_function_handler (netlist_file = "input_file" , datablock_name = "name" )
1457
1457
def add_netlist_datablock (self , input_file , name = None ):
1458
1458
"""Add a new netlist data block to the circuit schematic.
1459
1459
1460
1460
Parameters
1461
1461
----------
1462
- input_file : str
1462
+ input_file : str or :class:`pathlib.Path`
1463
1463
Path to the netlist file.
1464
1464
name : str, optional
1465
1465
Name of the data block.
@@ -1469,15 +1469,15 @@ def add_netlist_datablock(self, input_file, name=None):
1469
1469
bool
1470
1470
``True`` when successful, ``False`` when failed.
1471
1471
"""
1472
- if not os . path . exists (input_file ):
1472
+ if not Path ( input_file ). exists ():
1473
1473
self .logger .error ("Netlist File doesn't exists" )
1474
1474
return False
1475
1475
if not name :
1476
1476
name = generate_unique_name ("Inc" )
1477
1477
1478
1478
tmp_oModule = self .odesign .GetModule ("DataBlock" )
1479
1479
tmp_oModule .AddNetlistDataBlock (
1480
- ["NAME:DataBlock" , "name:=" , name , "filename:=" , input_file , "filelocation:=" , 0 ]
1480
+ ["NAME:DataBlock" , "name:=" , name , "filename:=" , str ( input_file ) , "filelocation:=" , 0 ]
1481
1481
)
1482
1482
return True
1483
1483
@@ -1487,41 +1487,43 @@ def browse_log_file(self, input_file=None):
1487
1487
1488
1488
Parameters
1489
1489
----------
1490
- input_file : str, optional
1490
+ input_file : str or :class:`pathlib.Path` , optional
1491
1491
File path to save the new log file to. The default is the ``pyaedt`` folder.
1492
1492
1493
1493
Returns
1494
1494
-------
1495
1495
str
1496
1496
File Path.
1497
1497
"""
1498
- if input_file and not os . path . exists ( os . path . normpath ( input_file )):
1498
+ if input_file and not Path ( input_file ). exists ( ):
1499
1499
self .logger .error ("Path does not exist." )
1500
1500
return None
1501
1501
elif not input_file :
1502
- input_file = os . path . join ( os . path . normpath ( self .working_directory ), "logfile" )
1503
- if not os . path . exists (input_file ):
1504
- os .mkdir (input_file )
1502
+ input_file = Path ( self .working_directory ) / "logfile"
1503
+ if not Path ( input_file ). exists ():
1504
+ Path ( input_file ) .mkdir ()
1505
1505
1506
- results_path = os . path . join ( os . path . normpath ( self .results_directory ), self .design_name )
1507
- results_temp_path = os . path . join (results_path , "temp" )
1506
+ results_path = Path ( self .results_directory ) / self .design_name
1507
+ results_temp_path = Path (results_path ) / "temp"
1508
1508
1509
1509
# Check if .log exist in temp folder
1510
- if os . path . exists (results_temp_path ) and search_files (results_temp_path , "*.log" ):
1510
+ if Path ( results_temp_path ). exists () and search_files (str ( results_temp_path ) , "*.log" ):
1511
1511
# Check the most recent
1512
- files = search_files (results_temp_path , "*.log" )
1513
- latest_file = max (files , key = os .path .getctime )
1514
- elif os .path .exists (results_path ) and search_files (results_path , "*.log" ):
1512
+ files = search_files (str (results_temp_path ), "*.log" )
1513
+ files = [Path (f ) for f in files ]
1514
+ latest_file = max (files , key = lambda f : str (f .stat ().st_ctime ))
1515
+ elif Path (results_path ).exists () and search_files (str (results_path ), "*.log" ):
1515
1516
# Check the most recent
1516
- files = search_files (results_path , "*.log" )
1517
- latest_file = max (files , key = os .path .getctime )
1517
+ files = search_files (str (results_path ), "*.log" )
1518
+ files = [Path (f ) for f in files ]
1519
+ latest_file = max (files , key = lambda f : str (f .stat ().st_ctime ))
1518
1520
else :
1519
1521
self .logger .error ("Design not solved" )
1520
1522
return None
1521
1523
1522
1524
shutil .copy (latest_file , input_file )
1523
- filename = os . path . basename (latest_file )
1524
- return os . path . join (input_file , filename )
1525
+ filename = Path (latest_file ). name
1526
+ return Path (input_file ) / filename
1525
1527
1526
1528
@pyaedt_function_handler ()
1527
1529
def connect_circuit_models_from_multi_zone_cutout (
@@ -1694,7 +1696,7 @@ def create_tdr_schematic_from_snp(
1694
1696
if isinstance (input_file , type (Hfss3dLayout )):
1695
1697
touchstone_path = input_file .export_touchstone ()
1696
1698
else :
1697
- touchstone_path = input_file
1699
+ touchstone_path = str ( input_file )
1698
1700
1699
1701
sub = self .modeler .components .create_touchstone_component (touchstone_path )
1700
1702
center_x = sub .location [0 ]
@@ -1834,7 +1836,7 @@ def create_lna_schematic_from_snp(
1834
1836
if isinstance (input_file , type (Hfss3dLayout )):
1835
1837
touchstone_path = input_file .export_touchstone ()
1836
1838
else :
1837
- touchstone_path = input_file
1839
+ touchstone_path = str ( input_file )
1838
1840
1839
1841
sub = self .modeler .components .create_touchstone_component (touchstone_path )
1840
1842
@@ -2089,11 +2091,11 @@ def create_ibis_schematic_from_snp(
2089
2091
if isinstance (input_file , type (Hfss3dLayout )):
2090
2092
touchstone_path = input_file .export_touchstone ()
2091
2093
else :
2092
- touchstone_path = input_file
2094
+ touchstone_path = str ( input_file )
2093
2095
2094
2096
sub = self .modeler .components .create_touchstone_component (touchstone_path )
2095
2097
return self .create_ibis_schematic_from_pins (
2096
- ibis_tx_file = ibis_tx_file ,
2098
+ ibis_tx_file = str ( ibis_tx_file ) ,
2097
2099
ibis_rx_file = ibis_rx_file ,
2098
2100
tx_buffer_name = tx_buffer_name ,
2099
2101
rx_buffer_name = rx_buffer_name ,
@@ -2441,7 +2443,7 @@ def create_schematic_from_asc_file(self, input_file, config_file=None):
2441
2443
2442
2444
Parameters
2443
2445
----------
2444
- input_file : str
2446
+ input_file : str or :class:`pathlib.Path`
2445
2447
Path to asc file.
2446
2448
config_file : str, optional
2447
2449
Path to configuration file to map components. Default is None which uses internal mapping.
@@ -2455,7 +2457,7 @@ def create_schematic_from_asc_file(self, input_file, config_file=None):
2455
2457
2456
2458
scale = 2.54e-3 / (16 / factor )
2457
2459
2458
- flag , wire_xy , symbol = self ._parse_asc_file (input_file = input_file , l_scale = scale , c_scale = scale )
2460
+ flag , wire_xy , symbol = self ._parse_asc_file (input_file = str ( input_file ) , l_scale = scale , c_scale = scale )
2459
2461
for i in flag :
2460
2462
if i [2 ] == "0" :
2461
2463
angle = 0
@@ -2470,9 +2472,7 @@ def create_schematic_from_asc_file(self, input_file, config_file=None):
2470
2472
self .modeler .schematic .create_interface_port (name = i [2 ], location = [i [0 ], i [1 ]])
2471
2473
2472
2474
if not config_file :
2473
- configuration = read_configuration_file (
2474
- os .path .join (os .path .dirname (__file__ ), "misc" , "asc_circuit_mapping.json" )
2475
- )
2475
+ configuration = read_configuration_file (str (Path (__file__ ).parent / "misc" / "asc_circuit_mapping.json" ))
2476
2476
else :
2477
2477
configuration = read_configuration_file (config_file )
2478
2478
@@ -2618,7 +2618,7 @@ def import_table(
2618
2618
2619
2619
Parameters
2620
2620
----------
2621
- input_file : str
2621
+ input_file : str or :class:`pathlib.Path`
2622
2622
Full path to the file.
2623
2623
link : bool, optional
2624
2624
Whether to link the file to the solution. The default is ``False``.
0 commit comments