Skip to content

Commit b40de3d

Browse files
committed
fix(common) allow rust server_kind env override
1 parent 7abe75e commit b40de3d

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

src/libtmux/common.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@
4040
PaneDict = dict[str, t.Any]
4141

4242
_RUST_BACKEND = os.getenv("LIBTMUX_BACKEND") == "rust"
43-
_RUST_SERVER_CACHE: dict[tuple[str | None, str | None, int | None], t.Any] = {}
44-
_RUST_SERVER_CONFIG: dict[tuple[str | None, str | None, int | None], set[str]] = {}
43+
_RUST_SERVER_CACHE: dict[
44+
tuple[str | None, str | None, int | None, str | None, str | None], t.Any
45+
] = {}
46+
_RUST_SERVER_CONFIG: dict[
47+
tuple[str | None, str | None, int | None, str | None, str | None], set[str]
48+
] = {}
4549

4650

4751
def _resolve_rust_socket_path(socket_path: str | None, socket_name: str | None) -> str:
@@ -161,21 +165,25 @@ def _rust_server(
161165
socket_path: str | None,
162166
colors: int | None,
163167
) -> t.Any:
164-
key = (socket_name, socket_path, colors)
168+
connection_kind = os.getenv("LIBTMUX_RUST_CONNECTION_KIND")
169+
server_kind = os.getenv("LIBTMUX_RUST_SERVER_KIND")
170+
key = (socket_name, socket_path, colors, connection_kind, server_kind)
165171
server = _RUST_SERVER_CACHE.get(key)
166172
if server is None:
167173
from libtmux import _rust as rust_backend
168174

169-
connection_kind = os.getenv("LIBTMUX_RUST_CONNECTION_KIND")
170175
kwargs: dict[str, t.Any] = {}
171176
if connection_kind:
172177
kwargs["connection_kind"] = connection_kind
178+
if server_kind:
179+
kwargs["server_kind"] = server_kind
173180
with libtmux_trace.span(
174181
"rust_server_init",
175182
layer="python",
176183
socket_name=socket_name,
177184
socket_path=socket_path,
178185
connection_kind=connection_kind,
186+
server_kind=server_kind,
179187
):
180188
server = rust_backend.Server(
181189
socket_path=socket_path,
@@ -214,6 +222,7 @@ def _rust_cmd_result(
214222
return stdout, stderr, process.returncode, cmd_list
215223

216224
connection_kind = os.getenv("LIBTMUX_RUST_CONNECTION_KIND")
225+
server_kind = os.getenv("LIBTMUX_RUST_SERVER_KIND")
217226
with libtmux_trace.span(
218227
"rust_cmd_result",
219228
layer="python",
@@ -222,13 +231,14 @@ def _rust_cmd_result(
222231
socket_path=socket_path,
223232
config_file=config_file,
224233
connection_kind=connection_kind,
234+
server_kind=server_kind,
225235
):
226236
if connection_kind in {"bin", "tmux-bin"} and config_file:
227237
cmd_parts = ["-f", config_file, *cmd_parts]
228238
config_file = None
229239

230240
server = _rust_server(socket_name, socket_path, colors)
231-
key = (socket_name, socket_path, colors)
241+
key = (socket_name, socket_path, colors, connection_kind, server_kind)
232242
if config_file:
233243
loaded = _RUST_SERVER_CONFIG.setdefault(key, set())
234244
if config_file not in loaded:

0 commit comments

Comments
 (0)