Mercurial > hg > Members > aka > jupyter_CbC_kernel
changeset 55:4a03cede4763
Merge pull request #27 from spoorcc/issue-14
Fix #14: Add args magic to provide cli-args to user program
committer: GitHub <noreply@github.com>
author | Brendan Rius <brendan.rius@gmail.com> |
---|---|
date | Thu, 13 Apr 2017 11:29:48 +0200 |
parents | 82b0505f1156 (current diff) 7857f8eea835 (diff) |
children | 161ad9354cbd |
files | |
diffstat | 2 files changed, 13 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/jupyter_c_kernel/kernel.py Wed Apr 12 20:59:16 2017 +0200 +++ b/jupyter_c_kernel/kernel.py Thu Apr 13 11:29:48 2017 +0200 @@ -2,6 +2,7 @@ from threading import Thread from ipykernel.kernelbase import Kernel +import re import subprocess import tempfile import os @@ -118,7 +119,9 @@ def _filter_magics(self, code): - magics = {'cflags': [], 'ldflags': []} + magics = {'cflags': [], + 'ldflags': [], + 'args': []} for line in code.splitlines(): if line.startswith('//%'): @@ -128,6 +131,10 @@ if key in ['ldflags', 'cflags']: for flag in value.split(): magics[key] += [flag] + elif key == "args": + # Split arguments respecting quotes + for argument in re.findall(r'(?:[^\s,"]|"(?:\\.|[^"])*")+', value): + magics['args'] += [argument.strip('"')] return magics @@ -151,7 +158,7 @@ return {'status': 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {}} - p = self.create_jupyter_subprocess([self.master_path, binary_file.name]) + p = self.create_jupyter_subprocess([self.master_path, binary_file.name] + magics['args']) while p.poll() is None: p.write_contents() p.write_contents()
--- a/resources/master.c Wed Apr 12 20:59:16 2017 +0200 +++ b/resources/master.c Thu Apr 13 11:29:48 2017 +0200 @@ -25,5 +25,7 @@ fprintf(stderr, "%s: %s\n", argv[0], error); return EXIT_FAILURE; } - return usermain(argc, argv, envp); -} \ No newline at end of file + + /* Call Users main, but make master.c invisible by removing first argument */ + return usermain(argc-1, argv+1, envp); +}