From 4fd8db542efbbe4bbfe983616dca3a996c1a8cfc Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Mon, 15 Apr 2024 11:51:23 -0500 Subject: [PATCH 1/5] pre-commit changes --- src/ansys/mechanical/core/run.py | 62 ++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/src/ansys/mechanical/core/run.py b/src/ansys/mechanical/core/run.py index 9ee5ec443..058f9825a 100644 --- a/src/ansys/mechanical/core/run.py +++ b/src/ansys/mechanical/core/run.py @@ -27,6 +27,7 @@ import os import sys import typing +from typing import Optional import warnings import ansys.tools.path as atp @@ -38,6 +39,56 @@ # 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 @@ -179,16 +230,7 @@ def cli( if input_script: raise Exception("Cannot open in server mode with an input script.") - if not revision: - exe = atp.get_mechanical_path() # check for saved mechanical path - if exe: - version = atp.version_from_path("mechanical", exe) # version is already int here - else: - exe, _version = atp.find_mechanical() - version = int(_version * 10) - else: - exe, _version = atp.find_mechanical(version=revision) - version = int(_version * 10) + version, exe = __version_resolve(revision) version_name = atp.SUPPORTED_ANSYS_VERSIONS[version] From 772c3bc0d65541203198cb560fcb922f6bcd89ae Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Mon, 15 Apr 2024 23:26:32 -0500 Subject: [PATCH 2/5] use updated get_mechanical --- src/ansys/mechanical/core/run.py | 57 +++----------------------------- 1 file changed, 5 insertions(+), 52 deletions(-) diff --git a/src/ansys/mechanical/core/run.py b/src/ansys/mechanical/core/run.py index 058f9825a..843b54f99 100644 --- a/src/ansys/mechanical/core/run.py +++ b/src/ansys/mechanical/core/run.py @@ -27,7 +27,6 @@ import os import sys import typing -from typing import Optional import warnings import ansys.tools.path as atp @@ -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 @@ -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] From 5f4d0c2dedc0726b133f0a474e439676e19718cb Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot Date: Tue, 16 Apr 2024 13:10:28 +0000 Subject: [PATCH 3/5] Adding changelog entry: 707.added.md --- doc/changelog.d/707.added.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/707.added.md diff --git a/doc/changelog.d/707.added.md b/doc/changelog.d/707.added.md new file mode 100644 index 000000000..869ee81f7 --- /dev/null +++ b/doc/changelog.d/707.added.md @@ -0,0 +1 @@ +Feat: Update `get_mechanical_path` \ No newline at end of file From 6d6673bb0c6151b30c3587361fb6ee3d7b67f2ad Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Tue, 16 Apr 2024 08:56:30 -0500 Subject: [PATCH 4/5] no need of exe exception --- src/ansys/mechanical/core/run.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/ansys/mechanical/core/run.py b/src/ansys/mechanical/core/run.py index 843b54f99..1ab27152d 100644 --- a/src/ansys/mechanical/core/run.py +++ b/src/ansys/mechanical/core/run.py @@ -180,10 +180,7 @@ def cli( raise Exception("Cannot open in server mode with an input script.") 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 = atp.version_from_path("mechanical", exe) version_name = atp.SUPPORTED_ANSYS_VERSIONS[version] From 8bc2180c86c00518794d961efc0cc7b9e6763d86 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Tue, 16 Apr 2024 14:12:49 -0500 Subject: [PATCH 5/5] test coverage --- codecov.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codecov.yml b/codecov.yml index 72687f0e0..2be9e4adf 100644 --- a/codecov.yml +++ b/codecov.yml @@ -8,7 +8,7 @@ coverage: patch: default: # basic - target: 80% + target: 90% if_not_found: success - if_ci_failed: error + if_ci_failed: success if_no_uploads: error