Open a notebook via the command line (#98)

* Open a notebook via the command line

* Assign default_url to self.serverapp

* Update to latest jupyter server to open via the cli

* Add redirect handler to open non notebook files
This commit is contained in:
Jeremy Tuloup 2021-02-28 17:20:47 +01:00 committed by GitHub
parent 027f8f515f
commit 78b572a136
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

@ -6,7 +6,7 @@ from jupyter_server.extension.handler import (
ExtensionHandlerMixin,
ExtensionHandlerJinjaMixin,
)
from jupyter_server.utils import url_path_join as ujoin, url_escape
from jupyter_server.utils import url_path_join as ujoin
from jupyterlab.commands import get_app_dir, get_user_settings_dir, get_workspaces_dir
from jupyterlab_server import LabServerApp
from jupyterlab_server.config import get_page_config, recursive_update, LabConfig
@ -105,8 +105,9 @@ class ClassicApp(NBClassicConfigShimMixin, LabServerApp):
app_name = "JupyterLab Classic"
description = "JupyterLab Classic - A JupyterLab Distribution with the Classic Notebook look and feel"
app_version = version
extension_url = "/classic/tree"
extension_url = "/classic"
default_url = "/classic/tree"
file_url_prefix = "/classic/notebooks"
load_other_extensions = True
app_dir = app_dir
app_settings_dir = pjoin(app_dir, "settings")
@ -114,8 +115,16 @@ class ClassicApp(NBClassicConfigShimMixin, LabServerApp):
themes_dir = pjoin(app_dir, "themes")
user_settings_dir = get_user_settings_dir()
workspaces_dir = get_workspaces_dir()
subcommands = {}
def initialize_handlers(self):
self.handlers.append(
(
rf"/{self.file_url_prefix}/((?!.*\.ipynb($|\?)).*)",
web.RedirectHandler,
{"url": "/classic/edit/{0}"}
)
)
self.handlers.append(("/classic/tree(.*)", ClassicTreeHandler))
self.handlers.append(("/classic/notebooks(.*)", ClassicNotebookHandler))
self.handlers.append(("/classic/edit(.*)", ClassicFileHandler))
@ -129,6 +138,13 @@ class ClassicApp(NBClassicConfigShimMixin, LabServerApp):
self.static_paths = [self.static_dir]
self.template_paths = [self.templates_dir]
def initialize_settings(self):
super().initialize_settings()
def initialize(self, argv=None):
"""Subclass because the ExtensionApp.initialize() method does not take arguments"""
super().initialize()
main = launch_new_instance = ClassicApp.launch_instance

View File

@ -84,7 +84,11 @@ setup_args = dict(
cmdclass=cmdclass,
packages=setuptools.find_packages(),
install_requires=[
"jupyterlab~=3.0",
"jupyterlab>=3.0.9,<4",
"jupyterlab_server~=2.3",
"jupyter_server~=1.4",
"nbclassic~=0.2",
"tornado>=6.1.0",
],
zip_safe=False,
include_package_data=True,