4141from abc import ABC
4242import ctypes
4343from typing import TYPE_CHECKING , Union
44+ from pathlib import Path
4445
4546import psutil
4647
6869def _get_dll_path (name , ansys_path = None ):
6970 """Helper function to get the right dll path for Linux or Windows"""
7071 ISPOSIX = os .name == "posix"
71- ANSYS_INSTALL = core .misc .get_ansys_path (ansys_path )
72+ ANSYS_INSTALL = Path ( core .misc .get_ansys_path (ansys_path ) )
7273 api_path = load_api ._get_path_in_install ()
7374 if api_path is None :
7475 raise ImportError (f"Could not find API path in install." )
75- SUB_FOLDERS = os . path . join ( ANSYS_INSTALL , api_path )
76+ SUB_FOLDERS = ANSYS_INSTALL / api_path
7677 if ISPOSIX :
7778 name = "lib" + name
78- return os . path . join ( SUB_FOLDERS , name )
79+ return SUB_FOLDERS / name
7980
8081
8182def check_valid_ip (ip ):
@@ -92,18 +93,19 @@ def check_valid_ip(ip):
9293def _verify_ansys_path_is_valid (ansys_path , executable , path_in_install = None ):
9394 if path_in_install is None :
9495 path_in_install = load_api ._get_path_in_install ()
95- if os .path .isdir (f"{ ansys_path } /{ path_in_install } " ):
96- dpf_run_dir = f"{ ansys_path } /{ path_in_install } "
96+ ansys_path = Path (ansys_path )
97+ if ansys_path .joinpath (path_in_install ).is_dir ():
98+ dpf_run_dir = ansys_path / path_in_install
9799 else :
98- dpf_run_dir = f" { ansys_path } "
99- if not os . path . isdir ( dpf_run_dir ):
100+ dpf_run_dir = ansys_path
101+ if not dpf_run_dir . is_dir ( ):
100102 raise NotADirectoryError (
101103 f'Invalid ansys path at "{ ansys_path } ". '
102104 "Unable to locate the directory containing DPF at "
103105 f'"{ dpf_run_dir } "'
104106 )
105107 else :
106- if not os . path . exists ( os . path . join ( dpf_run_dir , executable )):
108+ if not dpf_run_dir . joinpath ( executable ). exists ( ):
107109 raise FileNotFoundError (
108110 f'DPF executable not found at "{ dpf_run_dir } ". '
109111 f'Unable to locate the executable "{ executable } "'
@@ -117,7 +119,7 @@ def _run_launch_server_process(
117119 bShell = False
118120 if docker_config .use_docker :
119121 docker_server_port = int (os .environ .get ("DOCKER_SERVER_PORT" , port ))
120- dpf_run_dir = os . getcwd ()
122+ dpf_run_dir = Path . cwd ()
121123 if os .name == "posix" :
122124 bShell = True
123125 run_cmd = docker_config .docker_run_cmd_command (docker_server_port , port )
@@ -135,7 +137,7 @@ def _run_launch_server_process(
135137 path_in_install = load_api ._get_path_in_install (internal_folder = "bin" )
136138 dpf_run_dir = _verify_ansys_path_is_valid (ansys_path , executable , path_in_install )
137139
138- old_dir = os . getcwd ()
140+ old_dir = Path . cwd ()
139141 os .chdir (dpf_run_dir )
140142 if not bShell :
141143 process = subprocess .Popen (run_cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
@@ -940,11 +942,11 @@ def __init__(
940942 name = "DataProcessingCore"
941943 path = _get_dll_path (name , ansys_path )
942944 try :
943- data_processing_core_load_api (path , "common" )
945+ data_processing_core_load_api (str ( path ) , "common" )
944946 except Exception as e :
945- if not os . path .isdir ( os . path . dirname ( path ) ):
947+ if not path .parent . is_dir ( ):
946948 raise NotADirectoryError (
947- f"DPF directory not found at { os . path .dirname ( path ) } "
949+ f"DPF directory not found at { path .parent } "
948950 f"Unable to locate the following file: { path } "
949951 )
950952 raise e
0 commit comments