Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Separate pip install from extension activation #7

Merged
merged 5 commits into from
Jan 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ script:
- mkdir -p /home/travis/.jupyter/nbconfig
- jupyter notebook --generate-config
- pip install jupyter_dashboards
- jupyter dashboards install --user --symlink
- jupyter dashboards activate
- python setup.py sdist
- pip install --no-use-wheel --no-deps dist/*.tar.gz
- python -B -m unittest discover -s test
Expand Down
33 changes: 21 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ CMS_PACKAGE?=jupyter_cms
DASHBOARDS_PACKAGE?=jupyter_dashboards

# Using pyspark notebook to get both a python2 and python3 env
REPO:=jupyter/pyspark-notebook:a388c4a66fd4
DEV_REPO:=jupyter/pyspark-notebook-db-dev:a388c4a66fd4
REPO:=jupyter/pyspark-notebook:2988869079e6
DEV_REPO:=jupyter/pyspark-notebook-db-dev:2988869079e6
PYTHON2_SETUP:=source activate python2

define EXT_DEV_SETUP
pushd /src && \
pip install --no-deps -e . && \
jupyter dashboards_bundlers activate && \
popd
endef

help:
@echo 'Host commands:'
@echo ' build - build dev image'
Expand All @@ -26,9 +33,13 @@ help:

build:
@-docker rm -f dev-build
@docker run -it --user jovyan --name dev-build \
$(REPO) bash -c 'pip install --no-binary :all: $(CMS_PACKAGE) $(DASHBOARDS_PACKAGE); \
$(PYTHON2_SETUP); \
@docker run -it --name dev-build \
$(REPO) bash -c 'pip install --no-binary :all: $(CMS_PACKAGE) $(DASHBOARDS_PACKAGE) && \
jupyter cms install --user --symlink --overwrite && \
jupyter dashboards install --user --symlink --overwrite && \
jupyter cms activate && \
jupyter dashboards activate && \
$(PYTHON2_SETUP) && \
pip install --no-binary :all: $(CMS_PACKAGE) $(DASHBOARDS_PACKAGE)'
@docker commit dev-build $(DEV_REPO)
@-docker rm -f dev-build
Expand All @@ -41,22 +52,20 @@ clean:

dev: dev-$(PYTHON)

dev-python2: SETUP_CMD?=$(PYTHON2_SETUP); pushd /src && pip install --no-deps -e . && popd
dev-python2: LANG_SETUP_CMD?=$(PYTHON2_SETUP) && python --version
dev-python2: _dev

dev-python3: SETUP_CMD?=pushd /src && pip install --no-deps -vvv -e . && popd
dev-python3: LANG_SETUP_CMD?=python --version
dev-python3: _dev

_dev: NB_HOME?=/root
_dev: CMD?=sh -c "python --version; jupyter notebook --no-browser --port 8888 --ip=0.0.0.0"
_dev: CMD?=start-notebook.sh
_dev: AUTORELOAD?=no
_dev:
@docker run -it --rm \
--user jovyan \
-p 9500:8888 \
-e AUTORELOAD=$(AUTORELOAD) \
-v `pwd`:/src \
$(DEV_REPO) bash -c '$(SETUP_CMD); $(CMD)'
$(DEV_REPO) bash -c '$(LANG_SETUP_CMD) && $(EXT_DEV_SETUP) && $(CMD)'

install: CMD?=exit
install:
Expand All @@ -65,9 +74,9 @@ install:
-v `pwd`:/src \
$(REPO) bash -c 'cd /src/dist && \
pip install --no-binary :all: $$(ls -1 *.tar.gz | tail -n 1) && \
jupyter dashboards_bundlers activate && \
$(CMD)'

sdist: REPO?=jupyter/pyspark-notebook:$(TAG)
sdist:
@docker run -it --rm \
-v `pwd`:/src \
Expand Down
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,25 @@ Collection of reference implementation bundlers that convert, package, and deplo
## Prerequisites

* Jupyter Notebook 4.0.x running on Python 3.x or Python 2.7.x
* `jupyter_cms>=0.3.0`
* `jupyter_dashboards>=0.3.0`
* `jupyter_cms>=0.4.0`
* `jupyter_dashboards>=0.4.0`
* Edge, Chrome, Firefox, or Safari

## Install It

`pip install jupyter_dashboards_bundlers`
```bash
# install the python package
pip install jupyter_dashboards_bundlers
# enable the extension in your ~/.jupyter config
jupyter dashboards_bundlers activate
```

## Uninstall It

```bash
jupyter dashboards_bundlers deactivate
pip uninstall dashboards_bundlers
```

## Use It

Expand Down
132 changes: 132 additions & 0 deletions dashboards_bundlers/extensionapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import errno
import os.path
import sys

from notebook.services.config import ConfigManager
from notebook.nbextensions import (EnableNBExtensionApp,
DisableNBExtensionApp, flags, aliases)
from traitlets.config.application import catch_config_error
from traitlets.config.application import Application

# Make copies to reuse flags and aliases
INSTALL_FLAGS = {}
INSTALL_FLAGS.update(flags)

INSTALL_ALIASES = {}
INSTALL_ALIASES.update(aliases)
del INSTALL_ALIASES['destination']

def makedirs(path):
'''
mkdir -p and ignore existence errors compatible with Py2/3.
'''
try:
os.makedirs(path)
except OSError as e:
if e.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise

class ExtensionActivateApp(EnableNBExtensionApp):
'''Subclass that activates this particular extension.'''
name = u'jupyter-dashboards-bundlers-extension-activate'
description = u'Activate the jupyter_dashboards_bundlers extension'

flags = {}
aliases = {}

examples = """
jupyter dashboards_bundlers activate
"""

def _classes_default(self):
return [ExtensionActivateApp, EnableNBExtensionApp]

def start(self):
self.log.info("Activating jupyter_dashboards_bundlers JS notebook extensions")
cm = ConfigManager(parent=self, config=self.config)
cm.update('notebook', {
'jupyter_cms_bundlers': {
'dashboards_local_deploy': {
'label': 'Local Dashboard',
'module_name': 'dashboards_bundlers.local_deploy',
'group': 'deploy'
},
'dashboards_php_download': {
'label': 'PHP Dashboard bundle (.zip)',
'module_name': 'dashboards_bundlers.php_download',
'group': 'download'
}
}
})
self.log.info("Done.")

class ExtensionDeactivateApp(DisableNBExtensionApp):
'''Subclass that deactivates this particular extension.'''
name = u'jupyter-dashboards-bundlers-extension-deactivate'
description = u'Deactivate the jupyter_dashboards_bundlers extension'

flags = {}
aliases = {}

examples = """
jupyter dashboards_bundlers deactivate
"""

def _classes_default(self):
return [ExtensionDeactivateApp, DisableNBExtensionApp]

def start(self):
self.log.info("Deactivating jupyter_dashboards_bundlers JS notebook extensions")
cm = ConfigManager(parent=self, config=self.config)
cm.update('notebook', {
'jupyter_cms_bundlers': {
'dashboards_local_deploy' : None,
'dashboards_php_download' : None,
}
})
self.log.info("Done.")

class ExtensionApp(Application):
'''CLI for extension management.'''
name = u'jupyter_dashboards_bundlers extension'
description = u'Utilities for managing the jupyter_dashboards_bundlers extension'
examples = ""

subcommands = dict(
activate=(
ExtensionActivateApp,
"Activate the extension."
),
deactivate=(
ExtensionDeactivateApp,
"Deactivate the extension."
)
)

def _classes_default(self):
classes = super(ExtensionApp, self)._classes_default()

# include all the apps that have configurable options
for appname, (app, help) in self.subcommands.items():
if len(app.class_traits(config=True)) > 0:
classes.append(app)

@catch_config_error
def initialize(self, argv=None):
super(ExtensionApp, self).initialize(argv)

def start(self):
# check: is there a subapp given?
if self.subapp is None:
self.print_help()
sys.exit(1)

# This starts subapps
super(ExtensionApp, self).start()

def main():
ExtensionApp.launch_instance()
2 changes: 1 addition & 1 deletion dashboards_bundlers/local_deploy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def bundle_web_static(output_path):
]

# Paths for dashboard extension source and destination in local app folder
src_components = pjoin(jupyter_data_dir(), 'nbextensions/urth_dash_js/notebook')
src_components = pjoin(jupyter_data_dir(), 'nbextensions/jupyter_dashboards/notebook')
dest_components = pjoin(output_path, 'static')

# Copy individual files, making directories as we go
Expand Down
7 changes: 7 additions & 0 deletions scripts/jupyter-dashboards_bundlers
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import dashboards_bundlers.extensionapp

if __name__ == '__main__':
dashboards_bundlers.extensionapp.main()
63 changes: 22 additions & 41 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
# Distributed under the terms of the Modified BSD License.

import os
import sys
from setuptools import setup
from setuptools.command.install import install
from setuptools.command.develop import develop

from notebook.services.config import ConfigManager

# Get location of this file at runtime
HERE = os.path.abspath(os.path.dirname(__file__))
Expand All @@ -16,46 +13,18 @@
with open(os.path.join(HERE, 'dashboards_bundlers/_version.py')) as f:
exec(f.read(), {}, VERSION_NS)

def _install_notebook_extension():
cm = ConfigManager()
print('Installing notebook extension')
cm.update('notebook', {
'jupyter_cms_bundlers': {
'dashboards_local_deploy': {
'label': 'Local Dashboard',
'module_name': 'dashboards_bundlers.local_deploy',
'group': 'deploy'
},
'dashboards_php_download': {
'label': 'PHP Dashboard bundle (.zip)',
'module_name': 'dashboards_bundlers.php_download',
'group': 'download'
}
}
})

class InstallCommand(install):
def run(self):
install.run(self)
_install_notebook_extension()

class DevelopCommand(develop):
def run(self):
develop.run(self)
_install_notebook_extension()

setup(
setup_args = dict(
name='jupyter_dashboards_bundlers',
author='Jupyter Development Team',
author_email='[email protected]',
description='Plugins for jupyter_cms to deploy and download notebooks as dashboard apps',
long_description = '''
This package adds a *Deploy as* and *Download as* menu items for bundling
This package adds a *Deploy as* and *Download as* menu items for bundling
notebooks created using jupyter_dashboards as standalone web applications.

See `the project README <https://github.com/jupyter-incubator/dashboards_bundlers>`_
for more information.
''',
for more information.
''',
url='https://github.com/jupyter-incubator/dashboards_bundlers',
version=VERSION_NS['__version__'],
license='BSD',
Expand All @@ -66,11 +35,10 @@ def run(self):
'dashboards_bundlers.php_download'
],
include_package_data=True,
scripts=[
'scripts/jupyter-dashboards_bundlers'
],
install_requires=['jupyter_cms>=0.3.0'],
cmdclass={
'install': InstallCommand,
'develop': DevelopCommand
},
classifiers=[
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
Expand All @@ -82,4 +50,17 @@ def run(self):
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5'
]
)
)

if 'setuptools' in sys.modules:
# setupstools turns entrypoint scripts into executables on windows
setup_args['entry_points'] = {
'console_scripts': [
'jupyter-dashboards_bundlers = dashboards_bundlers.extensionapp:main'
]
}
# Don't bother installing the .py scripts if if we're using entrypoints
setup_args.pop('scripts', None)

if __name__ == '__main__':
setup(**setup_args)