ansys-mechanical-core 0.10.10__py3-none-any.whl → 0.11.12__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 (46) hide show
  1. ansys/mechanical/core/__init__.py +11 -4
  2. ansys/mechanical/core/_version.py +48 -47
  3. ansys/mechanical/core/embedding/__init__.py +1 -1
  4. ansys/mechanical/core/embedding/addins.py +1 -7
  5. ansys/mechanical/core/embedding/app.py +610 -281
  6. ansys/mechanical/core/embedding/app_libraries.py +24 -5
  7. ansys/mechanical/core/embedding/appdata.py +16 -4
  8. ansys/mechanical/core/embedding/background.py +106 -0
  9. ansys/mechanical/core/embedding/cleanup_gui.py +61 -0
  10. ansys/mechanical/core/embedding/enum_importer.py +2 -2
  11. ansys/mechanical/core/embedding/imports.py +27 -7
  12. ansys/mechanical/core/embedding/initializer.py +105 -53
  13. ansys/mechanical/core/embedding/loader.py +19 -9
  14. ansys/mechanical/core/embedding/logger/__init__.py +219 -216
  15. ansys/mechanical/core/embedding/logger/environ.py +1 -1
  16. ansys/mechanical/core/embedding/logger/linux_api.py +1 -1
  17. ansys/mechanical/core/embedding/logger/sinks.py +1 -1
  18. ansys/mechanical/core/embedding/logger/windows_api.py +2 -2
  19. ansys/mechanical/core/embedding/poster.py +38 -4
  20. ansys/mechanical/core/embedding/resolver.py +41 -44
  21. ansys/mechanical/core/embedding/runtime.py +1 -1
  22. ansys/mechanical/core/embedding/shims.py +9 -8
  23. ansys/mechanical/core/embedding/ui.py +228 -0
  24. ansys/mechanical/core/embedding/utils.py +1 -1
  25. ansys/mechanical/core/embedding/viz/__init__.py +1 -1
  26. ansys/mechanical/core/embedding/viz/{pyvista_plotter.py → embedding_plotter.py} +24 -8
  27. ansys/mechanical/core/embedding/viz/usd_converter.py +59 -25
  28. ansys/mechanical/core/embedding/viz/utils.py +32 -2
  29. ansys/mechanical/core/embedding/warnings.py +1 -1
  30. ansys/mechanical/core/errors.py +2 -1
  31. ansys/mechanical/core/examples/__init__.py +1 -1
  32. ansys/mechanical/core/examples/downloads.py +10 -5
  33. ansys/mechanical/core/feature_flags.py +51 -0
  34. ansys/mechanical/core/ide_config.py +212 -0
  35. ansys/mechanical/core/launcher.py +9 -9
  36. ansys/mechanical/core/logging.py +14 -2
  37. ansys/mechanical/core/mechanical.py +2324 -2237
  38. ansys/mechanical/core/misc.py +176 -176
  39. ansys/mechanical/core/pool.py +712 -712
  40. ansys/mechanical/core/run.py +321 -246
  41. {ansys_mechanical_core-0.10.10.dist-info → ansys_mechanical_core-0.11.12.dist-info}/LICENSE +7 -7
  42. {ansys_mechanical_core-0.10.10.dist-info → ansys_mechanical_core-0.11.12.dist-info}/METADATA +57 -56
  43. ansys_mechanical_core-0.11.12.dist-info/RECORD +45 -0
  44. {ansys_mechanical_core-0.10.10.dist-info → ansys_mechanical_core-0.11.12.dist-info}/WHEEL +1 -1
  45. {ansys_mechanical_core-0.10.10.dist-info → ansys_mechanical_core-0.11.12.dist-info}/entry_points.txt +1 -0
  46. ansys_mechanical_core-0.10.10.dist-info/RECORD +0 -40
@@ -0,0 +1,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
+
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,4 +1,4 @@
1
- # Copyright (C) 2022 - 2024 ANSYS, Inc. and/or its affiliates.
1
+ # Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates.
2
2
  # SPDX-License-Identifier: MIT
3
3
  #
4
4
  #
@@ -23,10 +23,11 @@
23
23
  """Launch Mechanical in batch or UI mode."""
24
24
  import errno
25
25
  import os
26
- import subprocess
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(args_list, shell=shell_value, env=env_variables)
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
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2022 - 2024 ANSYS, Inc. and/or its affiliates.
1
+ # Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates.
2
2
  # SPDX-License-Identifier: MIT
3
3
  #
4
4
  #
@@ -138,30 +138,42 @@ import weakref
138
138
 
139
139
  # Default configuration
140
140
  LOG_LEVEL = logging.DEBUG
141
+ """Default log level configuration."""
141
142
  FILE_NAME = "pymechanical.log"
143
+ """Default file name."""
142
144
 
143
145
  # For convenience
144
146
  DEBUG = logging.DEBUG
147
+ """Constant for logging.DEBUG."""
145
148
  INFO = logging.INFO
149
+ """Constant for logging.INFO."""
146
150
  WARN = logging.WARN
151
+ """Constant for logging.WARN."""
147
152
  ERROR = logging.ERROR
153
+ """Constant for logging.ERROR."""
148
154
  CRITICAL = logging.CRITICAL
155
+ """Constant for logging.CRITICAL."""
149
156
 
150
157
  # Formatting
151
-
152
158
  STDOUT_MSG_FORMAT = "%(levelname)s - %(instance_name)s - %(module)s - %(funcName)s - %(message)s"
159
+ """Standard output message format."""
153
160
 
154
161
  FILE_MSG_FORMAT = STDOUT_MSG_FORMAT
162
+ """File message format."""
155
163
 
156
164
  DEFAULT_STDOUT_HEADER = """
157
165
  LEVEL - INSTANCE NAME - MODULE - FUNCTION - MESSAGE
158
166
  """
167
+ """Default standard output header."""
168
+
159
169
  DEFAULT_FILE_HEADER = DEFAULT_STDOUT_HEADER
170
+ """Default file header."""
160
171
 
161
172
  NEW_SESSION_HEADER = f"""
162
173
  ===============================================================================
163
174
  NEW SESSION - {datetime.now().strftime("%m/%d/%Y, %H:%M:%S")}
164
175
  ==============================================================================="""
176
+ """Default new session header containing date and time."""
165
177
 
166
178
  string_to_loglevel = {
167
179
  "DEBUG": logging.DEBUG,