|
4 | 4 | # Copyright (c) Jupyter Development Team.
|
5 | 5 | # Distributed under the terms of the Modified BSD License.
|
6 | 6 |
|
7 |
| -from __future__ import absolute_import, print_function |
8 |
| - |
9 |
| -import jupyter_server |
10 | 7 | import binascii
|
11 | 8 | import datetime
|
12 | 9 | import errno
|
|
70 | 67 | __version__,
|
71 | 68 | )
|
72 | 69 |
|
73 |
| -from .base.handlers import MainHandler, RedirectWithParams, Template404 |
74 |
| -from .log import log_request |
75 |
| -from .services.kernels.kernelmanager import MappingKernelManager, AsyncMappingKernelManager |
76 |
| -from .services.config import ConfigManager |
77 |
| -from .services.contents.manager import AsyncContentsManager, ContentsManager |
78 |
| -from .services.contents.filemanager import AsyncFileContentsManager, FileContentsManager |
79 |
| -from .services.contents.largefilemanager import LargeFileManager |
80 |
| -from .services.sessions.sessionmanager import SessionManager |
81 |
| -from .gateway.managers import GatewayKernelManager, GatewayKernelSpecManager, GatewaySessionManager, GatewayClient |
| 70 | +from jupyter_server.base.handlers import MainHandler, RedirectWithParams, Template404 |
| 71 | +from jupyter_server.log import log_request |
| 72 | +from jupyter_server.services.kernels.kernelmanager import MappingKernelManager, AsyncMappingKernelManager |
| 73 | +from jupyter_server.services.config import ConfigManager |
| 74 | +from jupyter_server.services.contents.manager import AsyncContentsManager, ContentsManager |
| 75 | +from jupyter_server.services.contents.filemanager import AsyncFileContentsManager, FileContentsManager |
| 76 | +from jupyter_server.services.contents.largefilemanager import LargeFileManager |
| 77 | +from jupyter_server.services.sessions.sessionmanager import SessionManager |
| 78 | +from jupyter_server.gateway.managers import GatewayKernelManager, GatewayKernelSpecManager, GatewaySessionManager, GatewayClient |
82 | 79 |
|
83 |
| -from .auth.login import LoginHandler |
84 |
| -from .auth.logout import LogoutHandler |
85 |
| -from .base.handlers import FileFindHandler |
| 80 | +from jupyter_server.auth.login import LoginHandler |
| 81 | +from jupyter_server.auth.logout import LogoutHandler |
| 82 | +from jupyter_server.base.handlers import FileFindHandler |
86 | 83 |
|
87 | 84 | from traitlets.config import Config
|
88 | 85 | from traitlets.config.application import catch_config_error, boolean_flag
|
|
102 | 99 | from jupyter_core.paths import jupyter_runtime_dir, jupyter_path
|
103 | 100 | from jupyter_server._sysinfo import get_sys_info
|
104 | 101 |
|
105 |
| -from ._tz import utcnow, utcfromtimestamp |
106 |
| -from .utils import ( |
| 102 | +from jupyter_server._tz import utcnow, utcfromtimestamp |
| 103 | +from jupyter_server.utils import ( |
107 | 104 | url_path_join,
|
108 | 105 | check_pid,
|
109 | 106 | url_escape,
|
|
118 | 115 |
|
119 | 116 | # Tolerate missing terminado package.
|
120 | 117 | try:
|
121 |
| - from .terminal import TerminalManager |
| 118 | + from jupyter_server.terminal import TerminalManager |
122 | 119 | terminado_available = True
|
123 | 120 | except ImportError:
|
124 | 121 | terminado_available = False
|
|
152 | 149 | view=['jupyter_server.view.handlers']
|
153 | 150 | )
|
154 | 151 |
|
| 152 | +DEFAULT_SERVER_PORT = 8888 |
| 153 | + |
155 | 154 | #-----------------------------------------------------------------------------
|
156 | 155 | # Helper functions
|
157 | 156 | #-----------------------------------------------------------------------------
|
@@ -400,7 +399,7 @@ def _config_file_default(self):
|
400 | 399 | return os.path.join(self.config_dir, 'jupyter_server_config.json')
|
401 | 400 |
|
402 | 401 | def start(self):
|
403 |
| - from .auth.security import set_password |
| 402 | + from jupyter_server.auth.security import set_password |
404 | 403 | set_password(config_file=self.config_file)
|
405 | 404 | self.log.info("Wrote hashed password to %s" % self.config_file)
|
406 | 405 |
|
@@ -456,8 +455,8 @@ class JupyterServerStopApp(JupyterApp):
|
456 | 455 | version = __version__
|
457 | 456 | description = "Stop currently running Jupyter server for a given port"
|
458 | 457 |
|
459 |
| - port = Integer(8888, config=True, |
460 |
| - help="Port of the server to be killed. Default 8888") |
| 458 | + port = Integer(DEFAULT_SERVER_PORT, config=True, |
| 459 | + help=f"Port of the server to be killed. Default {DEFAULT_SERVER_PORT}") |
461 | 460 |
|
462 | 461 | def parse_command_line(self, argv=None):
|
463 | 462 | super(JupyterServerStopApp, self).parse_command_line(argv)
|
@@ -723,14 +722,27 @@ def _valdate_ip(self, proposal):
|
723 | 722 | or containerized setups for example).""")
|
724 | 723 | )
|
725 | 724 |
|
726 |
| - port = Integer(8888, config=True, |
727 |
| - help=_i18n("The port the Jupyter server will listen on.") |
| 725 | + port_env = 'JUPYTER_PORT' |
| 726 | + port_default_value = DEFAULT_SERVER_PORT |
| 727 | + port = Integer(port_default_value, config=True, |
| 728 | + help=_i18n("The port the server will listen on (env: JUPYTER_PORT).") |
728 | 729 | )
|
729 | 730 |
|
730 |
| - port_retries = Integer(50, config=True, |
731 |
| - help=_i18n("The number of additional ports to try if the specified port is not available.") |
| 731 | + @default('port') |
| 732 | + def port_default(self): |
| 733 | + return int(os.getenv(self.port_env, self.port_default_value)) |
| 734 | + |
| 735 | + port_retries_env = 'JUPYTER_PORT_RETRIES' |
| 736 | + port_retries_default_value = 50 |
| 737 | + port_retries = Integer(port_retries_default_value, config=True, |
| 738 | + help=_i18n("The number of additional ports to try if the specified port is not " |
| 739 | + "available (env: JUPYTER_PORT_RETRIES).") |
732 | 740 | )
|
733 | 741 |
|
| 742 | + @default('port_retries') |
| 743 | + def port_retries_default(self): |
| 744 | + return int(os.getenv(self.port_retries_env, self.port_retries_default_value)) |
| 745 | + |
734 | 746 | certfile = Unicode(u'', config=True,
|
735 | 747 | help=_i18n("""The full path to an SSL/TLS certificate file.""")
|
736 | 748 | )
|
@@ -1565,7 +1577,7 @@ def init_terminals(self):
|
1565 | 1577 | return
|
1566 | 1578 |
|
1567 | 1579 | try:
|
1568 |
| - from .terminal import initialize |
| 1580 | + from jupyter_server.terminal import initialize |
1569 | 1581 | initialize(self.web_app, self.root_dir, self.connection_url, self.terminado_settings)
|
1570 | 1582 | self.terminals_available = True
|
1571 | 1583 | except ImportError as e:
|
@@ -2084,7 +2096,7 @@ def start_app(self):
|
2084 | 2096 | for line in self.running_server_info(kernel_count=False).split("\n"):
|
2085 | 2097 | info(line)
|
2086 | 2098 | info(_i18n("Use Control-C to stop this server and shut down all kernels (twice to skip confirmation)."))
|
2087 |
| - if 'dev' in jupyter_server.__version__: |
| 2099 | + if 'dev' in __version__: |
2088 | 2100 | info(_i18n("Welcome to Project Jupyter! Explore the various tools available"
|
2089 | 2101 | " and their corresponding documentation. If you are interested"
|
2090 | 2102 | " in contributing to the platform, please visit the community"
|
|
0 commit comments