changeset 29:ee3ac764f5f0

Merge pull request #6 from ryukinix/install-sh Add alternative installation using wget and sh
author Brendan Rius <brendan.rius@gmail.com>
date Fri, 29 Apr 2016 10:41:04 +0100
parents f257b2d1f95b (diff) 47c2bcc86359 (current diff)
children ccfb2b273434
files README.md c_kernel/__init__.py c_kernel/__main__.py c_kernel/kernel.py jupyter_c_kernel/__init__.py jupyter_c_kernel/__main__.py jupyter_c_kernel/kernel.py
diffstat 8 files changed, 109 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LICENSE.txt	Fri Apr 29 10:41:04 2016 +0100
@@ -0,0 +1,9 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 Brendan Rius
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
--- a/README.md	Fri Apr 29 05:47:25 2016 -0300
+++ b/README.md	Fri Apr 29 10:41:04 2016 +0100
@@ -28,3 +28,7 @@
 ## Example of notebook
 
 ![Example of notebook](example-notebook.png?raw=true "Example of notebook")
+
+## License
+
+[MIT](LICENSE.txt)
\ No newline at end of file
--- a/c_kernel/__main__.py	Fri Apr 29 05:47:25 2016 -0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,3 +0,0 @@
-from ipykernel.kernelapp import IPKernelApp
-from .kernel import CKernel
-IPKernelApp.launch_instance(kernel_class=CKernel)
--- a/c_kernel/kernel.py	Fri Apr 29 05:47:25 2016 -0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,84 +0,0 @@
-from ipykernel.kernelbase import Kernel
-import subprocess
-import tempfile
-import os
-
-
-class CKernel(Kernel):
-    implementation = 'c_kernel'
-    implementation_version = '1.0'
-    language = 'c'
-    language_version = 'C11'
-    language_info = {'name': 'c',
-                     'mimetype': 'text/plain',
-                     'file_extension': 'c'}
-    banner = "C kernel.\n" \
-             "Uses gcc, compiles in C11, and creates source code files and executables in temporary folder.\n"
-
-    def __init__(self, *args, **kwargs):
-        super(CKernel, self).__init__(*args, **kwargs)
-        self.files = []
-
-    def cleanup_files(self):
-        """Remove all the temporary files created by the kernel"""
-        for file in self.files:
-            os.remove(file)
-
-    def new_temp_file(self, **kwargs):
-        """Create a new temp file to be deleted when the kernel shuts down"""
-        # We don't want the file to be deleted when closed, but only when the kernel stops
-        kwargs['delete'] = False
-        kwargs['mode'] = 'w'
-        file = tempfile.NamedTemporaryFile(**kwargs)
-        self.files.append(file.name)
-        return file
-
-    @staticmethod
-    def execute_command(cmd):
-        """Execute a command and returns the return code, stdout and stderr"""
-        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-        stdout, stderr = p.communicate()
-        return p.returncode, stdout.decode('utf-8'), stderr.decode('utf-8')
-
-    @staticmethod
-    def compile_with_gcc(source_filename, binary_filename):
-        args = ['gcc', source_filename, '-std=c11', '-o', binary_filename]
-        return CKernel.execute_command(args)
-
-    def do_execute(self, code, silent, store_history=True,
-                   user_expressions=None, allow_stdin=False):
-
-        retcode, stdout, stderr = None, '', ''
-        with self.new_temp_file(suffix='.c') as source_file:
-            source_file.write(code)
-            source_file.flush()
-            with self.new_temp_file(suffix='.out') as binary_file:
-                retcode, stdout, stderr = self.compile_with_gcc(source_file.name, binary_file.name)
-                if retcode != 0:
-                    stderr += "[C kernel] GCC exited with code {}, the executable will not be executed".format(retcode)
-                self.log.info("GCC return code: {}".format(retcode))
-                self.log.info("GCC stdout: {}".format(stdout))
-                self.log.info("GCC stderr: {}".format(stderr))
-
-        if retcode == 0:  # If the compilation succeeded
-            retcode, out, err = CKernel.execute_command([binary_file.name])
-            if retcode != 0:
-                stderr += "[C kernel] Executable exited with code {}".format(retcode)
-            self.log.info("Executable retcode: {}".format(retcode))
-            self.log.info("Executable stdout: {}".format(out))
-            self.log.info("Executable stderr: {}".format(err))
-            stdout += out
-            stderr += err
-        else:
-            self.log.info('Compilation failed, the program will not be executed')
-
-        if not silent:
-            stream_content = {'name': 'stderr', 'text': stderr}
-            self.send_response(self.iopub_socket, 'stream', stream_content)
-            stream_content = {'name': 'stdout', 'text': stdout}
-            self.send_response(self.iopub_socket, 'stream', stream_content)
-        return {'status': 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {}}
-
-    def do_shutdown(self, restart):
-        """Cleanup the created source code files and executables when shutting down the kernel"""
-        self.cleanup_files()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jupyter_c_kernel/__main__.py	Fri Apr 29 10:41:04 2016 +0100
@@ -0,0 +1,3 @@
+from ipykernel.kernelapp import IPKernelApp
+from .kernel import CKernel
+IPKernelApp.launch_instance(kernel_class=CKernel)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jupyter_c_kernel/kernel.py	Fri Apr 29 10:41:04 2016 +0100
@@ -0,0 +1,84 @@
+from ipykernel.kernelbase import Kernel
+import subprocess
+import tempfile
+import os
+
+
+class CKernel(Kernel):
+    implementation = 'jupyter_c_kernel'
+    implementation_version = '1.0'
+    language = 'c'
+    language_version = 'C11'
+    language_info = {'name': 'c',
+                     'mimetype': 'text/plain',
+                     'file_extension': 'c'}
+    banner = "C kernel.\n" \
+             "Uses gcc, compiles in C11, and creates source code files and executables in temporary folder.\n"
+
+    def __init__(self, *args, **kwargs):
+        super(CKernel, self).__init__(*args, **kwargs)
+        self.files = []
+
+    def cleanup_files(self):
+        """Remove all the temporary files created by the kernel"""
+        for file in self.files:
+            os.remove(file)
+
+    def new_temp_file(self, **kwargs):
+        """Create a new temp file to be deleted when the kernel shuts down"""
+        # We don't want the file to be deleted when closed, but only when the kernel stops
+        kwargs['delete'] = False
+        kwargs['mode'] = 'w'
+        file = tempfile.NamedTemporaryFile(**kwargs)
+        self.files.append(file.name)
+        return file
+
+    @staticmethod
+    def execute_command(cmd):
+        """Execute a command and returns the return code, stdout and stderr"""
+        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        stdout, stderr = p.communicate()
+        return p.returncode, stdout.decode('utf-8'), stderr.decode('utf-8')
+
+    @staticmethod
+    def compile_with_gcc(source_filename, binary_filename):
+        args = ['gcc', source_filename, '-std=c11', '-o', binary_filename]
+        return CKernel.execute_command(args)
+
+    def do_execute(self, code, silent, store_history=True,
+                   user_expressions=None, allow_stdin=False):
+
+        retcode, stdout, stderr = None, '', ''
+        with self.new_temp_file(suffix='.c') as source_file:
+            source_file.write(code)
+            source_file.flush()
+            with self.new_temp_file(suffix='.out') as binary_file:
+                retcode, stdout, stderr = self.compile_with_gcc(source_file.name, binary_file.name)
+                if retcode != 0:
+                    stderr += "[C kernel] GCC exited with code {}, the executable will not be executed".format(retcode)
+                self.log.info("GCC return code: {}".format(retcode))
+                self.log.info("GCC stdout: {}".format(stdout))
+                self.log.info("GCC stderr: {}".format(stderr))
+
+        if retcode == 0:  # If the compilation succeeded
+            retcode, out, err = CKernel.execute_command([binary_file.name])
+            if retcode != 0:
+                stderr += "[C kernel] Executable exited with code {}".format(retcode)
+            self.log.info("Executable retcode: {}".format(retcode))
+            self.log.info("Executable stdout: {}".format(out))
+            self.log.info("Executable stderr: {}".format(err))
+            stdout += out
+            stderr += err
+        else:
+            self.log.info('Compilation failed, the program will not be executed')
+
+        if not silent:
+            stream_content = {'name': 'stderr', 'text': stderr}
+            self.send_response(self.iopub_socket, 'stream', stream_content)
+            stream_content = {'name': 'stdout', 'text': stdout}
+            self.send_response(self.iopub_socket, 'stream', stream_content)
+        return {'status': 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {}}
+
+    def do_shutdown(self, restart):
+        """Cleanup the created source code files and executables when shutting down the kernel"""
+        self.cleanup_files()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.cfg	Fri Apr 29 10:41:04 2016 +0100
@@ -0,0 +1,2 @@
+[metadata]
+description-file = README.md
\ No newline at end of file
--- a/setup.py	Fri Apr 29 05:47:25 2016 -0300
+++ b/setup.py	Fri Apr 29 10:41:04 2016 +0100
@@ -1,9 +1,12 @@
-from distutils.core import setup
+from setuptools import setup
 
 setup(name='jupyter_c_kernel',
-      version='1.0',
+      version='1.0.0',
       description='Minimalistic C kernel for Jupyter',
       author='Brendan Rius',
       author_email='ping@brendan-rius.com',
-      packages=['c_kernel'],
-     )
+      url='https://github.com/brendanrius/jupyter-c-kernel/',
+      download_url='https://github.com/brendanrius/jupyter-c-kernel/tarball/1.0.0',
+      packages=['jupyter_c_kernel'],
+      keywords=['jupyter', 'kernel', 'c']
+      )