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

support fix ports from env #985

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jupyter_client/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
from typing import List, Union

__version__ = "8.4.0"
__version__ = "8.4.2"

# Build up version_info tuple for backwards compatibility
pattern = r'(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(?P<rest>.*)'
Expand Down
8 changes: 7 additions & 1 deletion jupyter_client/multikernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .connect import KernelConnectionInfo
from .kernelspec import NATIVE_KERNEL_NAME, KernelSpecManager
from .manager import KernelManager
from .utils import ensure_async, run_sync, utcnow
from .utils import PORTS_ENV_MAP, ensure_async, run_sync, utcnow


class DuplicateKernelError(Exception):
Expand Down Expand Up @@ -201,6 +201,12 @@ def pre_start_kernel(
# subclass we are using. It can be configured as any Configurable,
# including things like its transport and ip.
constructor_kwargs = {}
# ------ set ports from env begin
env = kwargs.get("env", {})
for arg_key, env_key in PORTS_ENV_MAP.items():
if env_key in env:
constructor_kwargs[arg_key] = int(env[env_key])
# ------ set ports from env end
if self.kernel_spec_manager:
constructor_kwargs["kernel_spec_manager"] = self.kernel_spec_manager
km = self.kernel_manager_factory(
Expand Down
5 changes: 5 additions & 0 deletions jupyter_client/provisioning/local_provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ..connect import KernelConnectionInfo, LocalPortCache
from ..launcher import launch_kernel
from ..localinterfaces import is_local_ip, local_ips
from ..utils import PORTS_ENV_MAP
from .provisioner_base import KernelProvisionerBase


Expand Down Expand Up @@ -189,6 +190,10 @@ async def pre_launch(self, **kwargs: Any) -> Dict[str, Any]:
km.control_port = lpc.find_available_port(km.ip)
self.ports_cached = True
if 'env' in kwargs:
env = kwargs.get("env", {})
for arg_key, env_key in PORTS_ENV_MAP.items():
if env_key in env:
setattr(km, arg_key, int(env[env_key]))
jupyter_session = kwargs['env'].get("JPY_SESSION_NAME", "")
km.write_connection_file(jupyter_session=jupyter_session)
else:
Expand Down
8 changes: 8 additions & 0 deletions jupyter_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@

from .session import utcnow # noqa

PORTS_ENV_MAP = {
'hb_port': 'JUPYTER_SERVER_HB_PORT',
'shell_port': 'JUPYTER_SERVER_SHELL_PORT',
'iopub_port': 'JUPYTER_SERVER_IOPUB_PORT',
'stdin_port': 'JUPYTER_SERVER_STDIN_PORT',
'control_port': 'JUPYTER_SERVER_CONTROL_PORT',
}


def _filefind(filename, path_dirs=None):
"""Find a file by looking through a sequence of paths.
Expand Down
Loading