ansys-mechanical-core 0.11.7__py3-none-any.whl → 0.11.9__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.
- ansys/mechanical/core/embedding/addins.py +0 -6
- ansys/mechanical/core/embedding/app.py +65 -8
- ansys/mechanical/core/embedding/background.py +5 -5
- ansys/mechanical/core/embedding/cleanup_gui.py +61 -0
- ansys/mechanical/core/embedding/initializer.py +91 -34
- ansys/mechanical/core/embedding/ui.py +228 -0
- ansys/mechanical/core/embedding/viz/utils.py +2 -1
- ansys/mechanical/core/examples/downloads.py +9 -4
- ansys/mechanical/core/ide_config.py +212 -0
- ansys/mechanical/core/launcher.py +8 -8
- ansys/mechanical/core/mechanical.py +2 -3
- ansys/mechanical/core/pool.py +5 -5
- ansys/mechanical/core/run.py +5 -4
- {ansys_mechanical_core-0.11.7.dist-info → ansys_mechanical_core-0.11.9.dist-info}/METADATA +22 -19
- {ansys_mechanical_core-0.11.7.dist-info → ansys_mechanical_core-0.11.9.dist-info}/RECORD +18 -15
- {ansys_mechanical_core-0.11.7.dist-info → ansys_mechanical_core-0.11.9.dist-info}/entry_points.txt +1 -0
- {ansys_mechanical_core-0.11.7.dist-info → ansys_mechanical_core-0.11.9.dist-info}/LICENSE +0 -0
- {ansys_mechanical_core-0.11.7.dist-info → ansys_mechanical_core-0.11.9.dist-info}/WHEEL +0 -0
@@ -52,9 +52,3 @@ class AddinConfiguration:
|
|
52
52
|
@addin_configuration.setter
|
53
53
|
def addin_configuration(self, value: str):
|
54
54
|
self._addin_configuration = value
|
55
|
-
|
56
|
-
|
57
|
-
def configure(configuration: AddinConfiguration):
|
58
|
-
"""Apply the given configuration."""
|
59
|
-
if configuration.no_act_addins:
|
60
|
-
os.environ["ANSYS_MECHANICAL_STANDALONE_NO_ACT_EXTENSIONS"] = "1"
|
@@ -21,8 +21,11 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
"""Main application class for embedded Mechanical."""
|
24
|
+
from __future__ import annotations
|
25
|
+
|
24
26
|
import atexit
|
25
27
|
import os
|
28
|
+
import shutil
|
26
29
|
import typing
|
27
30
|
import warnings
|
28
31
|
|
@@ -31,15 +34,20 @@ from ansys.mechanical.core.embedding.addins import AddinConfiguration
|
|
31
34
|
from ansys.mechanical.core.embedding.appdata import UniqueUserProfile
|
32
35
|
from ansys.mechanical.core.embedding.imports import global_entry_points, global_variables
|
33
36
|
from ansys.mechanical.core.embedding.poster import Poster
|
37
|
+
from ansys.mechanical.core.embedding.ui import launch_ui
|
34
38
|
from ansys.mechanical.core.embedding.warnings import connect_warnings, disconnect_warnings
|
35
39
|
|
40
|
+
if typing.TYPE_CHECKING:
|
41
|
+
# Make sure to run ``ansys-mechanical-ideconfig`` to add the autocomplete settings to VS Code
|
42
|
+
# Run ``ansys-mechanical-ideconfig --help`` for more information
|
43
|
+
import Ansys # pragma: no cover
|
44
|
+
|
36
45
|
try:
|
37
46
|
import ansys.tools.visualization_interface # noqa: F401
|
38
47
|
|
39
48
|
HAS_ANSYS_VIZ = True
|
40
49
|
"""Whether or not PyVista exists."""
|
41
50
|
except:
|
42
|
-
|
43
51
|
HAS_ANSYS_VIZ = False
|
44
52
|
|
45
53
|
|
@@ -187,10 +195,45 @@ class App:
|
|
187
195
|
else:
|
188
196
|
self.DataModel.Project.Save()
|
189
197
|
|
190
|
-
def save_as(self, path):
|
191
|
-
"""Save the project as.
|
198
|
+
def save_as(self, path: str, overwrite: bool = False):
|
199
|
+
"""Save the project as a new file.
|
200
|
+
|
201
|
+
If the `overwrite` flag is enabled, the current saved file is temporarily moved
|
202
|
+
to a backup location. The new file is then saved in its place. If the process fails,
|
203
|
+
the backup file is restored to its original location.
|
204
|
+
|
205
|
+
Parameters
|
206
|
+
----------
|
207
|
+
path: int, optional
|
208
|
+
The path where file needs to be saved.
|
209
|
+
overwrite: bool, optional
|
210
|
+
Whether the file should be overwritten if it already exists (default is False).
|
211
|
+
"""
|
212
|
+
if not os.path.exists(path):
|
213
|
+
self.DataModel.Project.SaveAs(path)
|
214
|
+
return
|
215
|
+
|
216
|
+
if not overwrite:
|
217
|
+
raise Exception(
|
218
|
+
f"File already exists in {path}, Use ``overwrite`` flag to "
|
219
|
+
"replace the existing file."
|
220
|
+
)
|
221
|
+
|
222
|
+
file_name = os.path.basename(path)
|
223
|
+
file_dir = os.path.dirname(path)
|
224
|
+
associated_dir = os.path.join(file_dir, os.path.splitext(file_name)[0] + "_Mech_Files")
|
225
|
+
|
226
|
+
# Remove existing files and associated folder
|
227
|
+
os.remove(path)
|
228
|
+
if os.path.exists(associated_dir):
|
229
|
+
shutil.rmtree(associated_dir)
|
230
|
+
# Save the new file
|
192
231
|
self.DataModel.Project.SaveAs(path)
|
193
232
|
|
233
|
+
def launch_gui(self, delete_tmp_on_close: bool = True, dry_run: bool = False):
|
234
|
+
"""Launch the GUI."""
|
235
|
+
launch_ui(self, delete_tmp_on_close, dry_run)
|
236
|
+
|
194
237
|
def new(self):
|
195
238
|
"""Clear to a new application."""
|
196
239
|
self.DataModel.Project.New()
|
@@ -227,7 +270,21 @@ class App:
|
|
227
270
|
light_mode = True
|
228
271
|
args = None
|
229
272
|
rets = None
|
230
|
-
|
273
|
+
script_result = self.script_engine.ExecuteCode(script, SCRIPT_SCOPE, light_mode, args, rets)
|
274
|
+
error_msg = f"Failed to execute the script"
|
275
|
+
if script_result is None:
|
276
|
+
raise Exception(error_msg)
|
277
|
+
if script_result.Error is not None:
|
278
|
+
error_msg += f": {script_result.Error.Message}"
|
279
|
+
raise Exception(error_msg)
|
280
|
+
return script_result.Value
|
281
|
+
|
282
|
+
def execute_script_from_file(self, file_path=None):
|
283
|
+
"""Execute the given script from file with the internal IronPython engine."""
|
284
|
+
text_file = open(file_path, "r", encoding="utf-8")
|
285
|
+
data = text_file.read()
|
286
|
+
text_file.close()
|
287
|
+
return self.execute_script(data)
|
231
288
|
|
232
289
|
def plotter(self) -> None:
|
233
290
|
"""Return ``ansys.tools.visualization_interface.Plotter`` object."""
|
@@ -273,22 +330,22 @@ class App:
|
|
273
330
|
return GetterWrapper(self._app, lambda app: app.DataModel)
|
274
331
|
|
275
332
|
@property
|
276
|
-
def ExtAPI(self):
|
333
|
+
def ExtAPI(self) -> Ansys.ACT.Interfaces.Mechanical.IMechanicalExtAPI:
|
277
334
|
"""Return the ExtAPI object."""
|
278
335
|
return GetterWrapper(self._app, lambda app: app.ExtAPI)
|
279
336
|
|
280
337
|
@property
|
281
|
-
def Tree(self):
|
338
|
+
def Tree(self) -> Ansys.ACT.Automation.Mechanical.Tree:
|
282
339
|
"""Return the Tree object."""
|
283
340
|
return GetterWrapper(self._app, lambda app: app.DataModel.Tree)
|
284
341
|
|
285
342
|
@property
|
286
|
-
def Model(self):
|
343
|
+
def Model(self) -> Ansys.ACT.Automation.Mechanical.Model:
|
287
344
|
"""Return the Model object."""
|
288
345
|
return GetterWrapper(self._app, lambda app: app.DataModel.Project.Model)
|
289
346
|
|
290
347
|
@property
|
291
|
-
def Graphics(self):
|
348
|
+
def Graphics(self) -> Ansys.ACT.Common.Graphics.MechanicalGraphicsWrapper:
|
292
349
|
"""Return the Graphics object."""
|
293
350
|
return GetterWrapper(self._app, lambda app: app.ExtAPI.Graphics)
|
294
351
|
|
@@ -59,9 +59,8 @@ class BackgroundApp:
|
|
59
59
|
time.sleep(0.05)
|
60
60
|
continue
|
61
61
|
else:
|
62
|
-
|
63
|
-
|
64
|
-
), "Cannot initialize a BackgroundApp once it has been stopped!"
|
62
|
+
if BackgroundApp.__stopped:
|
63
|
+
raise RuntimeError("Cannot initialize a BackgroundApp once it has been stopped!")
|
65
64
|
|
66
65
|
def new():
|
67
66
|
BackgroundApp.__app.new()
|
@@ -80,7 +79,8 @@ class BackgroundApp:
|
|
80
79
|
|
81
80
|
def post(self, callable: typing.Callable):
|
82
81
|
"""Post callable method to the background app thread."""
|
83
|
-
|
82
|
+
if BackgroundApp.__stopped:
|
83
|
+
raise RuntimeError("Cannot use BackgroundApp after stopping it.")
|
84
84
|
return BackgroundApp.__poster.post(callable)
|
85
85
|
|
86
86
|
def stop(self) -> None:
|
@@ -102,5 +102,5 @@ class BackgroundApp:
|
|
102
102
|
try:
|
103
103
|
utils.sleep(40)
|
104
104
|
except:
|
105
|
-
|
105
|
+
raise Exception("BackgroundApp cannot sleep.") # pragma: no cover
|
106
106
|
BackgroundApp.__stopped = True
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Copyright (C) 2022 - 2024 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
|
+
"""Clean up temporary mechdb files after GUI is closed."""
|
23
|
+
|
24
|
+
from pathlib import Path
|
25
|
+
import shutil
|
26
|
+
import sys
|
27
|
+
import time
|
28
|
+
|
29
|
+
import psutil
|
30
|
+
|
31
|
+
|
32
|
+
def cleanup_gui(pid, temp_mechdb) -> None:
|
33
|
+
"""Remove the temporary mechdb file after it is closed.
|
34
|
+
|
35
|
+
Parameters
|
36
|
+
----------
|
37
|
+
pid: int
|
38
|
+
The process ID of the open temporary mechdb file.
|
39
|
+
temp_mechdb: Path
|
40
|
+
The path of the temporary mechdb file.
|
41
|
+
"""
|
42
|
+
# While the pid exists, sleep
|
43
|
+
while psutil.pid_exists(pid):
|
44
|
+
time.sleep(1)
|
45
|
+
|
46
|
+
# Delete the temporary mechdb file once the GUI is closed
|
47
|
+
temp_mechdb.unlink()
|
48
|
+
|
49
|
+
# Delete the temporary mechdb Mech_Files folder
|
50
|
+
temp_folder_path = temp_mechdb.parent / f"{temp_mechdb.name.split('.')[0]}_Mech_Files"
|
51
|
+
shutil.rmtree(temp_folder_path)
|
52
|
+
|
53
|
+
|
54
|
+
if __name__ == "__main__": # pragma: no cover
|
55
|
+
"""Get the process ID and temporary file path to monitor and delete files after use."""
|
56
|
+
# Convert the process id (pid) argument into an integer
|
57
|
+
pid = int(sys.argv[1])
|
58
|
+
# Convert the temporary mechdb path into a Path
|
59
|
+
temp_mechdb_path = Path(sys.argv[2])
|
60
|
+
# Remove the temporary mechdb file when the GUI is closed
|
61
|
+
cleanup_gui(pid, temp_mechdb_path)
|
@@ -28,15 +28,13 @@ import platform
|
|
28
28
|
import sys
|
29
29
|
import warnings
|
30
30
|
|
31
|
-
import ansys.tools.path as atp
|
32
|
-
|
33
31
|
from ansys.mechanical.core.embedding.loader import load_clr
|
34
32
|
from ansys.mechanical.core.embedding.resolver import resolve
|
35
33
|
|
36
34
|
INITIALIZED_VERSION = None
|
37
35
|
"""Constant for the initialized version."""
|
38
36
|
|
39
|
-
|
37
|
+
SUPPORTED_MECHANICAL_EMBEDDING_VERSIONS = {242: "2024R2", 241: "2024R1", 232: "2023R2"}
|
40
38
|
"""Supported Mechanical embedding versions on Windows."""
|
41
39
|
|
42
40
|
|
@@ -59,48 +57,68 @@ def __workaround_material_server(version: int) -> None:
|
|
59
57
|
os.environ["ENGRDATA_SERVER_SERIAL"] = "1"
|
60
58
|
|
61
59
|
|
62
|
-
def
|
63
|
-
"""
|
60
|
+
def __check_for_supported_version(version) -> None:
|
61
|
+
"""Check if Mechanical version is supported with current version of PyMechanical.
|
64
62
|
|
65
|
-
|
66
|
-
|
67
|
-
The documented way to set those variables is to run python using the ``mechanical-env`` script,
|
68
|
-
which can be used after installing the ``ansys-mechanical-env`` package with this command:
|
69
|
-
``pip install ansys-mechanical-env``. The script takes user input of a version. If the user
|
70
|
-
does not provide a version, the ``find_mechanical()`` function from the ``ansys-tools-path``
|
71
|
-
package is used to find a version of Mechanical.
|
63
|
+
If specific environment variable is enabled, then users can overwrite the supported versions.
|
64
|
+
However, using unsupported versions may cause issues.
|
72
65
|
"""
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
return
|
66
|
+
allow_old_version = os.getenv("ANSYS_MECHANICAL_EMBEDDING_SUPPORT_OLD_VERSIONS") == "1"
|
67
|
+
|
68
|
+
# Check if the version is supported
|
69
|
+
if not allow_old_version and version < min(SUPPORTED_MECHANICAL_EMBEDDING_VERSIONS):
|
70
|
+
raise ValueError(f"Mechanical version {version} is not supported.")
|
71
|
+
|
72
|
+
return version
|
80
73
|
|
81
74
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
75
|
+
def _get_latest_default_version() -> int:
|
76
|
+
"""Try to get the latest Mechanical version from the environment.
|
77
|
+
|
78
|
+
Checks if multiple versions of Mechanical found in system.
|
79
|
+
For Linux it will be only one since ``mechanical-env`` takes care of that.
|
80
|
+
If multiple versions are detected, select the latest one, as no specific version is provided.
|
81
|
+
"""
|
82
|
+
awp_roots = [value for key, value in os.environ.items() if key.startswith("AWP_ROOT")]
|
83
|
+
|
84
|
+
if not awp_roots:
|
85
|
+
raise Exception("No Mechanical installations found.")
|
85
86
|
|
86
|
-
|
87
|
-
|
87
|
+
versions_found = []
|
88
|
+
for path in awp_roots:
|
89
|
+
folder = os.path.basename(os.path.normpath(path))
|
90
|
+
version = folder.split("v")[-1]
|
91
|
+
versions_found.append(int(version))
|
92
|
+
latest_version = max(versions_found)
|
88
93
|
|
89
|
-
|
90
|
-
|
91
|
-
|
94
|
+
if len(awp_roots) > 1:
|
95
|
+
warnings.warn(
|
96
|
+
f"Multiple versions of Mechanical found! Using latest version {latest_version} ..."
|
97
|
+
)
|
92
98
|
|
93
|
-
|
94
|
-
int_version = int(str(version).replace(".", ""))
|
95
|
-
return int_version
|
99
|
+
return latest_version
|
96
100
|
|
97
101
|
|
98
|
-
def __check_python_interpreter_architecture():
|
102
|
+
def __check_python_interpreter_architecture() -> None:
|
99
103
|
"""Embedding support only 64 bit architecture."""
|
100
104
|
if platform.architecture()[0] != "64bit":
|
101
105
|
raise Exception("Mechanical Embedding requires a 64-bit Python environment.")
|
102
106
|
|
103
107
|
|
108
|
+
def __set_environment(version: int) -> None:
|
109
|
+
"""Set environment variables to configure embedding."""
|
110
|
+
if os.name == "nt": # pragma: no cover
|
111
|
+
if version < 251:
|
112
|
+
os.environ["MECHANICAL_STARTUP_UNOPTIMIZED"] = "1"
|
113
|
+
|
114
|
+
# Set an environment variable to use the custom CLR host
|
115
|
+
# for embedding.
|
116
|
+
# In the future (>251), it would always be used.
|
117
|
+
if version == 251:
|
118
|
+
if "PYMECHANICAL_NO_CLR_HOST_LITE" not in os.environ:
|
119
|
+
os.environ["ANSYS_MECHANICAL_EMBEDDING_CLR_HOST"] = "1"
|
120
|
+
|
121
|
+
|
104
122
|
def __check_for_mechanical_env():
|
105
123
|
"""Embedding in linux platform must use mechanical-env."""
|
106
124
|
if platform.system() == "Linux" and os.environ.get("PYMECHANICAL_EMBEDDING") != "TRUE":
|
@@ -113,21 +131,60 @@ def __check_for_mechanical_env():
|
|
113
131
|
)
|
114
132
|
|
115
133
|
|
134
|
+
def __is_lib_loaded(libname: str): # pragma: no cover
|
135
|
+
"""Return whether a library is loaded."""
|
136
|
+
import ctypes
|
137
|
+
|
138
|
+
RTLD_NOLOAD = 4
|
139
|
+
try:
|
140
|
+
ctypes.CDLL(libname, RTLD_NOLOAD)
|
141
|
+
except:
|
142
|
+
return False
|
143
|
+
return True
|
144
|
+
|
145
|
+
|
146
|
+
def __check_loaded_libs(version: int = None): # pragma: no cover
|
147
|
+
"""Ensure that incompatible libraries aren't loaded prior to PyMechanical load."""
|
148
|
+
if platform.system() != "Linux":
|
149
|
+
return
|
150
|
+
|
151
|
+
if version < 251:
|
152
|
+
return
|
153
|
+
|
154
|
+
# For 2025 R1, PyMechanical will crash on shutdown if libX11.so is already loaded
|
155
|
+
# before starting Mechanical
|
156
|
+
if __is_lib_loaded("libX11.so"):
|
157
|
+
warnings.warn(
|
158
|
+
"libX11.so is loaded prior to initializing the Embedded Instance of Mechanical.\
|
159
|
+
Python will crash on shutdown..."
|
160
|
+
)
|
161
|
+
|
162
|
+
|
116
163
|
def initialize(version: int = None):
|
117
164
|
"""Initialize Mechanical embedding."""
|
118
165
|
__check_python_interpreter_architecture() # blocks 32 bit python
|
119
166
|
__check_for_mechanical_env() # checks for mechanical-env in linux embedding
|
120
167
|
|
121
168
|
global INITIALIZED_VERSION
|
122
|
-
if INITIALIZED_VERSION
|
123
|
-
|
169
|
+
if INITIALIZED_VERSION is not None:
|
170
|
+
if INITIALIZED_VERSION != version:
|
171
|
+
raise ValueError(
|
172
|
+
f"Initialized version {INITIALIZED_VERSION} "
|
173
|
+
f"does not match the expected version {version}."
|
174
|
+
)
|
124
175
|
return
|
125
176
|
|
126
177
|
if version == None:
|
127
|
-
version =
|
178
|
+
version = _get_latest_default_version()
|
179
|
+
|
180
|
+
version = __check_for_supported_version(version=version)
|
128
181
|
|
129
182
|
INITIALIZED_VERSION = version
|
130
183
|
|
184
|
+
__set_environment(version)
|
185
|
+
|
186
|
+
__check_loaded_libs(version)
|
187
|
+
|
131
188
|
__workaround_material_server(version)
|
132
189
|
|
133
190
|
# need to add system path in order to import the assembly with the resolver
|
@@ -0,0 +1,228 @@
|
|
1
|
+
# Copyright (C) 2022 - 2024 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
|
+
"""Run Mechanical UI from Python."""
|
23
|
+
|
24
|
+
from pathlib import Path
|
25
|
+
|
26
|
+
# Subprocess is needed to launch the GUI and clean up the process on close.
|
27
|
+
# Excluding bandit check.
|
28
|
+
from subprocess import Popen # nosec: B404
|
29
|
+
import sys
|
30
|
+
import tempfile
|
31
|
+
import typing
|
32
|
+
|
33
|
+
|
34
|
+
class UILauncher:
|
35
|
+
"""Launch the GUI using a temporary mechdb file."""
|
36
|
+
|
37
|
+
def __init__(self, dry_run: bool = False):
|
38
|
+
"""Initialize UILauncher class."""
|
39
|
+
self._dry_run = dry_run
|
40
|
+
|
41
|
+
def save_original(self, app: "ansys.mechanical.core.embedding.App") -> None:
|
42
|
+
"""Save the active mechdb file.
|
43
|
+
|
44
|
+
Parameters
|
45
|
+
----------
|
46
|
+
app: ansys.mechanical.core.embedding.app.App
|
47
|
+
A Mechanical embedding application.
|
48
|
+
"""
|
49
|
+
app.save()
|
50
|
+
|
51
|
+
def save_temp_copy(
|
52
|
+
self, app: "ansys.mechanical.core.embedding.App"
|
53
|
+
) -> typing.Union[Path, Path]:
|
54
|
+
"""Save a new mechdb file with a temporary name.
|
55
|
+
|
56
|
+
Parameters
|
57
|
+
----------
|
58
|
+
app: ansys.mechanical.core.embedding.app.App
|
59
|
+
A Mechanical embedding application.
|
60
|
+
"""
|
61
|
+
# Identify the mechdb of the saved session from save_original()
|
62
|
+
project_directory = Path(app.DataModel.Project.ProjectDirectory)
|
63
|
+
project_directory_parent = project_directory.parent
|
64
|
+
mechdb_file = (
|
65
|
+
project_directory_parent / f"{project_directory.parts[-1].split('_')[0]}.mechdb"
|
66
|
+
)
|
67
|
+
|
68
|
+
# Get name of NamedTemporaryFile
|
69
|
+
temp_file_name = tempfile.NamedTemporaryFile(
|
70
|
+
dir=project_directory_parent, suffix=".mechdb", delete=True
|
71
|
+
).name
|
72
|
+
|
73
|
+
# Save app with name of temporary file
|
74
|
+
app.save_as(temp_file_name)
|
75
|
+
|
76
|
+
return mechdb_file, temp_file_name
|
77
|
+
|
78
|
+
def open_original(self, app: "ansys.mechanical.core.embedding.App", mechdb_file: str) -> None:
|
79
|
+
"""Open the original mechdb file from save_original().
|
80
|
+
|
81
|
+
Parameters
|
82
|
+
----------
|
83
|
+
app: ansys.mechanical.core.embedding.app.App
|
84
|
+
A Mechanical embedding application.
|
85
|
+
mechdb_file: str
|
86
|
+
The full path to the active mechdb file.
|
87
|
+
"""
|
88
|
+
app.open(mechdb_file)
|
89
|
+
|
90
|
+
def graphically_launch_temp(
|
91
|
+
self, app: "ansys.mechanical.core.embedding.App", temp_file: Path
|
92
|
+
) -> typing.Union[Popen, str]:
|
93
|
+
"""Launch the GUI for the mechdb file with a temporary name from save_temp_copy().
|
94
|
+
|
95
|
+
Parameters
|
96
|
+
----------
|
97
|
+
app: ansys.mechanical.core.embedding.app.App
|
98
|
+
A Mechanical embedding application.
|
99
|
+
temp_file: pathlib.Path
|
100
|
+
The full path to the temporary mechdb file.
|
101
|
+
|
102
|
+
Returns
|
103
|
+
-------
|
104
|
+
subprocess.Popen
|
105
|
+
The subprocess that launches the GUI for the temporary mechdb file.
|
106
|
+
"""
|
107
|
+
# The ansys-mechanical command to launch the GUI in a subprocess
|
108
|
+
args = [
|
109
|
+
"ansys-mechanical",
|
110
|
+
"--project-file",
|
111
|
+
temp_file,
|
112
|
+
"--graphical",
|
113
|
+
"--revision",
|
114
|
+
str(app.version),
|
115
|
+
]
|
116
|
+
if not self._dry_run:
|
117
|
+
# The subprocess that uses ansys-mechanical to launch the GUI of the temporary
|
118
|
+
# mechdb file
|
119
|
+
process = Popen(args) # nosec: B603 # pragma: no cover
|
120
|
+
return process
|
121
|
+
else:
|
122
|
+
# Return a string containing the args
|
123
|
+
return " ".join(args)
|
124
|
+
|
125
|
+
def _cleanup_gui(self, process: Popen, temp_mechdb_path: Path) -> None:
|
126
|
+
"""Remove the temporary mechdb file and folder when the GUI is closed.
|
127
|
+
|
128
|
+
Parameters
|
129
|
+
----------
|
130
|
+
process: subprocess.Popen
|
131
|
+
The subprocess that launched the GUI of the temporary mechdb file.
|
132
|
+
temp_mechdb_path: pathlib.Path
|
133
|
+
The full path to the temporary mechdb file.
|
134
|
+
"""
|
135
|
+
# Get the path to the cleanup script
|
136
|
+
cleanup_script = Path(__file__).parent / "cleanup_gui.py" # pragma: no cover
|
137
|
+
|
138
|
+
if not self._dry_run:
|
139
|
+
# Open a subprocess to remove the temporary mechdb file and folder when the process ends
|
140
|
+
Popen(
|
141
|
+
[sys.executable, cleanup_script, str(process.pid), temp_mechdb_path]
|
142
|
+
) # pragma: no cover # nosec: B603
|
143
|
+
|
144
|
+
|
145
|
+
def _is_saved(app: "ansys.mechanical.core.embedding.App") -> bool:
|
146
|
+
"""Check if the mechdb file has been saved and raise an exception if not.
|
147
|
+
|
148
|
+
Parameters
|
149
|
+
----------
|
150
|
+
app: ansys.mechanical.core.embedding.app.App
|
151
|
+
A Mechanical embedding application.
|
152
|
+
|
153
|
+
Returns
|
154
|
+
-------
|
155
|
+
bool
|
156
|
+
``True`` when the embedded app has been saved.
|
157
|
+
``False`` when the embedded app has not been saved.
|
158
|
+
"""
|
159
|
+
try:
|
160
|
+
app.save()
|
161
|
+
except:
|
162
|
+
raise Exception("The App must have already been saved before using launch_ui!")
|
163
|
+
return True
|
164
|
+
|
165
|
+
|
166
|
+
def _launch_ui(
|
167
|
+
app: "ansys.mechanical.core.embedding.App", delete_tmp_on_close: bool, launcher: UILauncher
|
168
|
+
) -> None:
|
169
|
+
"""Launch the Mechanical UI if the mechdb file has been saved.
|
170
|
+
|
171
|
+
Parameters
|
172
|
+
----------
|
173
|
+
app: ansys.mechanical.core.embedding.app.App
|
174
|
+
A Mechanical embedding application.
|
175
|
+
delete_tmp_on_close: bool
|
176
|
+
Whether to delete the temporary mechdb file when the GUI is closed.
|
177
|
+
By default, this is ``True``.
|
178
|
+
launcher: UILauncher
|
179
|
+
Launch the GUI using a temporary mechdb file.
|
180
|
+
"""
|
181
|
+
if _is_saved(app):
|
182
|
+
# Save the active mechdb file.
|
183
|
+
launcher.save_original(app)
|
184
|
+
# Save a new mechdb file with a temporary name.
|
185
|
+
mechdb_file, temp_file = launcher.save_temp_copy(app)
|
186
|
+
# Open the original mechdb file from save_original().
|
187
|
+
launcher.open_original(app, str(mechdb_file))
|
188
|
+
# Launch the GUI for the mechdb file with a temporary name from save_temp_copy().
|
189
|
+
process = launcher.graphically_launch_temp(app, temp_file)
|
190
|
+
|
191
|
+
# If it's a dry run and graphically_launch_temp returned a string, print the string
|
192
|
+
if isinstance(process, str):
|
193
|
+
print(process)
|
194
|
+
|
195
|
+
# If the user wants the temporary file to be deleted and graphically_launch_temp
|
196
|
+
# returned a process. By default, this is True
|
197
|
+
if delete_tmp_on_close and not isinstance(process, str):
|
198
|
+
# Remove the temporary mechdb file and folder when the GUI is closed.
|
199
|
+
launcher._cleanup_gui(process, temp_file) # pragma: no cover
|
200
|
+
else:
|
201
|
+
# Let the user know that the mechdb started above will not automatically get cleaned up
|
202
|
+
print(
|
203
|
+
f"""Opened a new mechanical session based on {mechdb_file} named {temp_file}.
|
204
|
+
PyMechanical will not delete it after use."""
|
205
|
+
)
|
206
|
+
|
207
|
+
|
208
|
+
def launch_ui(
|
209
|
+
app: "ansys.mechanical.core.embedding.App",
|
210
|
+
delete_tmp_on_close: bool = True,
|
211
|
+
dry_run: bool = False,
|
212
|
+
) -> None:
|
213
|
+
"""Launch the Mechanical UI.
|
214
|
+
|
215
|
+
Precondition: Mechanical has to have already been saved
|
216
|
+
Side effect: If Mechanical has ever been saved, it overwrites that save.
|
217
|
+
|
218
|
+
Parameters
|
219
|
+
----------
|
220
|
+
app: ansys.mechanical.core.embedding.app.App
|
221
|
+
A Mechanical embedding application.
|
222
|
+
delete_tmp_on_close: bool
|
223
|
+
Whether to delete the temporary mechdb file when the GUI is closed.
|
224
|
+
By default, this is ``True``.
|
225
|
+
dry_run: bool
|
226
|
+
Whether or not to launch the GUI. By default, this is ``False``.
|
227
|
+
"""
|
228
|
+
_launch_ui(app, delete_tmp_on_close, UILauncher(dry_run))
|
@@ -41,7 +41,8 @@ def _reshape_3cols(arr: np.array, name: str = "array"):
|
|
41
41
|
"""
|
42
42
|
err = f"{name} must be of the form (x0,y0,z0,x1,y1,z1,...,xn,yn,zn).\
|
43
43
|
Given {name} are not divisible by 3!"
|
44
|
-
|
44
|
+
if arr.size % 3 != 0:
|
45
|
+
raise ValueError(err)
|
45
46
|
numrows = int(arr.size / 3)
|
46
47
|
numcols = 3
|
47
48
|
arr = np.reshape(arr, (numrows, numcols))
|
@@ -26,7 +26,8 @@ import os
|
|
26
26
|
import shutil
|
27
27
|
from typing import Optional
|
28
28
|
from urllib.parse import urljoin
|
29
|
-
|
29
|
+
|
30
|
+
import requests
|
30
31
|
|
31
32
|
import ansys.mechanical.core as pymechanical
|
32
33
|
|
@@ -53,9 +54,13 @@ def _get_filepath_on_default_server(filename: str, *directory: str):
|
|
53
54
|
return joiner(server, filename)
|
54
55
|
|
55
56
|
|
56
|
-
def _retrieve_url(url, dest):
|
57
|
-
|
58
|
-
|
57
|
+
def _retrieve_url(url: str, dest: str) -> str:
|
58
|
+
with requests.get(url, stream=True, timeout=10) as r:
|
59
|
+
r.raise_for_status()
|
60
|
+
with open(dest, "wb") as f:
|
61
|
+
for chunk in r.iter_content(chunk_size=4096):
|
62
|
+
f.write(chunk)
|
63
|
+
return dest
|
59
64
|
|
60
65
|
|
61
66
|
def _retrieve_data(url: str, filename: str, dest: str = None, force: bool = False):
|
@@ -0,0 +1,212 @@
|
|
1
|
+
# Copyright (C) 2022 - 2024 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, "242".
|
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, "242".
|
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. "242" or "241". 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, "242".
|
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 242
|
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
|
+
)
|
@@ -23,10 +23,11 @@
|
|
23
23
|
"""Launch Mechanical in batch or UI mode."""
|
24
24
|
import errno
|
25
25
|
import os
|
26
|
-
|
26
|
+
|
27
|
+
# Subprocess is needed to start the backend. Excluding bandit check.
|
28
|
+
import subprocess # nosec: B404
|
27
29
|
|
28
30
|
from ansys.mechanical.core import LOG
|
29
|
-
from ansys.mechanical.core.misc import is_windows
|
30
31
|
|
31
32
|
|
32
33
|
class MechanicalLauncher:
|
@@ -90,17 +91,16 @@ class MechanicalLauncher:
|
|
90
91
|
env_variables = self.__get_env_variables()
|
91
92
|
args_list = self.__get_commandline_args()
|
92
93
|
|
93
|
-
shell_value = False
|
94
|
-
|
95
|
-
if is_windows():
|
96
|
-
shell_value = True
|
97
|
-
|
98
94
|
LOG.info(f"Starting the process using {args_list}.")
|
99
95
|
if self.verbose:
|
100
96
|
command = " ".join(args_list)
|
101
97
|
print(f"Running {command}.")
|
102
98
|
|
103
|
-
process = subprocess.Popen(
|
99
|
+
process = subprocess.Popen(
|
100
|
+
args_list,
|
101
|
+
stdout=subprocess.PIPE,
|
102
|
+
env=env_variables,
|
103
|
+
) # nosec: B603
|
104
104
|
LOG.info(f"Started the process:{process} using {args_list}.")
|
105
105
|
|
106
106
|
@staticmethod
|
@@ -496,7 +496,6 @@ class Mechanical(object):
|
|
496
496
|
raise
|
497
497
|
finally:
|
498
498
|
self._disable_logging = False
|
499
|
-
pass
|
500
499
|
return self._version
|
501
500
|
|
502
501
|
@property
|
@@ -508,8 +507,8 @@ class Mechanical(object):
|
|
508
507
|
return f"GRPC_{self._channel._channel._channel.target().decode()}"
|
509
508
|
else:
|
510
509
|
return f"GRPC_{self._channel._channel.target().decode()}"
|
511
|
-
except Exception: # pragma: no cover
|
512
|
-
|
510
|
+
except Exception as e: # pragma: no cover
|
511
|
+
LOG.error(f"Error getting the Mechanical instance name: {str(e)}")
|
513
512
|
|
514
513
|
return f"GRPC_instance_{id(self)}" # pragma: no cover
|
515
514
|
|
ansys/mechanical/core/pool.py
CHANGED
@@ -180,7 +180,7 @@ class LocalMechanicalPool:
|
|
180
180
|
version = kwargs["version"]
|
181
181
|
self._remote = True
|
182
182
|
else:
|
183
|
-
raise "Pypim is configured
|
183
|
+
raise ValueError("Pypim is configured, but version is not passed.")
|
184
184
|
else: # get default executable
|
185
185
|
exec_file = get_mechanical_path()
|
186
186
|
if exec_file is None: # pragma: no cover
|
@@ -389,8 +389,8 @@ class LocalMechanicalPool:
|
|
389
389
|
LOG.error(f"Stopped instance because running failed.")
|
390
390
|
try:
|
391
391
|
obj.exit()
|
392
|
-
except:
|
393
|
-
|
392
|
+
except Exception as e:
|
393
|
+
LOG.error(f"Unexpected error while exiting: {e}")
|
394
394
|
|
395
395
|
obj.locked = False
|
396
396
|
if pbar:
|
@@ -583,8 +583,8 @@ class LocalMechanicalPool:
|
|
583
583
|
if instance_local:
|
584
584
|
try:
|
585
585
|
instance_local.exit()
|
586
|
-
except: # pragma: no cover
|
587
|
-
|
586
|
+
except Exception as e: # pragma: no cover
|
587
|
+
LOG.error(f"Error while exiting instance {str(instance_local)}: {str(e)}")
|
588
588
|
self._instances[index] = None
|
589
589
|
LOG.debug(f"Exited instance: {str(instance_local)}")
|
590
590
|
|
ansys/mechanical/core/run.py
CHANGED
@@ -54,7 +54,8 @@ async def _read_and_display(cmd, env, do_display: bool):
|
|
54
54
|
}
|
55
55
|
while tasks:
|
56
56
|
done, pending = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
|
57
|
-
|
57
|
+
if not done:
|
58
|
+
raise RuntimeError("Subprocess read failed: No tasks completed.")
|
58
59
|
for future in done:
|
59
60
|
buf, stream, display = tasks.pop(future)
|
60
61
|
line = future.result()
|
@@ -67,7 +68,7 @@ async def _read_and_display(cmd, env, do_display: bool):
|
|
67
68
|
|
68
69
|
# wait for the process to exit
|
69
70
|
rc = await process.wait()
|
70
|
-
return rc, b"".join(stdout), b"".join(stderr)
|
71
|
+
return rc, process, b"".join(stdout), b"".join(stderr)
|
71
72
|
|
72
73
|
|
73
74
|
def _run(args, env, check=False, display=False):
|
@@ -77,13 +78,13 @@ def _run(args, env, check=False, display=False):
|
|
77
78
|
else:
|
78
79
|
loop = asyncio.get_event_loop()
|
79
80
|
try:
|
80
|
-
rc, *output = loop.run_until_complete(_read_and_display(args, env, display))
|
81
|
+
rc, process, *output = loop.run_until_complete(_read_and_display(args, env, display))
|
81
82
|
if rc and check:
|
82
83
|
sys.exit("child failed with '{}' exit code".format(rc))
|
83
84
|
finally:
|
84
85
|
if os.name == "nt":
|
85
86
|
loop.close()
|
86
|
-
return output
|
87
|
+
return process, output
|
87
88
|
|
88
89
|
|
89
90
|
def _cli_impl(
|
@@ -1,23 +1,23 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: ansys-mechanical-core
|
3
|
-
Version: 0.11.
|
3
|
+
Version: 0.11.9
|
4
4
|
Summary: A python wrapper for Ansys Mechanical
|
5
5
|
Keywords: pymechanical,mechanical,ansys,pyansys
|
6
6
|
Author-email: "ANSYS, Inc." <pyansys.core@ansys.com>
|
7
7
|
Maintainer-email: "ANSYS, Inc." <pyansys.core@ansys.com>
|
8
|
-
Requires-Python: >=3.
|
8
|
+
Requires-Python: >=3.10,<4.0
|
9
9
|
Description-Content-Type: text/x-rst
|
10
10
|
Classifier: Development Status :: 4 - Beta
|
11
11
|
Classifier: Intended Audience :: Science/Research
|
12
12
|
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
13
|
-
Classifier: Programming Language :: Python :: 3.9
|
14
13
|
Classifier: Programming Language :: Python :: 3.10
|
15
14
|
Classifier: Programming Language :: Python :: 3.11
|
16
15
|
Classifier: Programming Language :: Python :: 3.12
|
17
16
|
Classifier: License :: OSI Approved :: MIT License
|
18
17
|
Classifier: Operating System :: OS Independent
|
19
18
|
Requires-Dist: ansys-api-mechanical==0.1.2
|
20
|
-
Requires-Dist: ansys-mechanical-env==0.1.
|
19
|
+
Requires-Dist: ansys-mechanical-env==0.1.8
|
20
|
+
Requires-Dist: ansys-mechanical-stubs==0.1.4
|
21
21
|
Requires-Dist: ansys-platform-instancemanagement>=1.0.1
|
22
22
|
Requires-Dist: ansys-pythonnet>=3.1.0rc2
|
23
23
|
Requires-Dist: ansys-tools-path>=0.3.1
|
@@ -26,37 +26,40 @@ Requires-Dist: click>=8.1.3
|
|
26
26
|
Requires-Dist: clr-loader==0.2.6
|
27
27
|
Requires-Dist: grpcio>=1.30.0
|
28
28
|
Requires-Dist: protobuf>=3.12.2,<6
|
29
|
+
Requires-Dist: psutil==6.1.0
|
29
30
|
Requires-Dist: tqdm>=4.45.0
|
30
|
-
Requires-Dist:
|
31
|
-
Requires-Dist:
|
32
|
-
Requires-Dist:
|
31
|
+
Requires-Dist: requests>=2,<3
|
32
|
+
Requires-Dist: sphinx==8.1.3 ; extra == "doc"
|
33
|
+
Requires-Dist: ansys-sphinx-theme[autoapi]==1.1.7 ; extra == "doc"
|
34
|
+
Requires-Dist: grpcio==1.67.0 ; extra == "doc"
|
33
35
|
Requires-Dist: imageio-ffmpeg==0.5.1 ; extra == "doc"
|
34
|
-
Requires-Dist: imageio==2.
|
36
|
+
Requires-Dist: imageio==2.36.0 ; extra == "doc"
|
35
37
|
Requires-Dist: jupyter_sphinx==0.5.3 ; extra == "doc"
|
36
38
|
Requires-Dist: jupyterlab>=3.2.8 ; extra == "doc"
|
37
39
|
Requires-Dist: matplotlib==3.9.2 ; extra == "doc"
|
38
|
-
Requires-Dist: numpy==2.1.
|
40
|
+
Requires-Dist: numpy==2.1.2 ; extra == "doc"
|
39
41
|
Requires-Dist: numpydoc==1.8.0 ; extra == "doc"
|
40
|
-
Requires-Dist: pandas==2.2.
|
41
|
-
Requires-Dist: panel==1.
|
42
|
-
Requires-Dist: plotly==5.
|
43
|
-
Requires-Dist: pypandoc==1.
|
42
|
+
Requires-Dist: pandas==2.2.3 ; extra == "doc"
|
43
|
+
Requires-Dist: panel==1.5.3 ; extra == "doc"
|
44
|
+
Requires-Dist: plotly==5.24.1 ; extra == "doc"
|
45
|
+
Requires-Dist: pypandoc==1.14 ; extra == "doc"
|
44
46
|
Requires-Dist: pytest-sphinx==0.6.3 ; extra == "doc"
|
45
47
|
Requires-Dist: pythreejs==2.4.2 ; extra == "doc"
|
46
48
|
Requires-Dist: pyvista>=0.39.1 ; extra == "doc"
|
47
|
-
Requires-Dist: sphinx-autobuild==2024.
|
48
|
-
Requires-Dist: sphinx-autodoc-typehints==2.
|
49
|
+
Requires-Dist: sphinx-autobuild==2024.10.3 ; extra == "doc"
|
50
|
+
Requires-Dist: sphinx-autodoc-typehints==2.5.0 ; extra == "doc"
|
49
51
|
Requires-Dist: sphinx-copybutton==0.5.2 ; extra == "doc"
|
50
52
|
Requires-Dist: sphinx_design==0.6.1 ; extra == "doc"
|
51
|
-
Requires-Dist: sphinx-gallery==0.
|
53
|
+
Requires-Dist: sphinx-gallery==0.18.0 ; extra == "doc"
|
52
54
|
Requires-Dist: sphinx-notfound-page==1.0.4 ; extra == "doc"
|
53
55
|
Requires-Dist: sphinxcontrib-websupport==2.0.0 ; extra == "doc"
|
54
56
|
Requires-Dist: sphinxemoji==0.3.1 ; extra == "doc"
|
55
|
-
Requires-Dist: pytest==8.3.
|
57
|
+
Requires-Dist: pytest==8.3.3 ; extra == "tests"
|
56
58
|
Requires-Dist: pytest-cov==5.0.0 ; extra == "tests"
|
57
|
-
Requires-Dist: pytest-print==1.0.
|
59
|
+
Requires-Dist: pytest-print==1.0.2 ; extra == "tests"
|
60
|
+
Requires-Dist: psutil==6.1.0 ; extra == "tests"
|
58
61
|
Requires-Dist: ansys-tools-visualization-interface>=0.2.6 ; extra == "viz"
|
59
|
-
Requires-Dist: usd-core==24.
|
62
|
+
Requires-Dist: usd-core==24.11 ; extra == "viz"
|
60
63
|
Project-URL: Changelog, https://mechanical.docs.pyansys.com/version/stable/changelog.html
|
61
64
|
Project-URL: Documentation, https://mechanical.docs.pyansys.com
|
62
65
|
Project-URL: Homepage, https://github.com/ansys/pymechanical
|
@@ -2,26 +2,29 @@ ansys/mechanical/core/__init__.py,sha256=91oPPatmqRyry_kzusIq522MQNiBgN5Of54zDMI
|
|
2
2
|
ansys/mechanical/core/_version.py,sha256=V2aPQlSX4bCe1N1hLIkQaed84WN4s9wl6Q7890ZihNU,1744
|
3
3
|
ansys/mechanical/core/errors.py,sha256=oGaBH-QZxen3YV3IChAFv8bwW5rK_IXTYgDqbX5lp1E,4508
|
4
4
|
ansys/mechanical/core/feature_flags.py,sha256=L88vHrI2lRjZPPUTW5sqcdloeK3Ouh8vt1VPfZLs5Wc,2032
|
5
|
-
ansys/mechanical/core/
|
5
|
+
ansys/mechanical/core/ide_config.py,sha256=Sbzax5Pf7FK0XAMhzcsBJu_8CclABLKuebDCqlvHN_0,7334
|
6
|
+
ansys/mechanical/core/launcher.py,sha256=dS3hN8RwiRh_c2RlXV5MVL7pgKZG5ZiNWreWQf3E800,6675
|
6
7
|
ansys/mechanical/core/logging.py,sha256=wQ8QwKd2k0R6SkN7cv2nHAO7V5-BrElEOespDNMpSLo,24554
|
7
|
-
ansys/mechanical/core/mechanical.py,sha256=
|
8
|
+
ansys/mechanical/core/mechanical.py,sha256=tLvmQ8gaFIFbiDdKT300uX8U32g8qC731zB0GWpwIKQ,79972
|
8
9
|
ansys/mechanical/core/misc.py,sha256=edm2UnklbooYW_hQUgk4n_UFCtlSGAVYJmC2gag74vw,5370
|
9
|
-
ansys/mechanical/core/pool.py,sha256=
|
10
|
-
ansys/mechanical/core/run.py,sha256=
|
10
|
+
ansys/mechanical/core/pool.py,sha256=F-Ckbc5c0V8OvYLOxoV2oJ3E8QOmPG0hH9XA07h3eAU,26586
|
11
|
+
ansys/mechanical/core/run.py,sha256=KgSL2XEyCxK7iq_XVDNEv6fx7SN56RA-ihNg2dLyuZc,9920
|
11
12
|
ansys/mechanical/core/embedding/__init__.py,sha256=y0yp3dnBW2oj9Jh_L_qfZstAbpON974EMmpV9w3kT3g,1356
|
12
|
-
ansys/mechanical/core/embedding/addins.py,sha256=
|
13
|
-
ansys/mechanical/core/embedding/app.py,sha256=
|
13
|
+
ansys/mechanical/core/embedding/addins.py,sha256=2-de-sIOWjO5MCKdBHC2LFxTItr1DUztABIONTQhiWc,2167
|
14
|
+
ansys/mechanical/core/embedding/app.py,sha256=WKMN_2UQHEo-fsE0yqtVCZwA4ItSq13NvRz22r7QS1g,18708
|
14
15
|
ansys/mechanical/core/embedding/app_libraries.py,sha256=RiTO23AzjssAylIH2DaTa6mcJmxhfrlHW-yYvHpIkt0,2923
|
15
16
|
ansys/mechanical/core/embedding/appdata.py,sha256=krcmcgHhraHIlORFr43QvUXlAiXg231g_2iOIxkW_aQ,4223
|
16
|
-
ansys/mechanical/core/embedding/background.py,sha256=
|
17
|
+
ansys/mechanical/core/embedding/background.py,sha256=QxR5QE1Q2gdcVy6QTy-PYmTOyXAhgYV7wqLV2bxUV4I,3731
|
18
|
+
ansys/mechanical/core/embedding/cleanup_gui.py,sha256=GvWX2ylGBb5k1Hgz9vUywXNgWpDVwZ6L2M4gaOXyxl4,2354
|
17
19
|
ansys/mechanical/core/embedding/enum_importer.py,sha256=3REw7SI_WmfPuzD0i9mdC7k53S-1jxhowqSxjzw7UGk,1543
|
18
20
|
ansys/mechanical/core/embedding/imports.py,sha256=FcpePAi867YCuCH_lJotrLzYc1MW5VSAaLpYz7RejcA,4287
|
19
|
-
ansys/mechanical/core/embedding/initializer.py,sha256
|
21
|
+
ansys/mechanical/core/embedding/initializer.py,sha256=I09XzY7QFhCvaHlrLDrx9U-8Bib9vS9yvFQnWOscSzw,8025
|
20
22
|
ansys/mechanical/core/embedding/loader.py,sha256=UgWN7C4hGMWiHhoMUdRKRyWaOwcsgw5auoW1ZqLtZDs,2503
|
21
23
|
ansys/mechanical/core/embedding/poster.py,sha256=V0-cm229HgpOgcYXa0bnz0U5BDGw8_AVE6LKXyPCEjo,2107
|
22
24
|
ansys/mechanical/core/embedding/resolver.py,sha256=95jUvZhNFEJBlbAbclzpK1Wgk51KsnYOKa5HvC7Oeco,1878
|
23
25
|
ansys/mechanical/core/embedding/runtime.py,sha256=zDxwKDTc23cR_kc63M9u4zDWVoJ2efEtF3djHGwicG4,2285
|
24
26
|
ansys/mechanical/core/embedding/shims.py,sha256=IJHhUmfsCtYEUFmuf2LGgozTiu03D0OZn1Qq1nCxXiI,1732
|
27
|
+
ansys/mechanical/core/embedding/ui.py,sha256=6LRLzfPZq2ktdToo8V-pCwoha_GzFZen_VdQeFmW0DE,8497
|
25
28
|
ansys/mechanical/core/embedding/utils.py,sha256=UObL4XBvx19aAYV8iVM4eCQR9vfqNSDsdwqkb1VFwTY,1900
|
26
29
|
ansys/mechanical/core/embedding/warnings.py,sha256=igXfTCkDb8IDQqYP02Cynsqr7ewnueR12Dr0zpku7Kw,3071
|
27
30
|
ansys/mechanical/core/embedding/logger/__init__.py,sha256=XgC05i7r-YzotLtcZ5_rGtA0jDKzeuZiDB88d2pIL7o,7986
|
@@ -32,11 +35,11 @@ ansys/mechanical/core/embedding/logger/windows_api.py,sha256=OCJ-SJEY7EjigZiW6H5
|
|
32
35
|
ansys/mechanical/core/embedding/viz/__init__.py,sha256=xgpBdf3yfEq3sn0bNewLwtje-SCH6vVWEmHfCdh6078,1206
|
33
36
|
ansys/mechanical/core/embedding/viz/embedding_plotter.py,sha256=ausbFhezwmLCGhu61JZJDM_uxwpRRuM-XWw9mk4i0GQ,3689
|
34
37
|
ansys/mechanical/core/embedding/viz/usd_converter.py,sha256=feDq2KrZhYL-RR1miECQL-y0VNDhnZQ9Wke5UOkYmp4,5329
|
35
|
-
ansys/mechanical/core/embedding/viz/utils.py,sha256=
|
38
|
+
ansys/mechanical/core/embedding/viz/utils.py,sha256=FuGDh7a5mUqs2UZOaXZLD0vONdmDXl5JfDRilIVbjds,3660
|
36
39
|
ansys/mechanical/core/examples/__init__.py,sha256=A1iS8nknTU1ylafHZpYC9LQJ0sY83x8m1cDXsgvFOBo,1267
|
37
|
-
ansys/mechanical/core/examples/downloads.py,sha256=
|
38
|
-
ansys_mechanical_core-0.11.
|
39
|
-
ansys_mechanical_core-0.11.
|
40
|
-
ansys_mechanical_core-0.11.
|
41
|
-
ansys_mechanical_core-0.11.
|
42
|
-
ansys_mechanical_core-0.11.
|
40
|
+
ansys/mechanical/core/examples/downloads.py,sha256=rYFsq8U3YpXi_DVx_Uu5sRFFUS85ks6rMJfcgyvBat0,4295
|
41
|
+
ansys_mechanical_core-0.11.9.dist-info/entry_points.txt,sha256=tErx6bIM27HGgwyM6ryyTUTw30Ab2F9J3FFkX2TPkhI,130
|
42
|
+
ansys_mechanical_core-0.11.9.dist-info/LICENSE,sha256=gBJ2GQ6oDJwAWxcxmjx_0uXc-N0P4sHhA7BXsdPTfco,1098
|
43
|
+
ansys_mechanical_core-0.11.9.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
|
44
|
+
ansys_mechanical_core-0.11.9.dist-info/METADATA,sha256=y7oWZjaJBccSx1Lx1mEMaIvJ6S6muD8OMmU29NIzn3o,9887
|
45
|
+
ansys_mechanical_core-0.11.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|