-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathsetup.py
More file actions
98 lines (87 loc) · 3.31 KB
/
setup.py
File metadata and controls
98 lines (87 loc) · 3.31 KB
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
96
97
98
import sys
import os
import json
import inspect
import subprocess
import site
from setuptools import setup
from distutils import log
from distutils.command.install import install
from distutils.sysconfig import get_python_lib
try:
# Python 3
from urllib.request import urlretrieve
except ImportError:
# Python 2
from urllib import urlretrieve
VERSION='0.6'
PACKAGE_NAME='eclairjs'
JAR_FILE='eclairjs-nashorn-'+VERSION+'-jar-with-dependencies.jar'
JAR_FILE_PATH = os.path.join(PACKAGE_NAME, "jars", JAR_FILE)
INSTALL_DIR = os.path.join(get_python_lib(), PACKAGE_NAME)
MAVEN_URL = 'http://repo2.maven.org/maven2/org/eclairjs/eclairjs-nashorn/'+VERSION+'/'+JAR_FILE
urlretrieve(MAVEN_URL, JAR_FILE_PATH)
svem_flag = '--single-version-externally-managed'
if svem_flag in sys.argv:
# Die, setuptools, die.
sys.argv.remove(svem_flag)
class install_with_kernelspec(install):
def build_kernel_json(self):
import toree
toree_home = os.path.dirname(inspect.getfile(toree))
jar_dir = site.getsitepackages()[0]
jar = os.path.join(jar_dir, PACKAGE_NAME, "jars", JAR_FILE)
#jar = os.path.join(INSTALL_DIR, "jars", JAR_FILE)
kernel_json = {
"name": "eclair",
"display_name": "Spark 1.6.0 (EclairJS Toree)",
"language": "javascript",
"argv": [
os.path.join(toree_home, 'bin/run.sh'),
"--interpreter-plugin",
"eclair:org.eclairjs.nashorn.JavascriptInterpreter",
"--default-interpreter",
"eclair",
"--nosparkcontext",
"--profile",
"{connection_file}"
],
"env": {
"SPARK_OPTS": "--jars " + jar,
"SPARK_HOME": os.environ['SPARK_HOME']
}
}
return kernel_json
def run(self):
install.run(self)
user = '--user' in sys.argv
kernel_json = self.build_kernel_json()
try:
from ipykernel.kerspec import install_kernel_spec
except ImportError:
from IPython.kernel.kernelspec import install_kernel_spec
from IPython.utils.tempdir import TemporaryDirectory
with TemporaryDirectory() as td:
os.chmod(td, 0o755) # Starts off as 700, not user readable
with open(os.path.join(td, 'kernel.json'), 'w') as f:
json.dump(kernel_json, f, sort_keys=True)
log.info('Installing kernel spec')
kernel_name = kernel_json['name']
try:
install_kernel_spec(td, kernel_name, user=user,
replace=True)
except:
install_kernel_spec(td, kernel_name, user=not user,
replace=True)
setup(name=PACKAGE_NAME,
version=VERSION,
description='jupyter toree kernel for eclairjs',
url='https://github.com/eclairjs/eclairjs-nashorn',
author='Brian Burns',
author_email='brian.p.burns@gmail.com',
license='Apache 2',
install_requires=["IPython >= 4.0", "ipykernel", "toree"],
cmdclass={'install': install_with_kernelspec},
package_data={PACKAGE_NAME: ['jars/*']},
packages=[PACKAGE_NAME]
)