2020# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222# SOFTWARE.
23- # Extension template to help get started
23+
2424from dataclasses import dataclass
2525import json
2626import os
3535
3636from pyedb import Edb
3737import toml
38- import tomli
3938
4039import ansys .aedt .core
4140from ansys .aedt .core .examples .downloads import download_file
4544from ansys .aedt .core .extensions .misc import get_port
4645from ansys .aedt .core .extensions .misc import get_process_id
4746from ansys .aedt .core .extensions .misc import is_student
47+ from ansys .aedt .core .generic .file_utils import read_json
48+ from ansys .aedt .core .generic .file_utils import read_toml
49+ from ansys .aedt .core .generic .file_utils import write_configuration_file
4850from ansys .aedt .core .generic .settings import settings
4951from ansys .aedt .core .internal .errors import AEDTRuntimeError
5052
@@ -89,8 +91,7 @@ def __init__(self, data):
8991
9092 def __init__ (self , file_path : Union [Path , str ]):
9193 self ._file_path = Path (file_path )
92- with open (self ._file_path , "rb" ) as f :
93- data = tomli .load (f )
94+ data = read_toml (self ._file_path )
9495 self .title = data ["title" ]
9596 self .version = data ["version" ]
9697 self .layout_file = Path (data ["layout_file" ])
@@ -101,7 +102,8 @@ def __init__(self, file_path: Union[Path, str]):
101102
102103 supplementary_json = data .get ("supplementary_json" , "" )
103104 if supplementary_json != "" :
104- self .supplementary_json = str (self ._file_path .with_name (supplementary_json ))
105+ Path (supplementary_json )
106+ self .supplementary_json = str (self ._file_path .with_name (Path (supplementary_json ).name ))
105107 else : # pragma: no cover
106108 self .supplementary_json = ""
107109 self .check ()
@@ -265,8 +267,8 @@ def call_back_load(self):
265267
266268 if self .tk_vars .load_overwrite .get ():
267269 desktop = ansys .aedt .core .Desktop (
268- new_desktop_session = False ,
269- specified_version = VERSION ,
270+ new_desktop = False ,
271+ version = VERSION ,
270272 port = PORT ,
271273 aedt_process_id = AEDT_PROCESS_ID ,
272274 student_version = IS_STUDENT ,
@@ -443,32 +445,36 @@ def load_config(config, working_directory, overwrite):
443445
444446 @staticmethod
445447 def export_template_config (working_directory ):
448+ export_directory = Path (working_directory )
446449 msg = []
450+
451+ # Read examples serdes
447452 example_master_config = Path (__file__ ).parent / "resources" / "configure_layout" / "example_serdes.toml"
448- example_slave_config = (
449- Path (__file__ ).parent / "resources" / "configure_layout" / "example_serdes_supplementary.json"
450- )
451- export_directory = Path (working_directory )
452- with open (example_master_config , "r" , encoding = "utf-8" ) as file :
453- content = file .read ()
453+ content = read_toml (example_master_config )
454+ content ["version" ] = VERSION
454455
455- example_edb = download_file (source = "edb/ANSYS_SVP_V1_1.aedb" , local_path = working_directory )
456+ # Not download in tests
457+ if "PYTEST_CURRENT_TEST" not in os .environ : # pragma: no cover
458+ example_edb = download_file (source = "edb/ANSYS_SVP_V1_1.aedb" , local_path = export_directory )
459+ else :
460+ example_edb = export_directory / "ANSYS_SVP_V1_1.aedb"
461+ content ["layout_file" ] = str (example_edb )
456462
457463 if bool (example_edb ):
458464 msg .append (f"Example Edb is downloaded to { example_edb } " )
459465 else : # pragma: no cover
460466 msg .append ("Failed to download example board." )
461467
462- with open (export_directory / example_master_config .name , "w" , encoding = "utf-8" ) as f :
463- f .write (content )
464- msg .append (f"Example master configure file is copied to { export_directory / example_master_config .name } " )
468+ example_config = Path (__file__ ).parent / "resources" / "configure_layout" / "example_serdes_supplementary.json"
469+ example_config_content = read_json (example_config )
470+ example_path = working_directory / "example_serdes_supplementary.json"
471+ write_configuration_file (example_config_content , example_path )
472+ msg .append (f"Example configure file is copied to { export_directory / example_config .name } " )
465473
466- with open (example_slave_config , "r" , encoding = "utf-8" ) as file :
467- content = file .read ()
468- with open (export_directory / example_slave_config .name , "w" , encoding = "utf-8" ) as f :
469- f .write (content )
470- msg .append (f"Example slave configure file is copied to { export_directory / example_slave_config .name } " )
474+ content ["supplementary_json" ] = str (example_path )
471475
476+ write_configuration_file (content , export_directory / "example_serdes.toml" )
477+ msg .append (f"Example master configure file is copied to { export_directory / example_master_config .name } " )
472478 return True , "\n \n " .join (msg )
473479
474480 @staticmethod
0 commit comments