ansys-mechanical-core 0.11.12__py3-none-any.whl → 0.11.14__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. ansys/mechanical/core/__init__.py +0 -1
  2. ansys/mechanical/core/_version.py +48 -48
  3. ansys/mechanical/core/embedding/app.py +681 -610
  4. ansys/mechanical/core/embedding/background.py +11 -2
  5. ansys/mechanical/core/embedding/enum_importer.py +0 -1
  6. ansys/mechanical/core/embedding/global_importer.py +50 -0
  7. ansys/mechanical/core/embedding/imports.py +30 -58
  8. ansys/mechanical/core/embedding/initializer.py +6 -4
  9. ansys/mechanical/core/embedding/logger/__init__.py +219 -219
  10. ansys/mechanical/core/embedding/messages.py +190 -0
  11. ansys/mechanical/core/embedding/resolver.py +48 -41
  12. ansys/mechanical/core/embedding/rpc/__init__.py +36 -0
  13. ansys/mechanical/core/embedding/rpc/client.py +259 -0
  14. ansys/mechanical/core/embedding/rpc/server.py +403 -0
  15. ansys/mechanical/core/embedding/rpc/utils.py +118 -0
  16. ansys/mechanical/core/embedding/runtime.py +22 -0
  17. ansys/mechanical/core/embedding/transaction.py +51 -0
  18. ansys/mechanical/core/feature_flags.py +1 -0
  19. ansys/mechanical/core/ide_config.py +226 -212
  20. ansys/mechanical/core/mechanical.py +2399 -2324
  21. ansys/mechanical/core/misc.py +176 -176
  22. ansys/mechanical/core/pool.py +712 -712
  23. ansys/mechanical/core/run.py +321 -321
  24. {ansys_mechanical_core-0.11.12.dist-info → ansys_mechanical_core-0.11.14.dist-info}/METADATA +40 -27
  25. ansys_mechanical_core-0.11.14.dist-info/RECORD +52 -0
  26. {ansys_mechanical_core-0.11.12.dist-info → ansys_mechanical_core-0.11.14.dist-info}/WHEEL +1 -1
  27. ansys_mechanical_core-0.11.12.dist-info/RECORD +0 -45
  28. {ansys_mechanical_core-0.11.12.dist-info → ansys_mechanical_core-0.11.14.dist-info}/entry_points.txt +0 -0
  29. {ansys_mechanical_core-0.11.12.dist-info → ansys_mechanical_core-0.11.14.dist-info/licenses}/LICENSE +0 -0
@@ -1,212 +1,226 @@
1
- # Copyright (C) 2022 - 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
- """Convenience CLI to run mechanical."""
24
-
25
- import json
26
- import os
27
- from pathlib import Path
28
- import re
29
- import site
30
- import sys
31
-
32
- import ansys.tools.path as atp
33
- import click
34
-
35
-
36
- def get_stubs_location():
37
- """Find the ansys-mechanical-stubs installation location in site-packages.
38
-
39
- Returns
40
- -------
41
- pathlib.Path
42
- The path to the ansys-mechanical-stubs installation in site-packages.
43
- """
44
- site_packages = site.getsitepackages()
45
- prefix_path = sys.prefix.replace("\\", "\\\\")
46
- site_packages_regex = re.compile(f"{prefix_path}.*site-packages$")
47
- site_packages_paths = list(filter(site_packages_regex.match, site_packages))
48
-
49
- if len(site_packages_paths) == 1:
50
- # Get the stubs location
51
- stubs_location = Path(site_packages_paths[0]) / "ansys" / "mechanical" / "stubs"
52
- return stubs_location
53
-
54
- raise Exception("Could not retrieve the location of the ansys-mechanical-stubs package.")
55
-
56
-
57
- def get_stubs_versions(stubs_location: Path):
58
- """Retrieve the revision numbers in ansys-mechanical-stubs.
59
-
60
- Parameters
61
- ----------
62
- pathlib.Path
63
- The path to the ansys-mechanical-stubs installation in site-packages.
64
-
65
- Returns
66
- -------
67
- list
68
- The list containing minimum and maximum versions in the ansys-mechanical-stubs package.
69
- """
70
- # Get revision numbers in stubs folder
71
- revns = [
72
- int(revision[1:])
73
- for revision in os.listdir(stubs_location)
74
- if os.path.isdir(os.path.join(stubs_location, revision)) and revision.startswith("v")
75
- ]
76
- return revns
77
-
78
-
79
- def _vscode_impl(
80
- target: str = "user",
81
- revision: int = None,
82
- ):
83
- """Get the IDE configuration for autocomplete in VS Code.
84
-
85
- Parameters
86
- ----------
87
- target: str
88
- The type of settings to update. Either "user" or "workspace" in VS Code.
89
- By default, it's ``user``.
90
- revision: int
91
- The Mechanical revision number. For example, "251".
92
- If unspecified, it finds the default Mechanical version from ansys-tools-path.
93
- """
94
- # Update the user or workspace settings
95
- if target == "user":
96
- # Get the path to the user's settings.json file depending on the platform
97
- if "win" in sys.platform:
98
- settings_json = (
99
- Path(os.environ.get("APPDATA")) / "Code" / "User" / "settings.json"
100
- ) # pragma: no cover
101
- elif "lin" in sys.platform:
102
- settings_json = (
103
- Path(os.environ.get("HOME")) / ".config" / "Code" / "User" / "settings.json"
104
- )
105
- elif target == "workspace":
106
- # Get the current working directory
107
- current_dir = Path.cwd()
108
- # Get the path to the settings.json file based on the git root & .vscode folder
109
- settings_json = current_dir / ".vscode" / "settings.json"
110
-
111
- # Location where the stubs are installed -> .venv/Lib/site-packages, for example
112
- stubs_location = get_stubs_location() / f"v{revision}"
113
-
114
- # The settings to add to settings.json for autocomplete to work
115
- settings_json_data = {
116
- "python.autoComplete.extraPaths": [str(stubs_location)],
117
- "python.analysis.extraPaths": [str(stubs_location)],
118
- }
119
- # Pretty print dictionary
120
- pretty_dict = json.dumps(settings_json_data, indent=4)
121
-
122
- print(f"Update {settings_json} with the following information:\n")
123
-
124
- if target == "workspace":
125
- print(
126
- "Note: Please ensure the .vscode folder is in the root of your project or repository.\n"
127
- )
128
-
129
- print(pretty_dict)
130
-
131
-
132
- def _cli_impl(
133
- ide: str = "vscode",
134
- target: str = "user",
135
- revision: int = None,
136
- ):
137
- """Provide the user with the path to the settings.json file and IDE settings.
138
-
139
- Parameters
140
- ----------
141
- ide: str
142
- The IDE to set up autocomplete settings. By default, it's ``vscode``.
143
- target: str
144
- The type of settings to update. Either "user" or "workspace" in VS Code.
145
- By default, it's ``user``.
146
- revision: int
147
- The Mechanical revision number. For example, "251".
148
- If unspecified, it finds the default Mechanical version from ansys-tools-path.
149
- """
150
- # Get the ansys-mechanical-stubs install location
151
- stubs_location = get_stubs_location()
152
- # Get all revision numbers available in ansys-mechanical-stubs
153
- revns = get_stubs_versions(stubs_location)
154
- # Check the IDE and raise an exception if it's not VS Code
155
- if revision < min(revns) or revision > max(revns):
156
- raise Exception(f"PyMechanical Stubs are not available for {revision}")
157
- elif ide != "vscode":
158
- raise Exception(f"{ide} is not supported at the moment.")
159
- else:
160
- return _vscode_impl(target, revision)
161
-
162
-
163
- @click.command()
164
- @click.help_option("--help", "-h")
165
- @click.option(
166
- "--ide",
167
- default="vscode",
168
- type=str,
169
- help="The IDE being used. By default, it's ``vscode``.",
170
- )
171
- @click.option(
172
- "--target",
173
- default="user",
174
- type=str,
175
- help="The type of settings to update - either ``user`` or ``workspace`` settings in VS Code.",
176
- )
177
- @click.option(
178
- "--revision",
179
- default=None,
180
- type=int,
181
- help='The Mechanical revision number, e.g. "251" or "242". If unspecified,\
182
- it finds and uses the default version from ansys-tools-path.',
183
- )
184
- def cli(ide: str, target: str, revision: int) -> None:
185
- """CLI tool to update settings.json files for autocomplete with ansys-mechanical-stubs.
186
-
187
- Parameters
188
- ----------
189
- ide: str
190
- The IDE to set up autocomplete settings. By default, it's ``vscode``.
191
- target: str
192
- The type of settings to update. Either "user" or "workspace" in VS Code.
193
- By default, it's ``user``.
194
- revision: int
195
- The Mechanical revision number. For example, "251".
196
- If unspecified, it finds the default Mechanical version from ansys-tools-path.
197
-
198
- Usage
199
- -----
200
- The following example demonstrates the main use of this tool:
201
-
202
- $ ansys-mechanical-ideconfig --ide vscode --target user --revision 251
203
-
204
- """
205
- exe = atp.get_mechanical_path(allow_input=False, version=revision)
206
- version = atp.version_from_path("mechanical", exe)
207
-
208
- return _cli_impl(
209
- ide,
210
- target,
211
- version,
212
- )
1
+ # Copyright (C) 2022 - 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
+ """Convenience CLI to run mechanical."""
24
+
25
+ import json
26
+ import os
27
+ from pathlib import Path
28
+ import re
29
+ import site
30
+ import sys
31
+ import warnings
32
+
33
+ import ansys.tools.path as atp
34
+ import click
35
+
36
+
37
+ def get_stubs_location():
38
+ """Find the ansys-mechanical-stubs installation location in site-packages.
39
+
40
+ Returns
41
+ -------
42
+ pathlib.Path
43
+ The path to the ansys-mechanical-stubs installation in site-packages.
44
+ """
45
+ site_packages = site.getsitepackages()
46
+ prefix_path = sys.prefix.replace("\\", "\\\\")
47
+ site_packages_regex = re.compile(f"{prefix_path}.*site-packages$")
48
+ site_packages_paths = list(filter(site_packages_regex.match, site_packages))
49
+
50
+ if len(site_packages_paths) == 1:
51
+ # Get the stubs location
52
+ stubs_location = Path(site_packages_paths[0]) / "ansys" / "mechanical" / "stubs"
53
+ return stubs_location
54
+
55
+ raise Exception("Could not retrieve the location of the ansys-mechanical-stubs package.")
56
+
57
+
58
+ def get_stubs_versions(stubs_location: Path):
59
+ """Retrieve the revision numbers in ansys-mechanical-stubs.
60
+
61
+ Parameters
62
+ ----------
63
+ pathlib.Path
64
+ The path to the ansys-mechanical-stubs installation in site-packages.
65
+
66
+ Returns
67
+ -------
68
+ list
69
+ The list containing minimum and maximum versions in the ansys-mechanical-stubs package.
70
+ """
71
+ # Get revision numbers in stubs folder
72
+ revns = [
73
+ int(revision[1:])
74
+ for revision in os.listdir(stubs_location)
75
+ if os.path.isdir(os.path.join(stubs_location, revision)) and revision.startswith("v")
76
+ ]
77
+ return revns
78
+
79
+
80
+ def _vscode_impl(
81
+ target: str = "user",
82
+ revision: int = None,
83
+ ):
84
+ """Get the IDE configuration for autocomplete in VS Code.
85
+
86
+ Parameters
87
+ ----------
88
+ target: str
89
+ The type of settings to update. Either "user" or "workspace" in VS Code.
90
+ By default, it's ``user``.
91
+ revision: int
92
+ The Mechanical revision number. For example, "251".
93
+ If unspecified, it finds the default Mechanical version from ansys-tools-path.
94
+ """
95
+ # Update the user or workspace settings
96
+ if target == "user":
97
+ # Get the path to the user's settings.json file depending on the platform
98
+ if "win" in sys.platform:
99
+ settings_json = (
100
+ Path(os.environ.get("APPDATA")) / "Code" / "User" / "settings.json"
101
+ ) # pragma: no cover
102
+ elif "lin" in sys.platform:
103
+ settings_json = (
104
+ Path(os.environ.get("HOME")) / ".config" / "Code" / "User" / "settings.json"
105
+ )
106
+ elif target == "workspace":
107
+ # Get the current working directory
108
+ current_dir = Path.cwd()
109
+ # Get the path to the settings.json file based on the git root & .vscode folder
110
+ settings_json = current_dir / ".vscode" / "settings.json"
111
+
112
+ # Location where the stubs are installed -> .venv/Lib/site-packages, for example
113
+ stubs_location = get_stubs_location() / f"v{revision}"
114
+
115
+ # The settings to add to settings.json for autocomplete to work
116
+ settings_json_data = {
117
+ "python.autoComplete.extraPaths": [str(stubs_location)],
118
+ "python.analysis.extraPaths": [str(stubs_location)],
119
+ }
120
+ # Pretty print dictionary
121
+ pretty_dict = json.dumps(settings_json_data, indent=4)
122
+
123
+ print(f"Update {settings_json} with the following information:\n")
124
+
125
+ if target == "workspace":
126
+ print(
127
+ "Note: Please ensure the .vscode folder is in the root of your project or repository.\n"
128
+ )
129
+
130
+ print(pretty_dict)
131
+
132
+
133
+ def _cli_impl(
134
+ ide: str = "vscode",
135
+ target: str = "user",
136
+ revision: int = None,
137
+ ):
138
+ """Provide the user with the path to the settings.json file and IDE settings.
139
+
140
+ Parameters
141
+ ----------
142
+ ide: str
143
+ The IDE to set up autocomplete settings. By default, it's ``vscode``.
144
+ target: str
145
+ The type of settings to update. Either "user" or "workspace" in VS Code.
146
+ By default, it's ``user``.
147
+ revision: int
148
+ The Mechanical revision number. For example, "251".
149
+ If unspecified, it finds the default Mechanical version from ansys-tools-path.
150
+ """
151
+ # Get the ansys-mechanical-stubs install location
152
+ stubs_location = get_stubs_location()
153
+ # Get all revision numbers available in ansys-mechanical-stubs
154
+ revns = get_stubs_versions(stubs_location)
155
+
156
+ # Check if the user revision number is less or greater than the min and max revisions
157
+ # in the ansys-mechanical-stubs package location
158
+ if revision < min(revns):
159
+ raise Exception(f"PyMechanical Stubs are not available for {revision}")
160
+ elif revision > max(revns):
161
+ warnings.warn(
162
+ f"PyMechanical Stubs are not available for {revision}. Using {max(revns)} instead.",
163
+ stacklevel=2,
164
+ )
165
+ revision = max(revns)
166
+
167
+ # Check the IDE and raise an exception if it's not VS Code
168
+ if ide != "vscode":
169
+ raise Exception(f"{ide} is not supported at the moment.")
170
+
171
+ return _vscode_impl(target, revision)
172
+
173
+
174
+ @click.command()
175
+ @click.help_option("--help", "-h")
176
+ @click.option(
177
+ "--ide",
178
+ default="vscode",
179
+ type=str,
180
+ help="The IDE being used. By default, it's ``vscode``.",
181
+ )
182
+ @click.option(
183
+ "--target",
184
+ default="user",
185
+ type=str,
186
+ help="The type of settings to update - either ``user`` or ``workspace`` settings in VS Code.",
187
+ )
188
+ @click.option(
189
+ "--revision",
190
+ default=None,
191
+ type=int,
192
+ help='The Mechanical revision number, e.g. "251" or "242". If unspecified,\
193
+ it finds and uses the default version from ansys-tools-path.',
194
+ )
195
+ def cli(ide: str, target: str, revision: int) -> None:
196
+ """CLI tool to update settings.json files for autocomplete with ansys-mechanical-stubs.
197
+
198
+ Parameters
199
+ ----------
200
+ ide: str
201
+ The IDE to set up autocomplete settings. By default, it's ``vscode``.
202
+ target: str
203
+ The type of settings to update. Either "user" or "workspace" in VS Code.
204
+ By default, it's ``user``.
205
+ revision: int
206
+ The Mechanical revision number. For example, "251".
207
+ If unspecified, it finds the default Mechanical version from ansys-tools-path.
208
+
209
+ Usage
210
+ -----
211
+ The following example demonstrates the main use of this tool:
212
+
213
+ $ ansys-mechanical-ideconfig --ide vscode --target user --revision 251
214
+
215
+ """
216
+ if not revision:
217
+ exe = atp.get_mechanical_path(allow_input=False, version=revision)
218
+ version = atp.version_from_path("mechanical", exe)
219
+ else:
220
+ version = revision
221
+
222
+ return _cli_impl(
223
+ ide,
224
+ target,
225
+ version,
226
+ )