Skip to content

FEAT: Add option for pep8 aliases in binding #1234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/1234.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add option for pep8 aliases in binding
23 changes: 19 additions & 4 deletions src/ansys/mechanical/core/embedding/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,20 @@ def __register_function_codec():
Ansys.Mechanical.CPython.Codecs.FunctionCodec.Register()


def _bind_assembly_for_explicit_interface(assembly_name: str):
"""Bind the assembly for explicit interface implementation."""
def _bind_assembly(
assembly_name: str, explicit_interface: bool = False, pep8_aliases: bool = False
) -> None:
"""Bind the assembly for explicit interface and/or pep8 aliases.

Parameters
----------
assembly_name : str
The name of the assembly to bind.
explicit_interface : bool, optional
If True, allows explicit interface implementation. Default is False.
pep8_aliases : bool, optional
If True, enables PEP 8 aliases. Default is False.
"""
# if pythonnet is not installed, we can't bind the assembly
try:
distribution("pythonnet")
Expand All @@ -64,7 +76,10 @@ def _bind_assembly_for_explicit_interface(assembly_name: str):
from Python.Runtime import BindingManager, BindingOptions

binding_options = BindingOptions()
binding_options.AllowExplicitInterfaceImplementation = True
if explicit_interface:
binding_options.AllowExplicitInterfaceImplementation = True
if pep8_aliases:
binding_options.Pep8Aliases = True
BindingManager.SetBindingOptions(assembly, binding_options)


Expand All @@ -86,4 +101,4 @@ def initialize(version: int) -> None:
__register_function_codec()
Logger.debug("Registered function codec")

_bind_assembly_for_explicit_interface("Ansys.ACT.WB1")
_bind_assembly("Ansys.ACT.WB1", True, True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make it opt-in for now, like this:

app = App(pep8=True)

until it has gone through more usage/testing.

Loading