Skip to content
Snippets Groups Projects
Commit 51430f77 authored by alice grosch's avatar alice grosch
Browse files

Support JupyterLab 2.x

parent b989c2a1
Branches
Tags
No related merge requests found
Showing
with 108 additions and 481 deletions
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/ *.egg-info/
.installed.cfg .ipynb_checkpoints/
*.egg dist/
build/
# PyInstaller *.py[cod]
# Usually these files are written by a python script from a template node_modules/
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask instance folder
instance/
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
docs/source/_static/embed-bundle.js
docs/source/_static/embed-bundle.js.map
# PyBuilder
target/
# IPython Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# dotenv
.env
# virtualenv
venv/
ENV/
# Spyder project settings
.spyderproject
# Rope project settings
.ropeproject
# ========================= # Compiled javascript
# Operating System Files dicom_upload/static/
# =========================
# OS X # OS X
# =========================
.DS_Store .DS_Store
.AppleDouble
.LSOverride
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# Windows
# =========================
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
# NPM
# ----
**/node_modules/
dicom_upload/nbextension/static/index.*
dicom_upload/labextension/*.tgz
# Coverage data
# -------------
**/coverage/
# Packed lab extensions
dicom_upload/labextension
# vscode # VS Code
.vscode/ *.vscode
# file GENERATED by distutils, do NOT edit
LICENSE.txt
README.md
dicom_upload.json
package.json
pytest.ini
setup.cfg
setup.py
setupbase.py
tsconfig.json
webpack.config.js
dicom_upload/__init__.py
dicom_upload/_frontend.py
dicom_upload/_version.py
dicom_upload/widget_upload.py
dicom_upload/labextension/dicom-upload-0.1.2.tgz
dicom_upload/nbextension/__init__.py
dicom_upload/nbextension/static/extension.js
dicom_upload/nbextension/static/index.js
dicom_upload/nbextension/static/index.js.map
dicom_upload/tests/__init__.py
dicom_upload/tests/conftest.py
dicom_upload/tests/test_example.py
dicom_upload/tests/test_nbextension_path.py
docs/Makefile
docs/environment.yml
docs/make.bat
docs/source/conf.py
docs/source/develop-install.rst
docs/source/index.rst
docs/source/installing.rst
docs/source/introduction.rst
docs/source/_static/embed-bundle.js
docs/source/_static/embed-bundle.js.map
docs/source/_static/helper.js
docs/source/examples/index.rst
docs/source/examples/introduction.nblink
examples/introduction.ipynb
examples/.ipynb_checkpoints/introduction-checkpoint.ipynb
src/extension.ts
src/index.ts
src/plugin.ts
src/version.ts
src/widget.ts
tests/karma.conf.js
tests/tsconfig.json
tests/src/index.spec.ts
tests/src/utils.spec.ts
include LICENSE.txt recursive-include dicom_upload/static *.*
include README.md include dicom-upload.json
include setupbase.py
include pytest.ini
include .coverage.rc
include tsconfig.json
include package.json
include webpack.config.js
include dicom_upload/labextension/*.tgz
# Documentation
graft docs
exclude docs/\#*
prune docs/build
prune docs/gh-pages
prune docs/dist
# Examples
graft examples
# Tests
graft tests
prune tests/build
# Javascript files
graft dicom_upload/nbextension
graft src
prune **/node_modules
prune coverage
prune lib
# Patterns to exclude from any directory
global-exclude *~
global-exclude *.pyc
global-exclude *.pyo
global-exclude .git
global-exclude .ipynb_checkpoints
# dicom-upload dicom-upload
===============================
[![Build Status](https://travis-ci.org/jsc/dicom-upload.svg?branch=master)](https://travis-ci.org/jsc/dicom_upload) Upload DICOM files with patient und study data removed from header
[![codecov](https://codecov.io/gh/jsc/dicom-upload/branch/master/graph/badge.svg)](https://codecov.io/gh/jsc/dicom-upload)
Installation
------------
FileUpload Widget using the Jupyter Notebook Server RestAPI. To install use pip:
Uploads DICOM files with anonymized headers, i.d. the 0004 and
0010 tags are removed on JS side before the upload.
Can handle large files by uploading files in chunks. $ pip install dicom_upload
$ jupyter nbextension enable --py --sys-prefix dicom_upload
## Installation To install for jupyterlab
You can install using `pip`: $ jupyter labextension install dicom_upload
```bash For a development installation (requires npm),
pip install dicom_upload
```
or from this GitLab directly
```bash $ git clone https://github.com/jsc/dicom-upload.git
pip install git+https://gitlab.version.fz-juelich.de/jupyter4jsc/j4j_extras/dicom-upload.git $ cd dicom-upload
``` $ pip install -e .
$ jupyter nbextension install --py --symlink --sys-prefix dicom_upload
$ jupyter nbextension enable --py --sys-prefix dicom_upload
$ jupyter labextension install js
Or if you use jupyterlab: When actively developing your extension, build Jupyter Lab with the command:
```bash $ jupyter lab --watch
pip install dicom_upload
jupyter labextension install @jupyter-widgets/jupyterlab-manager This take a minute or so to get started, but then allows you to hot-reload your javascript extension.
``` To see a change, save your javascript, watch the terminal for an update.
Note on first `jupyter lab --watch`, you may need to touch a file to get Jupyter Lab to open.
If you are using Jupyter Notebook 5.2 or earlier, you may also need to enable
the nbextension:
```bash
jupyter nbextension enable --py [--sys-prefix|--user|--system] dicom_upload
```
- To release a new version of dicom_upload on PyPI:
Update _version.py (set release version, remove 'dev')
git add the _version.py file and git commit
`python setup.py sdist upload`
`python setup.py bdist_wheel upload`
`git tag -a X.X.X -m 'comment'`
Update _version.py (add 'dev' and increment minor)
git add and git commit
git push
git push --tags
- To release a new version of dicom-upload on NPM:
Update `js/package.json` with new npm package version
```
# clean out the `dist` and `node_modules` directories
git clean -fdx
npm install
npm publish
```
\ No newline at end of file
{ {
"load_extensions": { "load_extensions": {
"dicom_upload/extension": true "dicom-upload/extension": true
} }
} }
#!/usr/bin/env python from ._version import version_info, __version__
# coding: utf-8
# Copyright (c) Alice Grosch. from .widget_upload import *
# Distributed under the terms of the Modified BSD License.
from .widget_upload import Uploader
from ._version import __version__, version_info
from .nbextension import _jupyter_nbextension_paths def _jupyter_nbextension_paths():
"""Called by Jupyter Notebook Server to detect if it is a valid nbextension and
to install the widget
Returns
=======
section: The section of the Jupyter Notebook Server to change.
Must be 'notebook' for widget extensions
src: Source directory name to copy files from. Webpack outputs generated files
into this directory and Jupyter Notebook copies from this directory during
widget installation
dest: Destination directory name to install widget files to. Jupyter Notebook copies
from `src` directory into <jupyter path>/nbextensions/<dest> directory
during widget installation
require: Path to importable AMD Javascript module inside the
<jupyter path>/nbextensions/<dest> directory
"""
return [{
'section': 'notebook',
'src': 'static',
'dest': 'dicom-upload',
'require': 'dicom-upload/extension'
}]
#!/usr/bin/env python
# coding: utf-8
# Copyright (c) Alice Grosch.
# Distributed under the terms of the Modified BSD License.
""" """
Information about the frontend package of the widgets. Information about the frontend package of the widgets.
""" """
module_name = "dicom-upload" module_name = "dicom-upload"
module_version = "^0.1.0" module_version = "0.1.3"
#!/usr/bin/env python # Module version
# coding: utf-8 version_info = (0, 1, 3, 'final', 0)
# Copyright (c) Alice Grosch. # Module version stage suffix map
# Distributed under the terms of the Modified BSD License. _specifier_ = {'alpha': 'a', 'beta': 'b', 'candidate': 'rc', 'final': ''}
version_info = (0, 1, 3, 'dev') # Module version accessible using dicom_upload.__version__
__version__ = ".".join(map(str, version_info)) __version__ = '%s.%s.%s%s' % (version_info[0], version_info[1], version_info[2],
'' if version_info[3] == 'final' else _specifier_[version_info[3]]+str(version_info[4]))
#!/usr/bin/env python
# coding: utf-8
# Copyright (c) Alice Grosch
# Distributed under the terms of the Modified BSD License.
def _jupyter_nbextension_paths():
return [{
'section': 'notebook',
'src': 'nbextension/static',
'dest': 'dicom_upload',
'require': 'dicom_upload/extension'
}]
// Entry point for the notebook bundle containing custom model definitions.
//
define(function() {
"use strict";
window['requirejs'].config({
map: {
'*': {
'dicom-upload': 'nbextensions/dicom_upload/index',
},
}
});
// Export the required load_ipython_extension function
return {
load_ipython_extension : function() {}
};
});
#!/usr/bin/env python
# coding: utf-8
# Copyright (c) Alice Grosch.
# Distributed under the terms of the Modified BSD License.
import pytest
from ipykernel.comm import Comm
from ipywidgets import Widget
class MockComm(Comm):
"""A mock Comm object.
Can be used to inspect calls to Comm's open/send/close methods.
"""
comm_id = 'a-b-c-d'
kernel = 'Truthy'
def __init__(self, *args, **kwargs):
self.log_open = []
self.log_send = []
self.log_close = []
super(MockComm, self).__init__(*args, **kwargs)
def open(self, *args, **kwargs):
self.log_open.append((args, kwargs))
def send(self, *args, **kwargs):
self.log_send.append((args, kwargs))
def close(self, *args, **kwargs):
self.log_close.append((args, kwargs))
_widget_attrs = {}
undefined = object()
@pytest.fixture
def mock_comm():
_widget_attrs['_comm_default'] = getattr(Widget, '_comm_default', undefined)
Widget._comm_default = lambda self: MockComm()
_widget_attrs['_ipython_display_'] = Widget._ipython_display_
def raise_not_implemented(*args, **kwargs):
raise NotImplementedError()
Widget._ipython_display_ = raise_not_implemented
yield MockComm()
for attr, value in _widget_attrs.items():
if value is undefined:
delattr(Widget, attr)
else:
setattr(Widget, attr, value)
#!/usr/bin/env python
# coding: utf-8
# Copyright (c) Alice Grosch.
# Distributed under the terms of the Modified BSD License.
import pytest
from ..example import ExampleWidget
def test_example_creation_blank():
w = ExampleWidget()
assert w.value == 'Hello World'
#!/usr/bin/env python
# coding: utf-8
# Copyright (c) Alice Grosch.
# Distributed under the terms of the Modified BSD License.
def test_nbextension_path():
# Check that magic function can be imported from package root:
from dicom_upload import _jupyter_nbextension_paths
# Ensure that it can be called without incident:
path = _jupyter_nbextension_paths()
# Some sanity checks:
assert len(path) == 1
assert isinstance(path[0], dict)
...@@ -25,6 +25,7 @@ from traitlets import ( ...@@ -25,6 +25,7 @@ from traitlets import (
from ._frontend import module_name, module_version from ._frontend import module_name, module_version
@register
class Uploader(DescriptionWidget, ValueWidget): class Uploader(DescriptionWidget, ValueWidget):
"""Upload Widget. """Upload Widget.
...@@ -45,10 +46,13 @@ class Uploader(DescriptionWidget, ValueWidget): ...@@ -45,10 +46,13 @@ class Uploader(DescriptionWidget, ValueWidget):
_view_module = Unicode(module_name).tag(sync=True) _view_module = Unicode(module_name).tag(sync=True)
_view_module_version = Unicode(module_version).tag(sync=True) _view_module_version = Unicode(module_version).tag(sync=True)
accept = Unicode(help='File types to accept, empty string for all').tag(sync=True) accept = Unicode(
multiple = Bool(help='If True, allow for multiple files upload').tag(sync=True) help='File types to accept, empty string for all').tag(sync=True)
multiple = Bool(
help='If True, allow for multiple files upload').tag(sync=True)
disabled = Bool(help='Enable or disable button').tag(sync=True) disabled = Bool(help='Enable or disable button').tag(sync=True)
icon = Unicode('upload', help="Font-awesome icon name, without the 'fa-' prefix.").tag(sync=True) icon = Unicode(
'upload', help="Font-awesome icon name, without the 'fa-' prefix.").tag(sync=True)
button_style = CaselessStrEnum( button_style = CaselessStrEnum(
values=['primary', 'success', 'info', 'warning', 'danger', ''], default_value='', values=['primary', 'success', 'info', 'warning', 'danger', ''], default_value='',
help="""Use a predefined styling for the button.""").tag(sync=True) help="""Use a predefined styling for the button.""").tag(sync=True)
...@@ -69,7 +73,6 @@ class Uploader(DescriptionWidget, ValueWidget): ...@@ -69,7 +73,6 @@ class Uploader(DescriptionWidget, ValueWidget):
hash = Unicode().tag(sync=True) hash = Unicode().tag(sync=True)
_upload = Bool(False).tag(sync=True) _upload = Bool(False).tag(sync=True)
def __init__(self, upload_url='http://localhost:8888/api/contents/', token='', *args, **kwargs): def __init__(self, upload_url='http://localhost:8888/api/contents/', token='', *args, **kwargs):
"""Args: """Args:
upload_url (str): Jupyter notebook URL appended by api/contents/<path>/. Directories on <path> must already exist. upload_url (str): Jupyter notebook URL appended by api/contents/<path>/. Directories on <path> must already exist.
......
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = dicom_upload
SOURCEDIR = source
BUILDDIR = build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
name: dicom_upload_docs
channels:
- conda-forge
dependencies:
- python=3.5
- nodejs
- numpy
- sphinx
- nbsphinx
- jupyter_sphinx
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build
set SPHINXPROJ=dicom_upload
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
:end
popd
var cache_require = window.require;
window.addEventListener('load', function() {
window.require = cache_require;
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment