Skip to content

Commit

Permalink
Merge pull request #24 from tristanlt/jlab4-adapt
Browse files Browse the repository at this point in the history
Support jupyterlab 4 and drop jupyterlab <4 and notebook <7 support
  • Loading branch information
consideRatio authored Jul 9, 2024
2 parents 39af7a2 + 5eec877 commit ff7a3da
Show file tree
Hide file tree
Showing 20 changed files with 395 additions and 1,225 deletions.
62 changes: 40 additions & 22 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
*.bundle.*
lib/
node_modules/
*.log
.eslintcache
.stylelintcache
*.egg-info/
.ipynb_checkpoints
*.tsbuildinfo
jupyter_launcher_shortcuts/labextension
# Version file is handled by hatchling
jupyter_launcher_shortcuts/_version.py

# Created by https://www.gitignore.io/api/python
# Edit at https://www.gitignore.io/?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand All @@ -20,7 +37,8 @@ parts/
sdist/
var/
wheels/
*.egg-info/
pip-wheel-metadata/
share/python-wheels/
.installed.cfg
*.egg
MANIFEST
Expand All @@ -38,10 +56,12 @@ pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage/
coverage.xml
*.cover
.hypothesis/
Expand All @@ -51,15 +71,6 @@ coverage.xml
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

Expand All @@ -69,9 +80,6 @@ docs/_build/
# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

Expand All @@ -81,24 +89,34 @@ celerybeat-schedule
# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# End of https://www.gitignore.io/api/python

# OSX files
.DS_Store

# Yarn cache
.yarn/
yarn.lock
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
34 changes: 34 additions & 0 deletions DEV.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
================================================
Jupyter Launcher Shortcuts development & release
================================================

Pre-build labextension
======================

In order to rebuild Jupyterlab extension

```
micromamba create -n jupyterlab-ext --override-channels --strict-channel-priority -c conda-forge -c nodefaults jupyterlab=4 nodejs=18 git hatch jinja2-time
micromamba activate jupyterlab-ext
```

Prebuild Jupyterlab extension
```
jlpm build
```

Create dist packages
====================

```
hatch build
```


Increase minor version
======================

```
hatch minor version
hatch build
```
21 changes: 8 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
Jupyter Launcher Shortcuts
==========================

Extensions for JupyterLab and classic Jupyter Notebook to add
**user defined** 'launcher' shortcuts. Primarily useful in
JupyterHub / Binder situations.
Extension for JupyterLab (version 4+) and classic Jupyter Notebook (version 7+,
currently broken, see `Issue #25<https://github.com/2i2c-org/jupyter-launcher-shortcuts/issues/25>`_)
to add **user defined** 'launcher' shortcuts. Primarily useful in JupyterHub /
Binder situations.

For JupyterLab, they're added in the launcher interface.

Expand All @@ -17,23 +18,17 @@ For classic Jupyter Notebook, they are added under the 'New' button
Installation
============

The supporting notebook server extension & classic notebook extension
can be installed with ``pip``.
The JupyterLab extension, the classic Jupyter Notebook extension, and a Jupyter
Server extension required behind the scenes can all be installed with ``pip``.

.. code:: bash
pip install jupyter-launcher-shortcuts
The JupyterLab extension needs to be installed separately.

.. code:: bash
jupyter labextension install jupyterlab-launcher-shortcuts
Configuring
===========

The extension can be configured in a ``jupyter_notebook_config.py``
The extension can be configured in a ``jupyter_server_config.py``
file created in any of the directories under ``config`` in the
output of ``jupyter --paths`` command.

Expand All @@ -45,4 +40,4 @@ output of ``jupyter --paths`` command.
'target': '{base_url}shiny/my-shiny-application-directory/',
'icon_path': '/path/to/svg/file'
}
}
}
5 changes: 5 additions & 0 deletions install.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"packageManager": "python",
"packageName": "jupyter-launcher-shortcuts",
"uninstallInstructions": "Use your Python package manager (pip, conda, etc.) to uninstall the package jupyter-launcher-shortcuts"
}
20 changes: 13 additions & 7 deletions jupyter_launcher_shortcuts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from notebook.utils import url_path_join as ujoin
from jupyter_server.utils import url_path_join as ujoin
import jupyter_server
from .api import ShortcutsHandler, IconHandler
from traitlets import Dict
from traitlets.config import Configurable
Expand Down Expand Up @@ -38,27 +39,26 @@ def shortcut_from_dict(name, shortcut_dict):
target=shortcut_dict['target']
)

def load_jupyter_server_extension(nbapp):
def _load_jupyter_server_extension(serverapp):
# Set up handlers picked up via config
base_url = nbapp.web_app.settings['base_url']
base_url = serverapp.web_app.settings['base_url']
shortcuts = [
shortcut_from_dict(k, v)
for k, v in LauncherShortcuts(parent=nbapp).shortcuts.items()
for k, v in LauncherShortcuts(parent=serverapp).shortcuts.items()
]

icons = {}
for ls in shortcuts:
if ls.icon_path:
icons[ls.name] = ls.icon_path

nbapp.web_app.add_handlers('.*', [
serverapp.web_app.add_handlers('.*', [
(ujoin(base_url, 'launcher-shortcuts/shortcuts'), ShortcutsHandler, {'shortcuts': shortcuts}),
(ujoin(base_url, 'launcher-shortcuts/icon/(.*)'), IconHandler, {'icons': icons})
])


# Jupyter Extension points
def _jupyter_server_extension_paths():
def _jupyter_server_extension_points():
return [{
'module': 'jupyter_launcher_shortcuts',
}]
Expand All @@ -70,3 +70,9 @@ def _jupyter_nbextension_paths():
'src': 'static',
"require": "jupyter_launcher_shortcuts/tree"
}]

def _jupyter_labextension_paths():
return [{
"src": "labextension",
"dest": "jupyter_launcher_shortcuts"
}]
8 changes: 4 additions & 4 deletions jupyter_launcher_shortcuts/api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from tornado import web
import mimetypes
from notebook.base.handlers import IPythonHandler
from notebook.utils import url_path_join as ujoin
from jupyter_server.base.handlers import JupyterHandler as handler
from jupyter_server.utils import url_path_join as ujoin

class ShortcutsHandler(IPythonHandler):
class ShortcutsHandler(handler):
def initialize(self, shortcuts):
self.shortcuts = shortcuts

Expand All @@ -24,7 +24,7 @@ async def get(self):


# FIXME: Should be a StaticFileHandler subclass
class IconHandler(IPythonHandler):
class IconHandler(handler):
"""
Serve launcher icons
"""
Expand Down
8 changes: 0 additions & 8 deletions jupyter_launcher_shortcuts/config.py

This file was deleted.

4 changes: 2 additions & 2 deletions jupyter_launcher_shortcuts/etc/serverextension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"NotebookApp": {
"nbserver_extensions": {
"ServerApp": {
"jpserver_extensions": {
"jupyter_launcher_shortcuts": true
}
}
Expand Down
5 changes: 0 additions & 5 deletions jupyterlab-launcher-shortcuts/.gitignore

This file was deleted.

32 changes: 0 additions & 32 deletions jupyterlab-launcher-shortcuts/README.md

This file was deleted.

43 changes: 0 additions & 43 deletions jupyterlab-launcher-shortcuts/package.json

This file was deleted.

18 changes: 0 additions & 18 deletions jupyterlab-launcher-shortcuts/tsconfig.json

This file was deleted.

Loading

0 comments on commit ff7a3da

Please sign in to comment.