2525import subprocess
2626import sys
2727import time
28+ from typing import Literal
2829
2930from Pyro5 .errors import CommunicationError
3031from ansys .tools .path import get_available_ansys_installations
@@ -172,7 +173,7 @@ def launch_freeflow( # pragma: no cover
172173 )
173174
174175 if freeflow_exe is None :
175- freeflow_exe = _find_executable (product_name = "Freeflow " , version = freeflow_version )
176+ freeflow_exe = _find_executable (product_name = "FreeFlow " , version = freeflow_version )
176177 else :
177178 if isinstance (freeflow_exe , str ):
178179 freeflow_exe = Path (freeflow_exe )
@@ -189,7 +190,7 @@ def launch_freeflow( # pragma: no cover
189190
190191 # Freeflow.exe call returned to soon, something happen
191192 if rocky_process .returncode is not None :
192- raise FreeflowLaunchError (f"Error launching Freeflow :\n { ' ' .join (cmd )} " )
193+ raise FreeflowLaunchError (f"Error launching FreeFlow :\n { ' ' .join (cmd )} " )
193194
194195 client = connect (port = server_port )
195196 client ._process = rocky_process
@@ -224,94 +225,17 @@ def _is_port_busy(port: int, timeout: int = 10) -> bool:
224225
225226
226227def _find_executable (
227- product_name : str ,
228- version : int | None ,
229- ) -> Path :
230- """
231- This function will search for the Rocky/Freeflow executable
232-
233- Parameters
234- ----------
235- product_name:
236- The name of the product (Rocky or Freeflow)
237- version:
238- The version of the executable
239-
240- Returns
241- -------
242- Path
243- The Path to the executable
244- """
245- if sys .platform == "win32" :
246- if version is not None :
247- if product_name == "Rocky" or version >= 261 :
248- version = f"{ version // 10 } .{ version % 10 } .0"
249- else :
250- version = f"{ version // 10 } .{ version % 10 } .0-BETA"
251-
252- executable = _get_exec_using_winreg (product_name = product_name , version = version )
253- else : # pragma: no cover
254- executable = _get_exec_using_tools_path (
255- product_name = product_name , version = version
256- )
257-
258- return executable
259-
260-
261- def _get_exec_using_winreg (
262- product_name : str ,
263- version : str | None = None ,
264- ) -> Path :
265- """
266- This function will search for the Rocky/Freeflow executable using the
267- Windows registry.
268-
269- Parameters
270- ----------
271- product_name:
272- The name of the product (Rocky or Freeflow)
273- version:
274- The version of the executable
275-
276- Returns
277- -------
278- Path
279- The Path to the executable
280- """
281- import winreg
282-
283- product_reg_path = rf"SOFTWARE\{ COMPANY } \{ product_name } "
284-
285- try :
286- if version is None :
287- # If no version is defined, the default is the 'current_version' attribute
288- with winreg .OpenKey (winreg .HKEY_LOCAL_MACHINE , product_reg_path ) as wr_key :
289- version , _ = winreg .QueryValueEx (wr_key , "current_version" )
290-
291- version_reg_path = rf"{ product_reg_path } \{ version } "
292- with winreg .OpenKey (winreg .HKEY_LOCAL_MACHINE , version_reg_path ) as wr_key :
293- executable_str , _ = winreg .QueryValueEx (wr_key , "local_executable" )
294- return Path (executable_str )
295- except FileNotFoundError :
296- raise FileNotFoundError (
297- f"Local executable not found for { product_name } { version } ."
298- )
299-
300-
301- def _get_exec_using_tools_path ( # pragma: no cover
302- product_name : str ,
228+ product_name : Literal ["Rocky" , "FreeFlow" ],
303229 version : int | None = None ,
304230) -> Path | None :
305231 """
306- This function will search for the Rocky/Freeflow executable using the
307- ansys-tools-path module. Currently, we are using this approach only
308- for Linux, since the ansys-tools-path depends on the AWP_ROOT variable,
309- which may not be defined in Rocky standalone for Windows.
232+ This function will search for the Rocky/FreeFlow executable using the
233+ ansys-tools-path module.
310234
311235 Parameters
312236 ----------
313237 product_name:
314- The name of the product (Rocky or Freeflow
238+ The name of the product (Rocky or FreeFlow)
315239 version:
316240 The version of the executable
317241
@@ -320,26 +244,32 @@ def _get_exec_using_tools_path( # pragma: no cover
320244 Path
321245 The Path to the executable
322246 """
247+
323248 ansys_installations = get_available_ansys_installations ()
249+ executable : Path | None = None
250+
251+ def get_platform_executable_path (
252+ installation_path : str , product_name : Literal ["Rocky" , "FreeFlow" ]
253+ ) -> Path :
254+ """
255+ Get the executable path for the current platform (Windows or Linux).
256+ """
257+ if sys .platform == "win32" :
258+ return Path (installation_path ) / f"{ product_name } /bin/{ product_name } .exe"
259+ else : # pragma: no cover
260+ return Path (installation_path ) / f"{ product_name .lower ()} /bin/{ product_name } "
324261
325262 if version is None :
326263 for installation in sorted (ansys_installations , reverse = True ):
327- executable = (
328- Path (ansys_installations [installation ])
329- / f"{ product_name .lower ()} /bin/{ product_name } "
264+ executable = get_platform_executable_path (
265+ ansys_installations [installation ], product_name
330266 )
267+
331268 if executable .is_file () and installation >= MINIMUM_ANSYS_VERSION_SUPPORTED :
332269 break
333- else :
334- return
335270 else :
336271 if version in ansys_installations :
337272 ansys_installation = ansys_installations .get (version )
338- else :
339- raise FileNotFoundError (f"{ product_name } executable is not found." )
340-
341- executable = (
342- Path (ansys_installation ) / f"{ product_name .lower ()} /bin/{ product_name } "
343- )
273+ executable = get_platform_executable_path (ansys_installation , product_name )
344274
345275 return executable
0 commit comments