Skip to content

Commit 1f3084d

Browse files
committed
Clean up installation
1 parent 3755cb2 commit 1f3084d

File tree

6 files changed

+46
-13
lines changed

6 files changed

+46
-13
lines changed

MANIFEST.in

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
include versioneer.py
22
include matlab_kernel/_version.py
3+
include matlab_kernel/kernel.json
4+
recursive-include matlab_kernel *.png

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ export NAME=`python setup.py --name 2>/dev/null`
55
export VERSION=`python setup.py --version 2>/dev/null`
66

77
all: clean
8-
python setup.py install
8+
pip install .
99

1010
clean:
1111
rm -rf build
1212
rm -rf dist
1313

1414
test: clean
15-
python setup.py build
16-
python -m matlab_kernel install
15+
pip install .
16+
python -c "from jupyter_client.kernelspec import find_kernel_specs; assert 'matlab' in find_kernel_specs()"
1717

1818
release: test clean
1919
pip install wheel

README.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ To install::
1010
$ pip install matlab_kernel
1111
# or `pip install git+https://github.com/Calysto/matlab_kernel`
1212
# for the devel version.
13-
$ python -m matlab_kernel install
1413

1514
To use it, run one of::
1615

@@ -35,4 +34,10 @@ open figures to image files whose format and resolution are defined using the
3534
``%plot`` magic. The resulting image is shown inline in the notebook. You can
3635
use ``%plot native`` to raise normal Matlab windows instead.
3736

37+
38+
Advanced Installation Notes::
39+
40+
We automatically install a Jupyter kernelspec when installing the python package. This location can be found using ``jupyter kernelspec list``. If the default location is not desired, you can remove the directory for the octave kernel, and install using python -m matlab_kernel install. See python -m matlab_kernel install --help for available options.
41+
42+
3843
.. _online: http://nbviewer.ipython.org/github/Calysto/matlab_kernel/blob/master/matlab_kernel.ipynb

matlab_kernel/kernel.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"argv": [
3+
"python", "-m", "matlab_kernel", "-f", "{connection_file}"],
4+
"display_name": "Matlab",
5+
"language": "matlab",
6+
"mimetype": "text/x-octave",
7+
"name": "matlab",
8+
}

matlab_kernel/kernel.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from StringIO import StringIO
99
except ImportError:
1010
from io import StringIO
11+
import json
1112
import os
1213
import sys
1314
try:
@@ -32,28 +33,31 @@ def __init__(self, writer):
3233
self.write = writer
3334

3435

36+
def get_kernel_json():
37+
"""Get the kernel json for the kernel.
38+
"""
39+
here = os.path.dirname(__file__)
40+
with open(os.path.join(here, 'kernel.json')) as fid:
41+
data = json.load(fid)
42+
data['argv'][0] = sys.executable
43+
return data
44+
45+
3546
class MatlabKernel(MetaKernel):
3647
implementation = "Matlab Kernel"
3748
implementation_version = __version__,
3849
language = "matlab"
3950
language_version = __version__,
4051
banner = "Matlab Kernel"
4152
language_info = {
42-
"mimetype": "text/x-matlab",
53+
"mimetype": "text/x-octave",
4354
"codemirror_mode": "octave",
4455
"name": "matlab",
4556
"file_extension": ".m",
4657
"version": __version__,
4758
"help_links": MetaKernel.help_links,
4859
}
49-
kernel_json = {
50-
"argv": [
51-
sys.executable, "-m", "matlab_kernel", "-f", "{connection_file}"],
52-
"display_name": "Matlab",
53-
"language": "matlab",
54-
"mimetype": "text/x-matlab",
55-
"name": "matlab",
56-
}
60+
kernel_json = get_kernel_json()
5761

5862
def __init__(self, *args, **kwargs):
5963
super(MatlabKernel, self).__init__(*args, **kwargs)

setup.py

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import glob
12
from setuptools import setup, find_packages
23

34
with open('matlab_kernel/__init__.py', 'rb') as fid:
@@ -7,6 +8,16 @@
78
version = line.strip().split()[-1][1:-1]
89
break
910

11+
DISTNAME = 'matlab_kernel'
12+
PACKAGE_DATA = {
13+
DISTNAME: ['*.m'] + glob.glob('%s/**/*.*' % DISTNAME)
14+
}
15+
DATA_FILES = [
16+
('share/jupyter/kernels/octave', [
17+
'%s/kernel.json' % DISTNAME
18+
] + glob.glob('%s/images/*.png' % DISTNAME)
19+
)
20+
]
1021

1122
if __name__ == "__main__":
1223
setup(name="matlab_kernel",
@@ -21,6 +32,9 @@
2132
"Programming Language :: Python :: 3.5",
2233
"Topic :: System :: Shells"],
2334
packages=find_packages(include=["matlab_kernel", "matlab_kernel.*"]),
35+
package_data=PACKAGE_DATA,
36+
include_package_data=True,
37+
data_files=DATA_FILES,
2438
requires=["metakernel (>0.18.0)", "jupyter_client (>=4.4.0)",
2539
"ipython (>=4.0.0)"],
2640
install_requires=["metakernel>=0.18.0", "jupyter_client >=4.4.0",

0 commit comments

Comments
 (0)