forked from danielballan/nbexamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
54 lines (44 loc) · 1.63 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
from setuptools import setup
from setuptools.command.install import install
from setuptools.command.develop import develop
from jupyter_core.paths import jupyter_config_dir
from IPython.html.nbextensions import install_nbextension
from IPython.html.services.config import ConfigManager
HERE = os.path.abspath(os.path.dirname(__file__))
EXT_DIR = os.path.join(HERE, 'nbshared', 'static')
SERVER_EXT_CONFIG = "c.NotebookApp.server_extensions.append('nbshared.handlers')"
class InstallCommand(install):
def run(self):
# Install Python package, possibly containing a kernel extension
install.run(self)
_install_server_extension()
_install_js()
class DevelopCommand(develop):
def run(self):
develop.run(self)
_install_server_extension()
_install_js()
def _install_server_extension():
# Install Notebook server extension
fn = os.path.join(jupyter_config_dir(), 'jupyter_notebook_config.py')
with open(fn, 'r+') as fh:
lines = fh.read()
if SERVER_EXT_CONFIG not in lines:
fh.seek(0, 2)
fh.write('\n')
fh.write(SERVER_EXT_CONFIG)
def _install_js():
install_nbextension(EXT_DIR, destination='nbshared',
overwrite=True, user=True, verbose=2)
cm = ConfigManager()
print('Enabling extension for notebook')
cm.update("notebook", {"load_extensions":
{"nbshared/submit-shared-button": True}})
cm.update("tree", {"load_extensions": {"nbshared/main": True}})
setup(
name='nbshared',
version='0.1',
packages=['nbshared'],
include_package_data=True
)