From 2270b47fdb106dada1da6a9a433a56e3fc0de006 Mon Sep 17 00:00:00 2001 From: fecet Date: Wed, 21 Jun 2023 14:30:26 +0800 Subject: [PATCH 1/5] allow kwargs in write_connection_file --- jupyter_client/connect.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jupyter_client/connect.py b/jupyter_client/connect.py index 01821d86..6320232f 100644 --- a/jupyter_client/connect.py +++ b/jupyter_client/connect.py @@ -40,6 +40,7 @@ def write_connection_file( transport: str = "tcp", signature_scheme: str = "hmac-sha256", kernel_name: str = "", + **kwargs, ) -> Tuple[str, KernelConnectionInfo]: """Generates a JSON config file, including the selection of random ports. @@ -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 @@ -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) -> None: """Write connection info to JSON dict in self.connection_file.""" if self._connection_file_written and os.path.exists(self.connection_file): return @@ -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() From 86613ff36eb962cdc955138d335a2a52aec2c3bf Mon Sep 17 00:00:00 2001 From: fecet Date: Wed, 21 Jun 2023 14:30:59 +0800 Subject: [PATCH 2/5] write jupyter session to connection file if exist --- jupyter_client/provisioning/local_provisioner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyter_client/provisioning/local_provisioner.py b/jupyter_client/provisioning/local_provisioner.py index e9c5066b..8abc1b84 100644 --- a/jupyter_client/provisioning/local_provisioner.py +++ b/jupyter_client/provisioning/local_provisioner.py @@ -187,7 +187,7 @@ async def pre_launch(self, **kwargs: Any) -> Dict[str, Any]: km.control_port = lpc.find_available_port(km.ip) self.ports_cached = True - km.write_connection_file() + km.write_connection_file(jupyter_session=kwargs['env'].get("JPY_SESSION_NAME", "")) self.connection_info = km.get_connection_info() kernel_cmd = km.format_kernel_cmd( From 261af365b4ef123b3141fe4f6b182bb21fbc2c13 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 21 Jun 2023 06:41:16 +0000 Subject: [PATCH 3/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- jupyter_client/connect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jupyter_client/connect.py b/jupyter_client/connect.py index 6320232f..5b18e40e 100644 --- a/jupyter_client/connect.py +++ b/jupyter_client/connect.py @@ -485,7 +485,7 @@ def cleanup_random_ports(self) -> None: self.cleanup_connection_file() - def write_connection_file(self,**kwargs) -> None: + def write_connection_file(self, **kwargs) -> None: """Write connection info to JSON dict in self.connection_file.""" if self._connection_file_written and os.path.exists(self.connection_file): return @@ -502,7 +502,7 @@ def write_connection_file(self,**kwargs) -> None: control_port=self.control_port, signature_scheme=self.session.signature_scheme, kernel_name=self.kernel_name, - **kwargs + **kwargs, ) # write_connection_file also sets default ports: self._record_random_port_names() From 623b2b34c70679ae70f22cb28474fe6c62046ce9 Mon Sep 17 00:00:00 2001 From: fecet Date: Wed, 21 Jun 2023 14:54:45 +0800 Subject: [PATCH 4/5] check env in kwargs --- jupyter_client/provisioning/local_provisioner.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jupyter_client/provisioning/local_provisioner.py b/jupyter_client/provisioning/local_provisioner.py index 8abc1b84..be79eedf 100644 --- a/jupyter_client/provisioning/local_provisioner.py +++ b/jupyter_client/provisioning/local_provisioner.py @@ -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(jupyter_session=kwargs['env'].get("JPY_SESSION_NAME", "")) + 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( From 7184ddce5d0de1085b512d3f910531460d2dbdd2 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 23 Jun 2023 04:59:01 -0500 Subject: [PATCH 5/5] lint --- jupyter_client/connect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jupyter_client/connect.py b/jupyter_client/connect.py index 5b18e40e..92acc68f 100644 --- a/jupyter_client/connect.py +++ b/jupyter_client/connect.py @@ -40,7 +40,7 @@ def write_connection_file( transport: str = "tcp", signature_scheme: str = "hmac-sha256", kernel_name: str = "", - **kwargs, + **kwargs: Any, ) -> Tuple[str, KernelConnectionInfo]: """Generates a JSON config file, including the selection of random ports. @@ -485,7 +485,7 @@ def cleanup_random_ports(self) -> None: self.cleanup_connection_file() - def write_connection_file(self, **kwargs) -> 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