/
setup.py
executable file
·95 lines (79 loc) · 3.06 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
import os
from setuptools import setup
from setuptools.command.install import install
from saagie import __version__
try:
from pypandoc import convert
except ImportError:
import io
def convert(filename, fmt):
with io.open(filename, encoding='utf-8') as fd:
return fd.read()
CURRENT_PATH = os.path.abspath(os.path.dirname(__file__))
EXTENSION_PATH = os.path.join(CURRENT_PATH, 'saagie')
with open(os.path.join(CURRENT_PATH, 'requirements.txt')) as f:
required = f.read().splitlines()
def setup_extensions():
try:
from notebook.nbextensions import install_nbextension
from notebook.services.config import ConfigManager
from jupyter_core.paths import jupyter_config_dir
except ImportError:
raise ImportError('Install Jupyter notebook before.')
# Installs JS extensions to ~/.local/share/jupyter/nbextensions
install_nbextension(EXTENSION_PATH, overwrite=True, user=True)
# Enables the JS extension.
js_cm = ConfigManager()
section = 'notebook'
cfg = js_cm.get(section)
extensions = cfg['load_extensions'] = cfg.setdefault('load_extensions',
{})
extensions['saagie/saagie'] = True
js_cm.update(section, cfg)
# Enables the Python server extension.
server_cm = ConfigManager(write_config_dir=jupyter_config_dir())
section = 'jupyter_notebook_config'
cfg = server_cm.get(section)
app = cfg['NotebookApp'] = cfg.setdefault('NotebookApp', {})
server_extensions = app['server_extensions'] = \
app.setdefault('server_extensions', [])
server_extension = 'saagie.server_extension'
if server_extension not in server_extensions:
server_extensions.append(server_extension)
server_cm.update(section, cfg)
class InstallCommand(install):
def run(self):
# Installs Python package & its dependencies.
install.do_egg_install(self)
self.execute(setup_extensions, (),
msg='Installing Jupyter JS & server extensions...')
setup(
name='jupyter-saagie-plugin',
version=__version__,
author='Saagie',
author_email='support@saagie.com',
url='https://github.com/saagie/jupyter-saagie-plugin',
description='Easily create a Saagie Python job from a Jupyter notebook',
long_description=convert('README.md', 'rst'),
classifiers=[
'Development Status :: 5 - Production/Stable',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
],
license='Apache',
packages=['saagie'],
cmdclass={
'install': InstallCommand,
},
install_requires=required,
include_package_data=True,
)