-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
120 lines (108 loc) · 3.54 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env python
# coding: utf-8
from __future__ import print_function
import sys
import os
import json
from setuptools import setup, find_packages
from distutils.command.install import install
# The package names
pkg_main = 'mpkernel'
pkg_unix = 'unix'
pkg_stmhal = 'stmhal'
# ----------------------------------------------------------------------------
# Configure the kernel json files
# ----------------------------------------------------------------------------
kernel_json_unix = {
"display_name": "micropython-unix",
"language": "python",
"argv": [
sys.executable,
"-m",
pkg_unix,
"-f",
"{connection_file}"
]
}
kernel_json_pyboard = {
"display_name": "micropython-stmhal",
"language": "python",
"argv": [
sys.executable,
"-m",
pkg_stmhal,
"-f",
"{connection_file}"
]
}
class install_with_kernelspec(install):
def run(self):
install.run(self)
try:
from jupyter_client.kernelspec import install_kernel_spec
except ImportError:
from IPython.kernel.kernelspec import install_kernel_spec
from IPython.utils.tempdir import TemporaryDirectory
# Install unix port
with TemporaryDirectory() as td:
os.chmod(td, 0o755)
with open(os.path.join(td, 'kernel.json'), 'w') as f:
json.dump(kernel_json_unix, f, sort_keys=True)
kernel_name = 'mp' + pkg_unix
try:
install_kernel_spec(td, kernel_name=kernel_name,
user=self.user, replace=True)
except:
install_kernel_spec(td, kernel_name=kernel_name,
user=not self.user, replace=True)
# Install pyboard port
with TemporaryDirectory() as td:
os.chmod(td, 0o755)
with open(os.path.join(td, 'kernel.json'), 'w') as f:
json.dump(kernel_json_pyboard, f, sort_keys=True)
kernel_name = 'mp' + pkg_stmhal
try:
install_kernel_spec(td, kernel_name=kernel_name,
user=self.user, replace=True)
except:
install_kernel_spec(td, kernel_name=kernel_name,
user=not self.user, replace=True)
# Get the readme text
with open('README.md') as readme_file:
readme = readme_file.read()
setup(
name=pkg_main,
version='0.2',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
cmdclass={'install': install_with_kernelspec},
test_suite='tests',
tests_require=[
],
install_requires=[
'jupyter>=1.0.0',
'pyserial>=2.7'
],
# Metadata for PyPI
author='Tony Abboud',
author_email='tony.abboud54@gmail.com',
description='Jupyter Kernels for Micropython',
long_description=readme,
license='MIT',
keywords=['Micropython', 'ipython', 'jupyter', 'interactive'],
# Project home page
url='https://github.com/tdabboud/%s' % pkg_main,
# download_url='https://github.com/tdabboud/%s/tarball/0.1' % pkg_main,
platforms='Linux',
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Developers',
'Natural Language :: English',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'License :: OSI Approved :: MIT License'
]
)