Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow kwargs when writting connection_file #953

Merged
merged 5 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion jupyter_client/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def write_connection_file(
transport: str = "tcp",
signature_scheme: str = "hmac-sha256",
kernel_name: str = "",
**kwargs: Any,
) -> Tuple[str, KernelConnectionInfo]:
"""Generates a JSON config file, including the selection of random ports.

Expand Down Expand Up @@ -140,6 +141,7 @@ def write_connection_file(
cfg["transport"] = transport
cfg["signature_scheme"] = signature_scheme
cfg["kernel_name"] = kernel_name
cfg.update(kwargs)

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

self.cleanup_connection_file()

def write_connection_file(self) -> None:
def write_connection_file(self, **kwargs: Any) -> None:
"""Write connection info to JSON dict in self.connection_file."""
if self._connection_file_written and os.path.exists(self.connection_file):
return
Expand All @@ -500,6 +502,7 @@ def write_connection_file(self) -> None:
control_port=self.control_port,
signature_scheme=self.session.signature_scheme,
kernel_name=self.kernel_name,
**kwargs,
)
# write_connection_file also sets default ports:
self._record_random_port_names()
Expand Down
7 changes: 5 additions & 2 deletions jupyter_client/provisioning/local_provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,11 @@ async def pre_launch(self, **kwargs: Any) -> Dict[str, Any]:
km.hb_port = lpc.find_available_port(km.ip)
km.control_port = lpc.find_available_port(km.ip)
self.ports_cached = True

km.write_connection_file()
if 'env' in kwargs:
jupyter_session = kwargs['env'].get("JPY_SESSION_NAME", "")
km.write_connection_file(jupyter_session=jupyter_session)
else:
km.write_connection_file()
self.connection_info = km.get_connection_info()

kernel_cmd = km.format_kernel_cmd(
Expand Down