Skip to content

Commit 5bff8a0

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

4 files changed

Lines changed: 259 additions & 35 deletions

File tree

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/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)