From a2b6920817a795fa2ae98426202091f470c8e5fc Mon Sep 17 00:00:00 2001 From: Darshan808 Date: Wed, 12 Feb 2025 16:59:18 +0545 Subject: [PATCH 1/2] fix-failing-CI --- examples/simple/pyproject.toml | 2 +- jupyter_server/serverapp.py | 116 ++++++++++++++++----------------- 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/examples/simple/pyproject.toml b/examples/simple/pyproject.toml index 38ae8e71a7..99fc390a4c 100644 --- a/examples/simple/pyproject.toml +++ b/examples/simple/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" name = "jupyter-server-example" description = "Jupyter Server Example" readme = "README.md" -license = "" +license = "BSD-3-Clause" requires-python = ">=3.8" dependencies = [ "jinja2", diff --git a/jupyter_server/serverapp.py b/jupyter_server/serverapp.py index 8e19658fc5..af76aaa53f 100644 --- a/jupyter_server/serverapp.py +++ b/jupyter_server/serverapp.py @@ -3061,6 +3061,24 @@ def start_app(self) -> None: ) self.exit(1) + info = self.log.info + for line in self.running_server_info(kernel_count=False).split("\n"): + info(line) + info( + _i18n( + "Use Control-C to stop this server and shut down all kernels (twice to skip confirmation)." + ) + ) + if "dev" in __version__: + info( + _i18n( + "Welcome to Project Jupyter! Explore the various tools available" + " and their corresponding documentation. If you are interested" + " in contributing to the platform, please visit the community" + " resources section at https://jupyter.org/community.html." + ) + ) + self.write_server_info_file() if not self.no_browser_open_file: @@ -3070,6 +3088,46 @@ def start_app(self) -> None: if self.open_browser and not self.sock: self.launch_browser() + if self.identity_provider.token and self.identity_provider.token_generated: + # log full URL with generated token, so there's a copy/pasteable link + # with auth info. + if self.sock: + self.log.critical( + "\n".join( + [ + "\n", + "Jupyter Server is listening on %s" % self.display_url, + "", + ( + "UNIX sockets are not browser-connectable, but you can tunnel to " + f"the instance via e.g.`ssh -L 8888:{self.sock} -N user@this_host` and then " + f"open e.g. {self.connection_url} in a browser." + ), + ] + ) + ) + else: + if self.no_browser_open_file: + message = [ + "\n", + _i18n("To access the server, copy and paste one of these URLs:"), + " %s" % self.display_url, + ] + else: + message = [ + "\n", + _i18n( + "To access the server, open this file in a browser:", + ), + " %s" % urljoin("file:", pathname2url(self.browser_open_file)), + _i18n( + "Or copy and paste one of these URLs:", + ), + " %s" % self.display_url, + ] + + self.log.critical("\nDP_DAI2\n"+"\n".join(message)) + async def _cleanup(self) -> None: """General cleanup of files, extensions and kernels created by this instance ServerApp. @@ -3127,64 +3185,6 @@ async def _post_start(self): except Exception as err: self.log.error(err) - info = self.log.info - for line in self.running_server_info(kernel_count=False).split("\n"): - info(line) - info( - _i18n( - "Use Control-C to stop this server and shut down all kernels (twice to skip confirmation)." - ) - ) - if "dev" in __version__: - info( - _i18n( - "Welcome to Project Jupyter! Explore the various tools available" - " and their corresponding documentation. If you are interested" - " in contributing to the platform, please visit the community" - " resources section at https://jupyter.org/community.html." - ) - ) - - if self.identity_provider.token and self.identity_provider.token_generated: - # log full URL with generated token, so there's a copy/pasteable link - # with auth info. - if self.sock: - self.log.critical( - "\n".join( - [ - "\n", - "Jupyter Server is listening on %s" % self.display_url, - "", - ( - "UNIX sockets are not browser-connectable, but you can tunnel to " - f"the instance via e.g.`ssh -L 8888:{self.sock} -N user@this_host` and then " - f"open e.g. {self.connection_url} in a browser." - ), - ] - ) - ) - else: - if self.no_browser_open_file: - message = [ - "\n", - _i18n("To access the server, copy and paste one of these URLs:"), - " %s" % self.display_url, - ] - else: - message = [ - "\n", - _i18n( - "To access the server, open this file in a browser:", - ), - " %s" % urljoin("file:", pathname2url(self.browser_open_file)), - _i18n( - "Or copy and paste one of these URLs:", - ), - " %s" % self.display_url, - ] - - self.log.critical("\n".join(message)) - def start(self) -> None: """Start the Jupyter server app, after initialization From e966a3cfe778962b428009c056df8f16d1a28c76 Mon Sep 17 00:00:00 2001 From: Darshan808 Date: Thu, 13 Feb 2025 15:39:39 +0545 Subject: [PATCH 2/2] docs: add note that startup banner displays before async tasks begin --- docs/source/developers/extensions.rst | 9 +++++++++ jupyter_server/serverapp.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/source/developers/extensions.rst b/docs/source/developers/extensions.rst index 7d1f24e431..e88acfb0f6 100644 --- a/docs/source/developers/extensions.rst +++ b/docs/source/developers/extensions.rst @@ -87,6 +87,10 @@ Here is basic example: """ await asyncio.sleep(.1) +.. note:: The server startup banner (displaying server info and access URLs) is printed before starting asynchronous tasks, so those tasks might still be running even after the banner appears. + +.. WARNING: This note is also present in the "Starting asynchronous tasks from an ExtensionApp" section. + If you update it here, please update it there as well. Making an extension discoverable -------------------------------- @@ -386,6 +390,11 @@ Here is a basic (pseudo) code example: async def stop_extension(self): self.my_background_task.cancel() +.. note:: The server startup banner (displaying server info and access URLs) is printed before starting asynchronous tasks, so those tasks might still be running even after the banner appears. + +.. WARNING: This note is also present in the "Starting asynchronous tasks from an extension" section. + If you update it here, please update it there as well. + Distributing a server extension =============================== diff --git a/jupyter_server/serverapp.py b/jupyter_server/serverapp.py index af76aaa53f..cdf92212c3 100644 --- a/jupyter_server/serverapp.py +++ b/jupyter_server/serverapp.py @@ -3126,7 +3126,7 @@ def start_app(self) -> None: " %s" % self.display_url, ] - self.log.critical("\nDP_DAI2\n"+"\n".join(message)) + self.log.critical("\n".join(message)) async def _cleanup(self) -> None: """General cleanup of files, extensions and kernels created