# HG changeset patch # User musou_aka <> # Date 1529977124 -32400 # Node ID 62bff02c6fbcee28518d9af65889cd6263841be9 # Parent 4d7d24e87c887eacbaa34ad7531ea9adba3254d5 fix file name diff -r 4d7d24e87c88 -r 62bff02c6fbc jupyter_CbC_kernel/install_CbC_kernel --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jupyter_CbC_kernel/install_CbC_kernel Tue Jun 26 10:38:44 2018 +0900 @@ -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_CbC_kernel", + "-f", + "{connection_file}" + ], + "display_name": "CbC", + "language": "CbC" +} + + +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, 'CbC', 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) diff -r 4d7d24e87c88 -r 62bff02c6fbc jupyter_CbC_kernel/install_c_kernel --- a/jupyter_CbC_kernel/install_c_kernel Mon Jun 25 23:26:36 2018 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -#!/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_CbC_kernel", - "-f", - "{connection_file}" - ], - "display_name": "CbC", - "language": "CbC" -} - - -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, 'CbC', 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)