Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix launching non python kernels from a windows store installed jupyter #568

Merged
merged 5 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion jupyter_client/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,12 @@ def format_kernel_cmd(self, extra_arguments=None):
# but it should be.
cmd[0] = sys.executable

ns = dict(connection_file=self.connection_file,
# Make sure to use the realpath for the connection_file
# On windows, when running with the store python, the connection_file path
# is not usable by non python kernels because the path is being rerouted when
# inside of a store app.
# See this bug here: https://bugs.python.org/issue41196
ns = dict(connection_file=os.path.realpath(self.connection_file),
prefix=sys.prefix,
)

Expand Down
38 changes: 38 additions & 0 deletions jupyter_client/tests/test_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Tests for KernelManager"""

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from jupyter_client.kernelspec import KernelSpec
from unittest import mock
from jupyter_client.manager import KernelManager
import os
import tempfile


def test_connection_file_real_path():
""" Verify realpath is used when formatting connection file """
with mock.patch('os.path.realpath') as patched_realpath:
patched_realpath.return_value = 'foobar'
km = KernelManager(connection_file=os.path.join(
tempfile.gettempdir(), "kernel-test.json"),
kernel_name='test_kernel')

# KernelSpec and launch args have to be mocked as we don't have an actual kernel on disk
km._kernel_spec = KernelSpec(resource_dir='test',
**{
"argv": [
"python.exe",
"-m",
"test_kernel",
"-f",
"{connection_file}"
],
"env": {},
"display_name": "test_kernel",
"language": "python",
"metadata": {}
})
km._launch_args = {}
cmds = km.format_kernel_cmd()
assert cmds[4] is 'foobar'