ansys / pymechanical-env

Repository for loading environment variables when using PyMechanical embedding instances in Linux
MIT License
1 stars 0 forks source link

ansys/tools/path/path.py #70

Open Cpp87 opened 1 month ago

Cpp87 commented 1 month ago

🔍 Before submitting the issue

🐞 Description of the bug

When running the command mechanical-env -r 232 python -v or any other command, mechanical-env crashes because it cannot find the version

I run on a linux cluster where ansys is installed in /share/...

There should be a speaking error, telling that the version cannot be found and telling me where the search took place. The root cause of the error is probably your selection of LINUX_DEFAULT_DIRS = [["/", "usr", "ansys_inc"], ["/", "ansys_inc"], ["/", "install", "ansys_inc"]] where my folder is not present.

But I cannot provide a different Default, so a feature like mechanical-env -r 232 --DEFAULT_LINUX_PATH=/share/my/custom/path is desirable

📝 Steps to reproduce

mechanical-env -r 232 python -v or any other command

💻 Which operating system are you using?

Linux

📀 Which ANSYS version are you using?

232

🐍 Which Python version are you using?

3.10

📦 Installed packages

ansys-api-mechanical==0.1.0
ansys-api-platform-instancemanagement==1.0.0
ansys-dpf-core==0.12.2
ansys-mechanical-core==0.10.2
ansys-mechanical-env==0.1.6
ansys-platform-instancemanagement==1.1.2
ansys-pythonnet==3.1.0rc3
ansys-tools-path==0.3.1
appdirs==1.4.4
astroid==3.2.3
attrs @ file:///croot/attrs_1668696182826/work
cachetools==5.3.2
certifi @ file:///croot/certifi_1720453481653/work/certifi
cffi==1.15.1
charset-normalizer==3.3.2
click==8.1.7
clr-loader==0.2.6
coverage @ file:///croot/coverage_1680092710405/work
dill==0.3.7
exceptiongroup @ file:///croot/exceptiongroup_1668714342571/work
flake8 @ file:///croot/flake8_1674581792275/work
flit_core @ file:///opt/conda/conda-bld/flit-core_1644941570762/work/source/flit_core
google-api-core==2.17.1
google-api-python-client==2.118.0
google-auth==2.27.0
google-auth-httplib2==0.2.0
googleapis-common-protos==1.62.0
grpcio==1.57.0
httplib2==0.22.0
idna==3.6
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1648562408262/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
isort==5.13.2
mccabe @ file:///opt/conda/conda-bld/mccabe_1644221741721/work
numpy==2.0.0
packaging @ file:///croot/packaging_1693575174725/work
platformdirs==3.10.0
pluggy==1.5.0
protobuf==3.20.3
psutil==5.9.8
py @ file:///opt/conda/conda-bld/py_1644396412707/work
pyasn1==0.5.1
pyasn1-modules==0.3.0
pycodestyle @ file:///croot/pycodestyle_1674267221883/work
pycparser==2.21
pyflakes @ file:///croot/pyflakes_1674165128613/work
pylint==3.2.5
pyparsing==3.1.1
pytest==8.2.2
pytest-cov==5.0.0
pytest-print==1.0.0
PyYAML==6.0.1
requests==2.31.0
rsa==4.9
scipy==1.14.0
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work
tomlkit==0.12.3
tqdm==4.66.1
typing_extensions @ file:///croot/typing_extensions_1690297465030/work
uritemplate==4.1.1
urllib3==2.2.0
zipp @ file:///croot/zipp_1672387121353/work
Cpp87 commented 1 month ago

This is the error message

.../lib/python3.10/site-packages/ansys/tools/path/path.py", line 862, in _mechanical_version_from_path matches = re.findall(r"v(\d\d\d)", path.replace("\", "/"), re.IGNORECASE) AttributeError: 'NoneType' object has no attribute 'replace' Error running the find-mechanical.

dipinknair commented 1 month ago

Hi @Cpp87 Thanks for opening this issue. you can always use save-ansys-path --name mechanical /share/my/custom/path/ansys_inc/v241/aisol/.workbench then you will be able to do use find-mechanical and hence mechanical-env. If the path is saved then you do not need to specify version with mechanical-env command.

as you suggested, having an option to input default directory is a very good idea. changing default directory should happen with ansys.tools.path.

Cpp87 commented 1 month ago

Thank you for the answer. I tried to follow your recommendation but calling save-ansys-path in any way yields bash: save-ansys-path: command not found

In which pip-package is this functionality?

dipinknair commented 1 month ago

This comes with with ansys.tools.path which is a dependency package for pymechanical. I can see it in your pip freeze list.

Cpp87 commented 1 month ago

Thank you very much. Somehow I had to re-build my environment and now I can work save-ansys-path.

Can you still improve the error message/handling?

The kernel should crash with such a low-level message. You could add a try/except and give some more info to the end-user like this try: ... except Exception as ex: raise RuntimeError(f'could not find ansys version among {LINUX_DEFAULT_DIRS }') from ex