The misc.py module#

Summary#

is_windows

Check if the host machine is on Windows.

get_mechanical_bin

Get the path for the Mechanical executable file based on the release version.

threaded

Decorate a function with this decorator to call it using a thread.

threaded_daemon

Decorate a function with this decorator to call it using a daemon thread.

check_valid_ip

Check if the IP address is valid.

check_valid_port

Check if the port is valid.

check_valid_start_instance

Check if the value obtained from the environmental variable is valid.

is_float

Check if a string can be converted to a float.

has_grpc_service_pack

Check if the Mechanical version supports advanced gRPC security options.

get_service_pack_message

Get the required service pack message for a given version.

is_linux

Check if the host machine is Linux.

resolve_certs_dir

Resolve the certificate directory for mTLS connections.

Description#

Contain miscellaneous functions and methods at the module level.

Module detail#

misc.is_windows()#

Check if the host machine is on Windows.

Returns:
True if the host machine is on Windows, False otherwise.
misc.get_mechanical_bin(release_version)#

Get the path for the Mechanical executable file based on the release version.

Parameters:
release_version: str

Mechanical version using the three-digit format. For example, "252" for 2025 R2.

misc.threaded(func)#

Decorate a function with this decorator to call it using a thread.

misc.threaded_daemon(func)#

Decorate a function with this decorator to call it using a daemon thread.

misc.check_valid_ip(ip)#

Check if the IP address is valid.

Parameters:
ipstr

IP address to check.

misc.check_valid_port(port, lower_bound=1000, high_bound=60000)#

Check if the port is valid.

Parameters:
portint

Port to check.

lower_boundint, optional

Lowest possible value for the port. The default is 1000.

high_boundint, optional

Highest possible value for the port. The default is 60000.

misc.check_valid_start_instance(start_instance)#

Check if the value obtained from the environmental variable is valid.

Parameters:
start_instancestr, bool

Value obtained from the corresponding environment variable.

Returns:
bool

True if start_instance is True or "True", False otherwise.

misc.is_float(input_string)#

Check if a string can be converted to a float.

Parameters:
input_stringstr

String to check.

Returns:
bool

True when conversion is possible, False otherwise.

misc.has_grpc_service_pack(version)#

Check if the Mechanical version supports advanced gRPC security options.

Advanced gRPC options (transport modes and host binding) require specific service packs: - 2024 R2 (242): requires SP05+ - 2025 R1 (251): requires SP04+ - 2025 R2 (252): requires SP03+ - 2026 R1 (261)+: all versions supported

Parameters:
versionint

Mechanical version number (e.g., 242, 251, 252, 261).

Returns:
bool

True if version has required service pack for gRPC security, False otherwise.

misc.get_service_pack_message(version)#

Get the required service pack message for a given version.

Parameters:
versionint

Mechanical version number (e.g., 241, 242, 251, 252).

Returns:
str

Message indicating required service pack, or empty string if not applicable.

misc.is_linux() bool#

Check if the host machine is Linux.

Returns:
True if the host machine is Linux, False otherwise.
misc.resolve_certs_dir(transport_mode, certs_dir=None)#

Resolve the certificate directory for mTLS connections.

Checks the ANSYS_GRPC_CERTIFICATES environment variable if: - transport_mode is “mtls” - certs_dir is None (not explicitly provided by user) - On Windows: only if the variable is set at user level - On Linux: at any level

Parameters:
transport_modestr

Transport mode being used (insecure, mtls, wnua).

certs_dirstr, optional

Certificate directory path. Default is None, which triggers environment variable lookup for mTLS, then defaults to “certs”.

Returns:
str

Resolved certificate directory path.