Skip to content

Commit 5fd8173

Browse files
committed
Update Alias api JSON serializer to work with the upcoming official Alias Python API module.
* Add temp api
1 parent 32acc7a commit 5fd8173

6 files changed

Lines changed: 259 additions & 44 deletions

File tree

3.24 MB
Binary file not shown.

python/tk_framework_alias/client/socketio/proxy_wrapper.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,11 @@ def _create_object(self):
609609
"""
610610

611611
class_attrs = self._get_attributes()
612+
613+
# Remove __slots__ — proxy classes don't need them, and their presence
614+
# causes ValueError when a class variable shares a name with a slot.
615+
class_attrs.pop("__slots__", None)
616+
612617
return type(self.__class_name, (self.__class__,), class_attrs)
613618

614619

@@ -773,11 +778,16 @@ def _create_proxy(cls, data):
773778
proxy_module_name = data["__module_name__"]
774779
module = AliasClientObjectProxyWrapper.get_module(proxy_module_name)
775780
if not module:
776-
raise Exception("Module not found")
781+
return None
777782
proxy_type_name = data["__class_name__"]
778783
proxy_type = cls.get_proxy_type(proxy_module_name, proxy_type_name)
779784
if not proxy_type:
780-
lookup_type = getattr(module, proxy_type_name)
785+
lookup_type = getattr(module, proxy_type_name, None)
786+
if lookup_type is None:
787+
# Unknown type (e.g. PyCapsule) — create a bare proxy
788+
proxy_type = type(proxy_type_name, (cls,), {})
789+
cls.store_type(proxy_module_name, proxy_type_name, proxy_type)
790+
return proxy_type(data)
781791
proxy_attributes = lookup_type.__dict__
782792

783793
# Skip any private members, and modify any attributes that conflict

python/tk_framework_alias/server/api/__init__.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,17 @@ def get_alias_api_module(alias_bin_path=None):
6363
The Alias Python API supports Python >= 3
6464
"""
6565

66-
# import debugpy
67-
# try:
68-
# debugpy.listen(5678)
69-
# debugpy.wait_for_client()
70-
# except Exception as e:
71-
# print(e)
72-
7366
# Determine the module name based on if running in OpenAlias or OpenModel
7467
# If the executable is Alias, then it is OpenAlias, else OpenModel.
7568
is_open_model = os.path.basename(sys.executable) != "Alias.exe"
7669
module_name = OPEN_MODEL_API_NAME if is_open_model else OPEN_ALIAS_API_NAME
7770
alias_version = get_alias_version()
7871

79-
print(f"init_api alias bin path: {alias_bin_path}")
8072
# First check if Alias ships the Python API module
8173
module_path = None
8274
if alias_bin_path:
8375
alias_api_pyd = f"{module_name}.pyd"
8476
alias_python_module_path = os.path.join(alias_bin_path, alias_api_pyd)
85-
print(f"init_api alias python module path: {alias_python_module_path}")
8677
if os.path.exists(alias_python_module_path):
8778
module_path = alias_python_module_path
8879

python/tk_framework_alias/server/socketio/namespaces/events_namespace.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,14 @@ def on_connect_error(self, data):
109109

110110
self._log_message(None, f"Client connection failed\n{data}")
111111

112-
def on_disconnect(self, sid):
112+
def on_disconnect(self, sid, reason=None):
113113
"""
114114
A disconnect error event triggered.
115115
116116
:param sid: The session id of the client that triggered the event.
117117
:type sid: str
118+
:param reason: The reason for the disconnect (provided by newer socketio versions).
119+
:type reason: str | None
118120
"""
119121

120122
if self.client_sid is None or sid != self.client_sid:

python/tk_framework_alias/server/socketio/namespaces/server_namespace.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,14 @@ def on_connect_error(self, data):
140140

141141
self._log_message(None, f"Client connection failed\n{data}")
142142

143-
def on_disconnect(self, sid):
143+
def on_disconnect(self, sid, reason=None):
144144
"""
145145
A disconnect error event triggered.
146146
147147
:param sid: The session id of the client that triggered the event.
148148
:type sid: str
149+
:param reason: The reason for the disconnect (provided by newer socketio versions).
150+
:type reason: str | None
149151
"""
150152

151153
if self.client_sid is None or sid != self.client_sid:
@@ -308,8 +310,13 @@ def on_load_alias_api(
308310
# Check if the cache is up-to-date. If not, create a new cache. Creating
309311
# a new cache is expensive and should only be done if the api or
310312
# extensions have changed
313+
force_rebuild = os.environ.get("TK_ALIAS_REBUILD_API_CACHE", "0") in (
314+
"1",
315+
"true",
316+
)
311317
if (
312-
not os.path.exists(cache_filepath)
318+
force_rebuild
319+
or not os.path.exists(cache_filepath)
313320
or not os.path.exists(cache_module_filepath)
314321
or not filecmp.cmp(api_info["file_path"], cache_module_filepath)
315322
or extensions_updated

0 commit comments

Comments
 (0)