The aedt_compat.py module#

Summary#

AedtVersionClashError

Raised when the process already loaded another AEDT version’s gRPC client.

normalize_version

Normalize an AEDT version to the YYYY.R form.

validate_preference

Validate an --aedt-version value.

resolve_default_version

Map an --aedt-version preference to the version to pin.

pin_default_version

Make version the PyAEDT default for this process.

rewrite_desktop_arguments

Fix Desktop.__init__ arguments in place.

install

Apply the version fixes to this process.

VERSION_ENV

Environment variable forwarding --aedt-version to lane backends.

DEFAULT_PREFERENCE

Description#

In-process PyAEDT version fixes applied by lane backends.

PyAEDT treats the newest installed AEDT that is not newer than its CURRENT_STABLE_AEDT_VERSION as the default. With a newer AEDT installed, launch_aedt without a version starts the older release, and connect_to_aedt(port=...) can decide the port belongs to another AEDT version and launch a new session instead of attaching. Also, once a process loads the gRPC client of one AEDT version it can never attach to another version ([WinError 127] The specified procedure could not be found).

install() addresses this without modifying PyAEDT:

  • The default version becomes the newest installed AEDT, or the one chosen with --aedt-version.

  • Attaching to a local port uses the version of the AEDT process on that port.

  • Attaching to a version the process can no longer load fails fast with an actionable message.

Module detail#

aedt_compat.normalize_version(value: Any) → str#

Normalize an AEDT version to the YYYY.R form.

Parameters:
valueAny

Version such as "271", "27.1", "2027.1", or "2027 R1".

Returns:
str

Normalized version, for example "2027.1".

Raises:
ValueError

If value is not a recognized AEDT version.

aedt_compat.validate_preference(value: str) → str#

Validate an --aedt-version value.

Parameters:
valuestr

"latest", "pyaedt", or an AEDT version.

Returns:
str

Normalized preference.

Raises:
ValueError

If value is not a valid preference.

aedt_compat.resolve_default_version(preference: str, installed: collections.abc.Iterable[str]) → str | None#

Map an --aedt-version preference to the version to pin.

Parameters:
preferencestr

"latest" picks the newest regular release in installed, ignoring student and client variants. "pyaedt" keeps the PyAEDT default. Any other value is an explicit version.

installedIterable[str]

Installed version keys, as in aedt_versions.installed_versions.

Returns:
str or None

Version to pin, or None to leave PyAEDT unchanged.

aedt_compat.pin_default_version(version: str) → None#

Make version the PyAEDT default for this process.

Parameters:
versionstr

Normalized AEDT version.

aedt_compat.rewrite_desktop_arguments(arguments: dict[str, Any], *, find_session: collections.abc.Callable[[int], tuple[str, bool] | None], installed: dict[str, str], loaded_plugin_dir: str | None, reusing_session: bool) → list[str]#

Fix Desktop.__init__ arguments in place.

Parameters:
argumentsdict[str, Any]

Bound Desktop.__init__ arguments with defaults applied.

find_sessionCallable[[int], tuple[str, bool] | None]

Returns the version and student flag of the AEDT serving a port.

installeddict[str, str]

Installed versions mapped to their installation directories.

loaded_plugin_dirstr, optional

Directory of the gRPC client already loaded by the process.

reusing_sessionbool

Whether PyAEDT is about to return an existing session. In that case nothing is changed.

Returns:
list[str]

Log messages describing the changes.

Raises:
AedtVersionClashError

If the target version cannot be loaded by this process.

aedt_compat.install(preference: str | None = None) → str | None#

Apply the version fixes to this process.

Calling it more than once is safe.

Parameters:
preferencestr, optional

AEDT version preference. Defaults to VERSION_ENV, then "latest".

Returns:
str or None

Pinned default version, or None if the PyAEDT default is kept.

aedt_compat.VERSION_ENV = 'ANSYS_AEDT_MCP_LANE_AEDT_VERSION'#

Environment variable forwarding --aedt-version to lane backends.

aedt_compat.DEFAULT_PREFERENCE = 'latest'#
aedt_compat.logger#