Skip to content

Commit

Permalink
[Utils] Remove legacy notebook server and bump jupyter server
Browse files Browse the repository at this point in the history
  • Loading branch information
alonmr committed Nov 5, 2024
1 parent 9bdf902 commit e88a9ea
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 34 deletions.
3 changes: 1 addition & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ name = "pypi"

[packages]
nbconvert = ">=6.4.5"
# notebook.notebookapp has been deprecated since 7.0.0
notebook = ">=6.4, <7.0.0"
pyyaml = ">=3.13, <7"
requests = ">=2.31.0"
boto3 = ">=1.28.0"
importlib-metadata = "<8.0.0"
ipython = ">=7.27.0"
jupyter_server = ">=2.0.0"

[dev-packages]
flake8 = "*"
Expand Down
31 changes: 5 additions & 26 deletions nuclio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import shlex
from argparse import ArgumentParser
from sys import stdout
from itertools import chain

import ipykernel
from urllib.parse import urlencode, urljoin
Expand Down Expand Up @@ -178,22 +177,11 @@ def str2nametag(input):
def notebook_file_name(ikernel):
"""Return the full path of the jupyter notebook."""

from jupyter_server.serverapp import list_running_servers

# the following code won't work when the notebook is being executed
# through running `jupyter nbconvert --execute` this env var enables to
# overcome it
from notebook.notebookapp import list_running_servers \
as nb_list_running_servers
# installing jupyter-server is optional (only when doing pip install
# nuclio-jupyter[jupyter-server]) therefore don't fail on import error
jupyter_server_supported = False
try:
from jupyter_server.serverapp import list_running_servers \
as jp_list_running_servers
except ImportError:
pass
else:
jupyter_server_supported = True

file_name = environ.get('JUPYTER_NOTEBOOK_FILE_NAME')
if file_name is not None:
return file_name
Expand All @@ -205,25 +193,16 @@ def notebook_file_name(ikernel):
kernel_id = re.search('kernel-(.*).json',
ipykernel.connect.get_connection_file()).group(1)

# list both notebook servers (nbserver-*.json) and the newer
# jupyter servers (jpserver-*.json), remove nb_list_running_servers()
# when fully moving to jupyter servers.
servers = nb_list_running_servers()
if jupyter_server_supported:
servers = chain(nb_list_running_servers(), jp_list_running_servers())
# list jupyter servers (jpserver-*.json)
servers = list_running_servers()
for srv in servers:
query = {'token': srv.get('token', '')}
url = urljoin(srv['url'], 'api/sessions') + '?' + urlencode(query)
for session in json.load(urlopen(url)):
if session['kernel']['id'] == kernel_id:
relative_path = session['notebook']['path']

# remove srv.get('notebook_dir') when fully moving to
# jupyter servers.
return path.join(
srv.get('notebook_dir') or srv.get('root_dir'),
relative_path
)
return path.join(srv.get('root_dir'), relative_path)

# vscode jupyter plugin communicates directly with ipykernel and doesn't execute a server
return ikernel.user_ns.get("__vsc_ipynb_file__")
6 changes: 0 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@ def load_deps(section):
],
setup_requires=['pytest-runner'],
tests_require=tests_require,
extras_require={
# jupyter-server is the new "infrastructure" of jupyter, in the Iguazio Jupyter we're still using an old version
# which uses the notebook-server. installing jupyter-server there is causing troubles (unwanted upgrade of
# tornado package, so we're installing jupyter-server only if explicitly requested by adding an extra
"jupyter-server": ["jupyter-server~=1.0"],
},
entry_points={
'nbconvert.exporters': [
'nuclio=nuclio.export:NuclioExporter',
Expand Down

0 comments on commit e88a9ea

Please sign in to comment.