changeset 58:8a8a9952c887

Change install procedure
author Brendan Rius <brendan.rius@gmail.com>
date Thu, 10 Aug 2017 17:00:32 +0200
parents 308a0eaa4e49
children f7b9bc7445e2
files Dockerfile README.md c_spec/kernel.json jupyter_c_kernel/install_c_kernel setup.py
diffstat 5 files changed, 89 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/Dockerfile	Tue Aug 08 02:00:58 2017 +0200
+++ b/Dockerfile	Thu Aug 10 17:00:32 2017 +0200
@@ -3,13 +3,13 @@
 
 USER root
 
-RUN mkdir /jupyter
-
-WORKDIR /jupyter
+WORKDIR /tmp
 
 COPY ./ jupyter_c_kernel/
-RUN pip install -e jupyter_c_kernel/
 
-RUN jupyter-kernelspec install jupyter_c_kernel/c_spec/
+RUN pip install --no-cache-dir -e jupyter_c_kernel/
+RUN cd jupyter_c_kernel && python -m jupyter_c_kernel.install_c_kernel --user
 
 WORKDIR /home/$NB_USER/
+
+USER $NB_USER
--- a/README.md	Tue Aug 08 02:00:58 2017 +0200
+++ b/README.md	Thu Aug 10 17:00:32 2017 +0200
@@ -16,9 +16,7 @@
 
 ### Step-by-step:
  * `pip install jupyter-c-kernel`
- * `git clone https://github.com/brendan-rius/jupyter-c-kernel.git`
- * `cd jupyter-c-kernel`
- * `jupyter-kernelspec install c_spec/`
+ * `install_c_kernel`
  * `jupyter-notebook`. Enjoy!
 
 ### Easy installation for Unix user:
--- a/c_spec/kernel.json	Tue Aug 08 02:00:58 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-{
-  "argv": [
-    "python3",
-    "-m",
-    "jupyter_c_kernel",
-    "-f",
-    "{connection_file}"
-  ],
-  "display_name": "C",
-  "language": "c"
-}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jupyter_c_kernel/install_c_kernel	Thu Aug 10 17:00:32 2017 +0200
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+
+import json
+import os
+import sys
+import argparse
+
+from jupyter_client.kernelspec import KernelSpecManager
+from IPython.utils.tempdir import TemporaryDirectory
+
+kernel_json = {
+    "argv": [
+        "python3",
+        "-m",
+        "jupyter_c_kernel",
+        "-f",
+        "{connection_file}"
+    ],
+    "display_name": "C",
+    "language": "c"
+}
+
+
+def install_my_kernel_spec(user=True, prefix=None):
+    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)
+        # TODO: Copy resources once they're specified
+
+        print('Installing IPython kernel spec')
+        KernelSpecManager().install_kernel_spec(td, 'bash', user=user, replace=True, prefix=prefix)
+
+
+def _is_root():
+    try:
+        return os.geteuid() == 0
+    except AttributeError:
+        return False  # assume not an admin on non-Unix platforms
+
+
+def main(argv=[]):
+    parser = argparse.ArgumentParser(
+        description='Install KernelSpec for C Kernel'
+    )
+    prefix_locations = parser.add_mutually_exclusive_group()
+
+    prefix_locations.add_argument(
+        '--user',
+        help='Install KernelSpec in user homedirectory',
+        action='store_false' if _is_root() else 'store_true'
+    )
+    prefix_locations.add_argument(
+        '--sys-prefix',
+        help='Install KernelSpec in sys.prefix. Useful in conda / virtualenv',
+        action='store_true',
+        dest='sys_prefix'
+    )
+    prefix_locations.add_argument(
+        '--prefix',
+        help='Install KernelSpec in this prefix',
+        default=None
+    )
+
+    args = parser.parse_args()
+
+    if args.sys_prefix:
+        prefix = sys.prefix
+        user = None
+    elif args.user:
+        prefix = None
+        user = True
+    else:
+        prefix = args.prefix
+        user = None
+
+    install_my_kernel_spec(user=user, prefix=prefix)
+
+
+if __name__ == '__main__':
+    main(argv=sys.argv)
--- a/setup.py	Tue Aug 08 02:00:58 2017 +0200
+++ b/setup.py	Thu Aug 10 17:00:32 2017 +0200
@@ -8,5 +8,6 @@
       url='https://github.com/brendanrius/jupyter-c-kernel/',
       download_url='https://github.com/brendanrius/jupyter-c-kernel/tarball/1.1.0',
       packages=['jupyter_c_kernel'],
-      keywords=['jupyter', 'kernel', 'c']
+      scripts=['jupyter_c_kernel/install_c_kernel'],
+      keywords=['jupyter', 'notebook', 'kernel', 'c']
       )