@@ -45,30 +45,44 @@ def __register_function_codec():
45
45
Ansys .Mechanical .CPython .Codecs .FunctionCodec .Register ()
46
46
47
47
48
- def _bind_assembly_for_explicit_interface (assembly_name : str ):
49
- """Bind the assembly for explicit interface implementation."""
48
+ def _bind_assembly (
49
+ assembly_name : str , explicit_interface : bool = False , pep8_aliases : bool = False
50
+ ) -> None :
51
+ """Bind the assembly for explicit interface and/or pep8 aliases.
52
+
53
+ Parameters
54
+ ----------
55
+ assembly_name : str
56
+ The name of the assembly to bind.
57
+ explicit_interface : bool, optional
58
+ If True, allows explicit interface implementation. Default is False.
59
+ pep8_aliases : bool, optional
60
+ If True, enables PEP 8 aliases. Default is False.
61
+ """
50
62
# if pythonnet is not installed, we can't bind the assembly
51
63
try :
52
64
distribution ("pythonnet" )
53
65
Logger .warning ("Cannot bind for explicit interface because pythonnet is installed" )
54
66
return
55
67
except ModuleNotFoundError :
56
68
pass
57
-
58
- Logger .debug (f"Binding assembly for explicit interface { assembly_name } " )
59
69
import clr
60
70
61
- Logger .debug (f"Binding assembly for explicit interface, Loading { assembly_name } " )
71
+ Logger .debug (f"Binding assembly { assembly_name } " )
62
72
assembly = clr .AddReference (assembly_name )
63
- Logger .debug (f"Binding assembly for explicit interface, Loaded { assembly_name } " )
64
73
from Python .Runtime import BindingManager , BindingOptions
65
74
66
75
binding_options = BindingOptions ()
67
- binding_options .AllowExplicitInterfaceImplementation = True
76
+ if explicit_interface :
77
+ Logger .debug (f"Binding explicit interface for { assembly_name } " )
78
+ binding_options .AllowExplicitInterfaceImplementation = True
79
+ if pep8_aliases :
80
+ Logger .debug (f"Setting PEP 8 aliases for { assembly_name } " )
81
+ binding_options .Pep8Aliases = True
68
82
BindingManager .SetBindingOptions (assembly , binding_options )
69
83
70
84
71
- def initialize (version : int ) -> None :
85
+ def initialize (version : int , pep8_aliases : bool = False ) -> None :
72
86
"""Initialize the runtime.
73
87
74
88
Pythonnet is already initialized but we need to
@@ -86,4 +100,14 @@ def initialize(version: int) -> None:
86
100
__register_function_codec ()
87
101
Logger .debug ("Registered function codec" )
88
102
89
- _bind_assembly_for_explicit_interface ("Ansys.ACT.WB1" )
103
+ explicit_interface = True
104
+
105
+ if os .environ .get ("PYMECHANICAL_EXPLICIT_INTERFACE" ) == "0" :
106
+ explicit_interface = False
107
+
108
+ # TODO: When the pep8_aliases option is enabled (True by default),
109
+ # keep three environment variables to turn explicit, pep8, and both off.
110
+
111
+ _bind_assembly (
112
+ "Ansys.ACT.WB1" , explicit_interface = explicit_interface , pep8_aliases = pep8_aliases
113
+ )
0 commit comments