Skip to content

Commit

Permalink
use updated get_mechanical
Browse files Browse the repository at this point in the history
  • Loading branch information
dipinknair committed Apr 16, 2024
1 parent 4fd8db5 commit 772c3bc
Showing 1 changed file with 5 additions and 52 deletions.
57 changes: 5 additions & 52 deletions src/ansys/mechanical/core/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import os
import sys
import typing
from typing import Optional
import warnings

import ansys.tools.path as atp
Expand All @@ -39,56 +38,6 @@
# TODO - add timeout


def __version_resolve(revision: Optional[int]):
"""Resolve finding different Mechanical versions.
Returns Mechanical version and location
Steps:
1. Checks for saved version path in config.txt using get_mechanical_path()
2. If saved version path and requested do not match, find requested version path in system
3. If no saved version path in config.txt, then find mechanical path in system
"""
if revision is None:
print("Finding Mechanical path ...")
else:
print(f"Finding Mechanical path for [{revision}] ...")

# TODO if get_mechanical_path supports getting version path from config file
# currently get_mechanical_path reads config file only if version arg is None
# exe = atp.get_mechanical_path() if revision is None else atp.get_mechanical_path(revision)
exe = atp.get_mechanical_path() # gets path from saved
if exe:
_version = atp.version_from_path("mechanical", exe)
if revision and _version != revision:
print(
f"Saved Mechanical version [{_version}] does not match with requested [{revision}]"
)
print(f"Finding requested Mechanical version [{revision}] ...")
exe, _version = atp.find_mechanical(version=revision)
else:
exe, _version = atp.find_mechanical(version=revision)

# find_mechanical returns empty string if not able to find Mechanical in system or saved path
if _version != "":
print(f"Mechanical [{_version}] found at [{exe}]")
else:
print("Save Mechanical path using ``save-ansys-path`` if not installed in default location")
if revision is not None:
raise Exception(
f"Cannot find requested Mechanical [{revision}] in system or saved path."
)
else:
raise Exception("Cannot find requested Mechanical in system or saved path.")

# TODO find_mechanical and version_from_path returns different format
# making this coherent as 241 int will be less confusing
int_version = int(str(_version).replace(".", ""))

return int_version, exe


async def _read_and_display(cmd, env, do_display: bool):
"""Read command's stdout and stderr and display them as they are processed."""
# start process
Expand Down Expand Up @@ -230,7 +179,11 @@ def cli(
if input_script:
raise Exception("Cannot open in server mode with an input script.")

version, exe = __version_resolve(revision)
exe = atp.get_mechanical_path(allow_input=False, version=revision)
if exe is not None:
version = atp.version_from_path("mechanical", exe)
else:
raise Exception("No Mechanical found")

version_name = atp.SUPPORTED_ANSYS_VERSIONS[version]

Expand Down

0 comments on commit 772c3bc

Please sign in to comment.