Skip to content

Commit f3de8be

Browse files
feat: Move ansys-tools-path (#16)
* feat: Move ansys-tools-path * fix: Metadata * fix: Metadata * fix: metadata * fix: Code comments * test: Mark tests that require mapdl * test: Remove unneeded test * test: Fix * test: fix ci * fix: Revert * test: Separate mapdl dependant tests * fix: Rename CI * fix: Move to common folder and add latest changes * fix: Update module paths * fix: Missing module fix * fix: Comments
1 parent 2872a54 commit f3de8be

File tree

18 files changed

+2510
-6
lines changed

18 files changed

+2510
-6
lines changed

.github/workflows/cicd.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,15 @@ jobs:
3939
operating-system: ${{ matrix.os }}
4040
python-version: ${{ matrix.python-version }}
4141
whitelist-license-check: "termcolor" # Has MIT license, but it's not recognized
42-
tests:
43-
name: Run tests
42+
43+
build-tests:
44+
name: Build and Testing
4445
runs-on: ubuntu-latest
46+
needs: [smoke-tests]
47+
env:
48+
ANSYS_LOCAL: false
49+
ON_UBUNTU: true
50+
4551
steps:
4652
- name: Run tests
4753
uses: ansys/actions/tests-pytest@v10
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: MAPDL dependent tests for paths tool
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
push:
7+
tags:
8+
- "*"
9+
branches:
10+
- main
11+
12+
env:
13+
PACKAGE_NAME: ansys-tools-common
14+
MAIN_PYTHON_VERSION: 3.13
15+
16+
jobs:
17+
build-tests:
18+
name: Build and Testing
19+
runs-on: ubuntu-22.04
20+
container:
21+
image: ghcr.io/ansys/pymapdl/mapdl:v22.2-ubuntu
22+
options: "-u=0:0 --entrypoint /bin/bash"
23+
credentials:
24+
username: ${{ secrets.GH_USERNAME }}
25+
password: ${{ secrets.GH_TOKEN }}
26+
env:
27+
ANSYS_LOCAL: true
28+
ON_UBUNTU: true
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
- name: Setup Python
33+
uses: actions/setup-python@v5
34+
with:
35+
python-version: ${{ env.MAIN_PYTHON_VERSION }}
36+
- name: Install library, with test extra
37+
run: python -m pip install .[tests]
38+
39+
- name: Unit testing
40+
run: |
41+
python -m pytest -vx --cov=${{ env.PACKAGE_NAMESPACE }} --cov-report=term --cov-report=xml:.cov/coverage.xml --cov-report=html:.cov/html
42+
43+
- name: Upload coverage reports to Codecov
44+
uses: codecov/codecov-action@v5
45+
with:
46+
files: .cov/coverage.xml

doc/source/user_guide/ansys_downloader.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Ansys example downloader
66
You can use any of the functions available in the
77
to identify the path of the local Ansys installation.
88

9-
For example you can use :func:`find_ansys <ansys.tools.path.find_ansys>`
9+
For example you can use :func:`find_ansys <ansys.tools.common.path.find_ansys>`
1010
to locate the path of the latest Ansys installation available:
1111

1212
.. code:: pycon

doc/source/user_guide/ansys_tools_path.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ How to use
1111
You can use any of the functions available in the
1212
to identify the path of the local Ansys installation.
1313

14-
For example you can use :func:`find_ansys <ansys.tools.path.find_ansys>`
14+
For example you can use :func:`find_ansys <ansys.tools.common.path.find_ansys>`
1515
to locate the path of the latest Ansys installation available:
1616

1717
.. code:: pycon
1818
19-
>>> from ansys.tools.path import find_ansys
19+
>>> from ansys.tools.common.path import find_ansys
2020
>>> find_ansys()
2121
'C:/Program Files/ANSYS Inc/v211/ANSYS/bin/winx64/ansys211.exe', 21.1

pyproject.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ classifiers = [
2222
"Programming Language :: Python :: 3.12",
2323
"Programming Language :: Python :: 3.13",
2424
]
25-
dependencies = []
25+
dependencies = [
26+
"platformdirs>=3.6.0",
27+
"click>=8.1.3", # for CLI interface
28+
]
2629

2730
[project.optional-dependencies]
2831
all = [
@@ -40,6 +43,8 @@ filetransfer = [
4043

4144
tests = [
4245
"pytest==8.4.0",
46+
"pytest-cov==6.1.1",
47+
"pyfakefs==5.8.0",
4348
"hypothesis==6.135.10",
4449
"grpcio==1.73.0",
4550
]
@@ -54,6 +59,9 @@ doc = [
5459
"sphinx-jinja==2.0.2",
5560
]
5661

62+
[project.scripts]
63+
save-ansys-path = "ansys.tools.common.path.save:cli"
64+
5765
[project.urls]
5866
Source = "https://github.com/ansys/ansys-tools-common"
5967
Issues = "https://github.com/ansys/ansys-tools-common/issues"
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Copyright (C) 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
"""
24+
Tools to find/cache installed Ansys products.
25+
26+
WARNING: This is not concurrent-safe (multiple python processes might race on this data.)
27+
"""
28+
29+
from ansys.tools.common.path.path import (
30+
LOG,
31+
SETTINGS_DIR,
32+
SUPPORTED_ANSYS_VERSIONS,
33+
change_default_ansys_path, # deprecated
34+
change_default_dyna_path,
35+
change_default_mapdl_path,
36+
change_default_mechanical_path,
37+
clear_configuration,
38+
find_ansys, # deprecated
39+
find_dyna,
40+
find_mapdl,
41+
find_mechanical,
42+
get_ansys_path, # deprecated
43+
get_available_ansys_installations,
44+
get_dyna_path,
45+
get_latest_ansys_installation,
46+
get_mapdl_path,
47+
get_mechanical_path,
48+
get_saved_application_path,
49+
save_ansys_path, # deprecated
50+
save_dyna_path,
51+
save_mapdl_path,
52+
save_mechanical_path,
53+
version_from_path,
54+
)
55+
56+
__all__ = [
57+
"LOG",
58+
"SETTINGS_DIR",
59+
"SUPPORTED_ANSYS_VERSIONS",
60+
"change_default_mapdl_path",
61+
"change_default_mechanical_path",
62+
"change_default_dyna_path",
63+
"clear_configuration",
64+
"find_mapdl",
65+
"find_mechanical",
66+
"find_dyna",
67+
"get_available_ansys_installations",
68+
"get_latest_ansys_installation",
69+
"get_mapdl_path",
70+
"get_mechanical_path",
71+
"get_saved_application_path",
72+
"get_dyna_path",
73+
"save_mapdl_path",
74+
"save_mechanical_path",
75+
"save_dyna_path",
76+
"version_from_path",
77+
"change_default_ansys_path",
78+
"find_ansys",
79+
"get_ansys_path",
80+
"save_ansys_path",
81+
]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright (C) 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
"""
24+
Application plugin for ansys-tools-path.
25+
26+
This defines the interface of a plugin, which is implemented using a module.
27+
"""
28+
29+
# TODO - consider using pluggy?
30+
# TODO: Remove?
31+
32+
33+
class ApplicationPlugin:
34+
"""Class for application plugins."""
35+
36+
def is_valid_executable_path(self, exe_loc: str) -> bool:
37+
r"""Check if the executable path is valid for the application.
38+
39+
Parameters
40+
----------
41+
exe_loc : str
42+
The path to the executable file.
43+
44+
Returns
45+
-------
46+
bool
47+
``True`` if the path is valid for the application, ``False`` otherwise.
48+
"""
49+
raise Exception("This is just a base class.")
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (C) 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
"""dyna-specific logic for ansys-tools-path."""
24+
25+
26+
# TODO: Remove?
27+
def is_valid_executable_path(exe_loc: str) -> bool:
28+
"""Check if the executable path is valid for Ansys Dyna.
29+
30+
Parameters
31+
----------
32+
exe_loc : str
33+
The path to the executable file.
34+
35+
Returns
36+
-------
37+
bool
38+
``True`` if the path is valid for Ansys Dyna, ``False`` otherwise.
39+
"""
40+
# dyna paths can be anything
41+
return True
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright (C) 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
"""MAPDL-specific logic for ansys-tools-path."""
24+
25+
from pathlib import Path
26+
import re
27+
28+
29+
def is_valid_executable_path(exe_loc: str) -> bool:
30+
"""Check if the executable path is valid for Ansys MAPDL.
31+
32+
Parameters
33+
----------
34+
exe_loc : str
35+
The path to the executable file.
36+
37+
Returns
38+
-------
39+
bool
40+
``True`` if the path is valid for Ansys MAPDL, ``False`` otherwise.
41+
"""
42+
path = Path(exe_loc)
43+
return path.is_file() and re.search(r"ansys\d{3}", path.name) is not None
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (C) 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
"""Mechanical-specific logic for ansys-tools-path."""
24+
25+
import os
26+
from pathlib import Path
27+
import re
28+
29+
30+
def is_valid_executable_path(exe_loc: str) -> bool:
31+
"""Check if the executable path is valid for Ansys Mechanical.
32+
33+
Parameters
34+
----------
35+
exe_loc : str
36+
The path to the executable file.
37+
38+
Returns
39+
-------
40+
bool
41+
``True`` if the path is valid for Ansys Mechanical, ``False`` otherwise.
42+
"""
43+
path = Path(exe_loc)
44+
if os.name == "nt": # pragma: no cover
45+
return path.is_file() and re.search("AnsysWBU.exe", path.name, re.IGNORECASE) is not None
46+
return path.is_file() and re.search(r"\.workbench$", path.name) is not None

0 commit comments

Comments
 (0)