The helpers.py module#
Summary#
Determine the gRPC transport mode and certificate directory to use. |
|
List running Mechanical instances on the system. |
|
Get information from the Mechanical instance. |
Description#
Helper functions for PyMechanical-MCP.
Module detail#
- helpers.resolve_transport_mode(transport_mode: str | None = None, certs_dir: str | None = None) tuple[str | None, str | None]#
Determine the gRPC transport mode and certificate directory to use.
The resolution strategy follows:
Explicit override: If the caller (CLI flag, environment variable, or tool parameter) supplies a concrete mode (
insecure,mtls, orwnua), honor it unconditionally.- Auto-detect (
transport_modeisNoneor"auto"): On Windows: Return
Noneso that PyMechanical applies its own platform default (wnua).On Linux / Docker: Return
"mtls"plus the resolved certificate directory when mTLS certificate files are found. Otherwise, return"insecure"(the only mode that can succeed without certificates). WNUA is Windows-only.
- Auto-detect (
- Parameters:
- Returns:
- Raises:
ValueErrorIf
transport_modeis not one of the accepted values.
- helpers.list_instances(instances: bool = False, long: bool = False, cmd: bool = False, location: bool = False) str#
List running Mechanical instances on the system.
This function scans all running processes to identify Ansys Mechanical instances that are using gRPC communication. It returns a formatted table with information about each discovered instance.
- Parameters:
- instancesbool, default:
False If
True, only show main Mechanical instances (exclude child processes). IfFalse, show all Mechanical-related processes.- longbool, default:
False If
True, enable verbose output including command line and working directory. This automatically sets bothcmdandlocationtoTrue.- cmdbool, default:
False If
True, include the command-line arguments in the output table.- locationbool, default:
False If
True, include the working directory path in the output table.
- instancesbool, default:
- Returns:
strA formatted table string containing information about Mechanical instances. The table includes columns for process name, status, gRPC port, PID, and optionally the command line and working directory based on the parameters.
Notes
This function identifies Mechanical processes by looking for
AnsysWBUormechanicalin the process name or command line.Only processes with status
RUNNING,IDLE, orSLEEPINGare considered valid.
- helpers.get_info(mechanical: ansys.mechanical.core.Mechanical) dict[str, str | dict[str, Any]]#
Get information from the Mechanical instance.
- helpers.VALID_TRANSPORT_MODES#
- helpers.logger#