Ejemplo n.º 1
0
def install_my_kernel_spec(user=True, prefix=None, powershell_command=None):

    if sys.version_info >= (3, 0):
        if powershell_command is None:
            powershell_command = get_powershell()
        kernel_json.update({'env': {'powershell_command': powershell_command}})
        print('Using powershell_command=%r' % powershell_command)
    else:
        # python 2 cannot use env to pass values to the kernel
        # https://github.com/vors/jupyter-powershell/issues/7
        # TODO(python2): find a way to pass it
        if powershell_command is not None:
            print(
                'Ignoring powershell_command on python2, jupyter will use default powershell_command=%r'
                % powershell_command)

    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,
                                                'powershell',
                                                user=user,
                                                prefix=prefix)
Ejemplo n.º 2
0
    def __createProxy(self):
        # powershell_command env variable is set by the kernel to allow both powershell and pwsh
        # but on python2 we cannot pass it thru env variable, see https://github.com/vors/jupyter-powershell/issues/7
        # TODO(python2): can we pass it somehow differently and still provide user-picked value on python2?
        try:
            powershell_command = environ['powershell_command']
        except:
            powershell_command = get_powershell()

        repl = subprocess_repl.SubprocessRepl([
            powershell_command, '-noninteractive', '-noprofile', '-File', '-'
        ])
        self.proxy = powershell_proxy.ReplProxy(repl)
Ejemplo n.º 3
0
    def __init__(self, **kwargs):
        Kernel.__init__(self, **kwargs)
        
        # powershell_command env variable is set by the kernel to allow both powershell and pwsh
        # but on python2 we cannot pass it thru env variable, see https://github.com/vors/jupyter-powershell/issues/7
        # TODO(python2): can we pass it somehow differently and still provide user-picked value on python2?
        try:
            powershell_command = environ['powershell_command']
        except:
            powershell_command = get_powershell()

        repl = subprocess_repl.SubprocessRepl([powershell_command, '-noprofile', '-File', '-'])
        self.proxy = powershell_proxy.ReplProxy(repl)
Ejemplo n.º 4
0
    def __init__(self, **kwargs):
        Kernel.__init__(self, **kwargs)

        # powershell_command env variable is set by the kernel to allow both powershell and pwsh
        # but on python2 we cannot pass it thru env variable, see https://github.com/vors/jupyter-powershell/issues/7
        # TODO(python2): can we pass it somehow differently and still provide user-picked value on python2?
        try:
            powershell_command = environ['powershell_command']
        except:
            powershell_command = get_powershell()

        repl = powershell_repl.PowershellRepl(
            'utf8', cmd=[powershell_command, '-noprofile', '-File', '-'])
        self.proxy = powershell_proxy.ReplProxy(repl)
Ejemplo n.º 5
0
def install_my_kernel_spec(user=True, prefix=None, powershell_command=None):
    
    if sys.version_info >= (3, 0): 
        if powershell_command is None:
            powershell_command = get_powershell()
        kernel_json.update({'env': {'powershell_command' : powershell_command}})
        print('Using powershell_command=%r' % powershell_command)
    else:
        # python 2 cannot use env to pass values to the kernel
        # https://github.com/vors/jupyter-powershell/issues/7
        # TODO(python2): find a way to pass it
        if powershell_command is not None:
            print('Ignoring powershell_command on python2, jupyter will use default powershell_command=%r' % powershell_command)

    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, 'powershell', user=user, replace=True, prefix=prefix)