SmartDataInnovationLab / jupyter_nbextensions_vcs_integration

VCS Integration into the frontend of jupyter
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

the python package should install and enable the frontend package when installed #1

Open bjuergens opened 6 years ago

bjuergens commented 6 years ago

With this it would be trivial to include this plugin in a conda environment.

What needs to be done during package installation:

Currently we do this by hand and via bash. It needs to be done python and automatically.

according to this blog post it is possible.

Their example the setup.py is this:

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

from notebook.nbextensions import install_nbextension
from notebook.services.config import ConfigManager
from jupyter_core.paths import jupyter_config_dir

EXT_DIR = os.path.join(os.path.dirname(__file__), 'myext')

class InstallCommand(install):
    def run(self):
        # Install Python package
        install.run(self)

        # Install JavaScript extensions to ~/.local/jupyter/
        install_nbextension(EXT_DIR, overwrite=True, user=True)

        # Activate the JS extensions on the notebook, tree, and edit screens
        js_cm = ConfigManager()
        js_cm.update('notebook', {"load_extensions": {'myext_js/notebook': True}})
        js_cm.update('tree', {"load_extensions": {'myext_js/dashboard': True}})
        js_cm.update('edit', {"load_extensions": {'myext_js/editor': True}})

        # Activate the Python server extension
        server_cm = ConfigManager(config_dir=jupyter_config_dir())
        cfg = server_cm.get('jupyter_notebook_config')
        server_extensions = (cfg.setdefault('NotebookApp', {})
            .setdefault('server_extensions', [])
        )
        if extension not in server_extensions:
            cfg['NotebookApp']['server_extensions'] += ['myext.my_handler']
            server_cm.update('jupyter_notebook_config', cfg)

setup(
    name='myext',
    version='0.1',
    packages=['myext'],
    cmdclass={
        'install': InstallCommand
    }
)
bjuergens commented 6 years ago

better way here: https://github.com/jupyter/notebook/pull/3116