Skip to content

Commit bddb885

Browse files
fecetpre-commit-ci[bot]blink1073
authored
feat: allow kwargs when writting connection_file (#953)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Steven Silvester <[email protected]>
1 parent 57b11c3 commit bddb885

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

jupyter_client/connect.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def write_connection_file(
4040
transport: str = "tcp",
4141
signature_scheme: str = "hmac-sha256",
4242
kernel_name: str = "",
43+
**kwargs: Any,
4344
) -> Tuple[str, KernelConnectionInfo]:
4445
"""Generates a JSON config file, including the selection of random ports.
4546
@@ -140,6 +141,7 @@ def write_connection_file(
140141
cfg["transport"] = transport
141142
cfg["signature_scheme"] = signature_scheme
142143
cfg["kernel_name"] = kernel_name
144+
cfg.update(kwargs)
143145

144146
# Only ever write this file as user read/writeable
145147
# This would otherwise introduce a vulnerability as a file has secrets
@@ -483,7 +485,7 @@ def cleanup_random_ports(self) -> None:
483485

484486
self.cleanup_connection_file()
485487

486-
def write_connection_file(self) -> None:
488+
def write_connection_file(self, **kwargs: Any) -> None:
487489
"""Write connection info to JSON dict in self.connection_file."""
488490
if self._connection_file_written and os.path.exists(self.connection_file):
489491
return
@@ -500,6 +502,7 @@ def write_connection_file(self) -> None:
500502
control_port=self.control_port,
501503
signature_scheme=self.session.signature_scheme,
502504
kernel_name=self.kernel_name,
505+
**kwargs,
503506
)
504507
# write_connection_file also sets default ports:
505508
self._record_random_port_names()

jupyter_client/provisioning/local_provisioner.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,11 @@ async def pre_launch(self, **kwargs: Any) -> Dict[str, Any]:
186186
km.hb_port = lpc.find_available_port(km.ip)
187187
km.control_port = lpc.find_available_port(km.ip)
188188
self.ports_cached = True
189-
190-
km.write_connection_file()
189+
if 'env' in kwargs:
190+
jupyter_session = kwargs['env'].get("JPY_SESSION_NAME", "")
191+
km.write_connection_file(jupyter_session=jupyter_session)
192+
else:
193+
km.write_connection_file()
191194
self.connection_info = km.get_connection_info()
192195

193196
kernel_cmd = km.format_kernel_cmd(

0 commit comments

Comments
 (0)