You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/source/user_guide/ansys_downloader.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
Ansys example downloader
4
4
========================
5
5
6
-
Use the Ansys example downloader to download examples from a PyAnsys library. After you import this tool, specify the filename, directory, and local path for the file to download:
6
+
Use the Ansys example downloader to download an example from a PyAnsys library. Import this tool and then specify the filename, directory, and local path for the file to download:
Copy file name to clipboardExpand all lines: doc/source/user_guide/ansys_exceptions.rst
+16-2Lines changed: 16 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,11 @@
3
3
Ansys exceptions
4
4
================
5
5
6
-
Use the Ansys exceptions tool to gracefully catch and handle exceptions that might occur when using Ansys tools, thereby providing a better user experience.
6
+
Ansys exceptions are a set of predefined error-handling classes designed to help developers identify, catch, and handle errors that might occur when using Ansys tools. These exceptions provide a structured way to manage errors, ensuring that your programs can gracefully recover from unexpected issues and provide meaningful feedback to users.
7
7
8
-
After importing this tool, use the base :class:`AnsysError <ansys.tools.common.exceptions.AnsysError>` class to catch and handle exceptions related to Ansys tools, extending with your exceptions or using them directly in your programs:
8
+
By using Ansys exceptions, you can improve the robustness and maintainability of your code. They allow you to differentiate between various types of errors, such as invalid input types or logical inconsistencies, and handle them appropriately.
9
+
10
+
You can import exception classes and use the predefined exceptions directly in your programs:
9
11
10
12
.. code:: pycon
11
13
@@ -18,3 +20,15 @@ After importing this tool, use the base :class:`AnsysError <ansys.tools.common.e
18
20
AnsysTypeError: An invalid type was provided.
19
21
>>> raise AnsysLogicError("A logic error occurred in Ansys tools.")
20
22
AnsysLogicError: A logic error occurred in Ansys tools.
23
+
24
+
You can also extend the base exception class to define your own custom exceptions. This allows you to create error types specific to your needs:
25
+
26
+
```python
27
+
class CustomError(AnsysError):
28
+
"""A custom exception for specific error handling."""
29
+
30
+
pass
31
+
32
+
33
+
raise CustomError("This is a custom error message.")
Copy file name to clipboardExpand all lines: doc/source/user_guide/ansys_tools_path.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
Ansys path tool
4
4
===============
5
5
6
-
Use the Ansys path tool to find the path of the latest local Ansys installation. After importing this tool, call the :func:`find_ansys <ansys.tools.common.path.find_ansys>` function to return the installation path:
6
+
Use the Ansys path tool to find the path of the latest local Ansys installation. Importing this tool and then call the :func:`find_ansys <ansys.tools.common.path.find_ansys>` function to return the installation path:
Copy file name to clipboardExpand all lines: doc/source/user_guide/index.rst
+4-6Lines changed: 4 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,12 +4,10 @@
4
4
User guide
5
5
==========
6
6
7
-
This section explains key concepts for implementing its set of tools in your
8
-
PyAnsys workflows. You can use these tools in your examples as well as integrate Ansys Common Tools into your own code.
7
+
This section explains key concepts for implementing the tools in Ansys Common Tools in your PyAnsys workflows. You can use these tools in your examples as well as integrate them into your own code.
9
8
10
9
.. important::
11
-
This library only supports the last two major versions of Python. Usage with older
12
-
versions might or might not work.
10
+
Ansys Common Tools only supports the last two major versions of Python. Usage with older versions might not work.
13
11
14
12
15
13
@@ -20,14 +18,14 @@ PyAnsys workflows. You can use these tools in your examples as well as integrate
Copy file name to clipboardExpand all lines: doc/source/user_guide/launcher/index.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
Local product launcher
2
2
----------------------
3
3
4
-
Use the local product launcher rather than launch functions implemented by various PyAnsys libraries. These pages provide an overview and describes how to use it.
4
+
Use the local product launcher rather than the launch functions implemented by various PyAnsys libraries. These pages provide an overview and describe how to use the local product launcher:
5
5
6
6
- :ref:`rationale`: Provides a high-level overview of the problem that the
Copy file name to clipboardExpand all lines: doc/source/user_guide/launcher/plugin_creation.rst
+33-46Lines changed: 33 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,10 +3,9 @@
3
3
Launcher plugin creation
4
4
------------------------
5
5
6
-
This page explains how to create a plugin for the Local Product Launcher. The plugin
7
-
in the example launches Ansys Composite PrepPost (ACP) as a subprocess.
6
+
This page explains how to create a plugin for the local product launcher. The plugin in the example launches Ansys Composite PrepPost (ACP) as a subprocess.
8
7
9
-
The Local Product Launcher defines the interface that a plugin must satisfy in the :mod:`.interface` module.
8
+
The local product launcher defines the interface that a plugin must satisfy in the :mod:`.interface` module.
10
9
11
10
.. note::
12
11
@@ -88,14 +87,13 @@ there's quite a lot going on in this code, descriptions of each part are provide
88
87
return {"main": self._url}
89
88
90
89
91
-
The launcher class inherits from ``LauncherProtocol[LauncherConfig]``. This isn't a requirement, but it means a type checker like `mypy<https://mypy.readthedocs.io>`_ can verify that the :class:`.LauncherProtocol` interface is fulfilled.
90
+
The launcher class inherits from ``LauncherProtocol[LauncherConfig]``. This isn't a requirement, but it means a type checker like `Mypy<https://mypy.readthedocs.io>`_ can verify that the :class:`.LauncherProtocol` interface is fulfilled.
92
91
93
92
Next, setting ``CONFIG_MODEL = DirectLauncherConfig`` connects the launcher to the configuration class.
94
93
95
94
The subsequent line, ``SERVER_SPEC = {"main": ServerType.GRPC}``, defines which kind of servers the
96
-
product starts. Here, there's only a single server, which is accessible via gRPC. The keys in this
97
-
dictionary can be chosen arbitrarily, but they should be consistent across the launcher implementation.
98
-
Ideally, you use the key to convey some meaning. For example, ``"main"`` could refer to the main interface
95
+
product starts. Here, there's only a single server, which is accessible via gRPC. The keys in this dictionary can be chosen arbitrarily, but they should be consistent across the launcher implementation.
96
+
Ideally, use the key to convey some meaning. For example, ``"main"`` could refer to the main interface
99
97
to your product and ``file_transfer`` could refer to an additional service for file upload and download.
100
98
101
99
The ``__init__`` method must accept exactly one keyword-only argument, ``config``, which contains the
@@ -109,7 +107,7 @@ For the ``_url`` and ``_process`` attributes, only the type is declared for the
109
107
self._url: str
110
108
self._process: subprocess.Popen[str]
111
109
112
-
The core of the launcher implementation is in the ``start()`` and ``stop()`` methods:
110
+
The core of the launcher implementation is in the ``start`` and ``stop`` methods:
113
111
114
112
.. code:: python
115
113
@@ -126,11 +124,11 @@ The core of the launcher implementation is in the ``start()`` and ``stop()`` met
126
124
text=True,
127
125
)
128
126
129
-
This:meth:`start()<.LauncherProtocol.start>` method selects an available port using the
130
-
:func:`.find_free_ports` function. It then starts the server as a subprocess. Note that here, the server output is simply discarded. In a real launcher, the option to redirect it (for example to a file) should be added.
127
+
The:meth:`start<.LauncherProtocol.start>` method selects an available port using the
128
+
:func:`.find_free_ports` function. It then starts the server as a subprocess. Note that here, the server output is simply discarded. In a real launcher, you should add the option to redirect it (for example to a file).
131
129
The ``_url`` attribute keeps track of the URL and port that the server should be accessible on.
132
130
133
-
The :meth:`start()<.LauncherProtocol.stop>` method terminates the subprocess:
131
+
The :meth:`start<.LauncherProtocol.stop>` method terminates the subprocess:
134
132
135
133
.. code:: python
136
134
@@ -143,12 +141,12 @@ The :meth:`start()<.LauncherProtocol.stop>` method terminates the subprocess:
143
141
self._process.wait()
144
142
145
143
If your product is prone to ignoring ``SIGTERM``, you might want to add a timeout to the
146
-
:py:meth:`.wait() <subprocess.Popen.wait>` method and retry with the
147
-
:py:meth:`.kill() <subprocess.Popen.kill>` method instead of the
Finally, the ``_url`` attribute stored in the :meth:`start() <.LauncherProtocol.start>` method must
159
+
Finally, the ``_url`` attribute stored in the :meth:`start <.LauncherProtocol.start>` method must
162
160
be made available in the :attr:`urls <.LauncherProtocol.urls>` property:
163
161
164
162
.. code:: python
@@ -174,19 +172,17 @@ Note that the return value for the ``urls`` property should adhere to the schema
174
172
Register entrypoint
175
173
'''''''''''''''''''
176
174
177
-
Having defined all the necessary components for a Local Product Launcher plugin, you can now register the
178
-
plugin, which makes it available. You do this through the Python `entrypoints <https://packaging.python.org/specifications/entry-points/>`_
179
-
mechanism.
175
+
Having defined all the necessary components for a local product launcher plugin, you can now register the
176
+
plugin, which makes it available. You do this through the Python `entrypoints mechanism <https://packaging.python.org/specifications/entry-points/>`_.
180
177
181
-
You define the entrypoint in your package's build configuration. The exact syntax depends on which
182
-
packaging tool you use:
178
+
You define the entrypoint in your package's build configuration. The exact syntax depends on which packaging tool you use:
183
179
184
180
.. .. grid:: 1
185
181
.. :gutter: 3
186
182
187
183
.. tab-set::
188
184
189
-
.. tab-item:: setuptools
185
+
.. tab-item:: Setuptools
190
186
191
187
Setuptools can accept its configuration in one of three ways. Choose the one that applies to your project:
192
188
@@ -221,9 +217,9 @@ packaging tool you use:
221
217
)
222
218
223
219
224
-
For more information, see the `setuptools documentation <https://setuptools.pypa.io/en/latest/userguide/entry_point.html#entry-points-for-plugins>`_.
220
+
For more information, see the `Entry Points for Plugins <https://setuptools.pypa.io/en/latest/userguide/entry_point.html#entry-points-for-plugins>`_ in the Setuptools documentation.
For more information, see the `flit documentation <https://flit.pypa.io/en/stable/pyproject_toml.html#pyproject-project-entrypoints>`_.
231
+
For more information, see the `Entry points sections <https://flit.pypa.io/en/stable/pyproject_toml.html#pyproject-project-entrypoints>`_ in the Flit documentation.
For more information, see the `poetry documentation <https://python-poetry.org/docs/pyproject#plugins>`_.
242
+
For more information, see the `plugins <https://python-poetry.org/docs/pyproject#plugins>`_ in the Poetry documentation.
247
243
248
-
In all cases, ``ansys.tools.local_product_launcher.launcher`` is an identifier specifying that the entrypoint defines a Local Product Launcher plugin. It must be kept the same.
244
+
In all cases, ``ansys.tools.local_product_launcher.launcher`` is an identifier specifying that the entrypoint defines a local product launcher plugin. It must be kept the same.
249
245
250
246
The entrypoint itself has two parts:
251
247
252
-
- The entrypoint name ``ACP.direct`` consists of two parts: ``ACP`` is the product name, and
253
-
``direct`` is the launch mode identifier. The name must be of this format and contain exactly
254
-
one dot ``.`` separating the two parts.
255
-
- The entrypoint value ``<your.module.name>:DirectLauncher`` defines where the launcher
256
-
implementation is located. In other words, it must load the launcher class:
248
+
- The entrypoint name ``ACP.direct`` consists of two parts: ``ACP`` is the product name, and ``direct`` is the launch mode identifier. The name must be of this format and contain exactly one dot ``.`` separating the two parts.
249
+
- The entrypoint value ``<your.module.name>:DirectLauncher`` defines where the launcher implementation is located. In other words, it must load the launcher class:
257
250
258
251
.. code::
259
252
260
253
from <your.module.name> import DirectLauncher
261
254
262
255
263
-
For the entrypoints to update, you must re-install your package (even if it was installed with ``pip install -e``).
256
+
For the entrypoints to update, you must re-install your package (even if it was installed with the ``pip install -e`` command).
264
257
265
258
Add command-line default and description
266
259
''''''''''''''''''''''''''''''''''''''''
267
260
268
-
With the three preceding parts, you've successfully created a Local Product Launcher plugin. :octicon:`rocket`
261
+
With the three preceding parts, you've successfully created a local product launcher plugin. :octicon:`rocket`
269
262
270
-
You can now improve the usability of the command line by adding a default and description to the configuration class.
263
+
You can now improve the usability of the command line by adding a default and a description to the configuration class.
271
264
272
265
To do so, edit the ``DirectLaunchConfig`` class, using the :py:func:`dataclasses.field` function to enrich
273
266
the ``binary_path``:
274
267
275
268
* The default value is specified as the ``default`` argument.
276
269
* The description is given in the ``metadata`` dictionary, using the special key :py:obj:`METADATA_KEY_DOC <.interface.METADATA_KEY_DOC>`.
277
270
278
-
279
271
.. code:: python
280
272
281
273
import os
@@ -309,23 +301,18 @@ the ``binary_path``:
309
301
For the default value, use the :py:func:`get_available_ansys_installations <path.get_available_ansys_installations>`
310
302
helper to find the Ansys installation directory.
311
303
312
-
Now, when running ``ansys-launcher configure ACP direct``, users can see and accept the default
313
-
value if they want.
304
+
Now, when running ``ansys-launcher configure ACP direct``, users can see and accept the default value if they want.
314
305
315
306
.. note::
316
307
317
-
If the default value is ``None``, it is converted to the string ``default`` for the
318
-
command-line interface. This allows implementing more complicated default behaviors
319
-
that may not be expressible when the command-line interface is run.
308
+
If the default value is ``None``, it is converted to the string ``default`` for command-line interface. This allows implementing more complicated default behaviors that may not be expressible when the command-line interface is run.
320
309
321
310
Add a fallback launch mode
322
311
''''''''''''''''''''''''''
323
312
324
-
If you want to provide a fallback launch mode that can be used without any configuration, you can add
325
-
an entrypoint with the special name ``<product>.__fallback__``.
313
+
If you want to provide a fallback launch mode that can be used without any configuration, you can add an entrypoint with the special name ``<product>.__fallback__``.
326
314
327
-
For example, if you wanted the ``DirectLauncher`` to be the fallback for ACP, you could add this
328
-
entrypoint:
315
+
For example, to make ``DirectLauncher`` the fallback for ACP, add this entry point:
0 commit comments