-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
executable file
·81 lines (61 loc) · 2.28 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
#!/usr/bin/env python
import sys
import subprocess
from distutils import log
from setuptools import setup
from setuptools.command.install import install
# General Requirements
SETUP_REQUIRES = ['ipython', 'ipykernel']
INSTALL_REQUIRES = ['mathics>=1.0.dev0'] + SETUP_REQUIRES
kernel_json = {
'argv': [sys.executable,
'-m', 'mathicsnotebook',
'-f', '{connection_file}'],
'display_name': 'MathicsKernel',
'language': 'Mathematica',
'name': 'mathicsnotebook',
}
class InstallIMathics(install):
def run(self):
# The recommended way is with the setup_requires argument to setup
# This fails because ipython doesn't build under easy_install
subprocess.check_call([sys.executable, '-m', 'pip', 'install'] + SETUP_REQUIRES)
# Unfortunately the recommended call to 'install.run(self)'
# will completely ignore the install_requirements.
# So we trick it by calling the underlying bdist_egg instead:
self.do_egg_install()
self.install_kernelspec()
def install_kernelspec(self):
from ipykernel.kernelspec import write_kernel_spec
from jupyter_client.kernelspec import KernelSpecManager
kernel_spec_manager = KernelSpecManager()
log.info('Writing kernel spec')
kernel_spec_path = write_kernel_spec(overrides=kernel_json)
log.info('Installing kernel spec ' + kernel_spec_path)
try:
kernel_spec_manager.install_kernel_spec(
kernel_spec_path,
kernel_name=kernel_json['name'],
user=self.user)
except Exception as e:
log.error(str(e.args))
log.error('Failed to install kernel spec')
else:
return
# retry with not self.user
log.info('Retry install kernel spec')
try:
kernel_spec_manager.install_kernel_spec(
kernel_spec_path,
kernel_name=kernel_json['name'],
user=not self.user)
except Exception as e:
log.error(str(e.args))
log.error('Failed to install kernel spec')
setup(
name="mathicsnotebook",
cmdclass={'install': InstallIMathics},
version='0.1',
packages=['mathicsnotebook'],
install_requires=INSTALL_REQUIRES,
)