Skip to content

Commit

Permalink
Accept kernel name with * and ? in language module #192
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Peng committed Feb 9, 2019
1 parent 8a6cf20 commit a72268b
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/sos_notebook/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,10 @@ def update_existing(idx):
except Exception as e:
raise RuntimeError(
f'Failed to load language {language}: {e}')
if name in plugin.supported_kernels:
# if name is defined in the module, only search kernels for this language
avail_kernels = [x for x in plugin.supported_kernels[name] if
x in [y.kernel for y in self._kernel_list]]
else:
# otherwise we search all supported kernels
avail_kernels = [x for x in sum(plugin.supported_kernels.values(), []) if
x in [y.kernel for y in self._kernel_list]]

avail_kernels = [y.kernel for y in self._kernel_list if
y.kernel in sum(plugin.supported_kernels.values(), []) or
any(fnmatch.fnmatch(y.kernel, x) for x in sum(plugin.supported_kernels.values(), []))]

if not avail_kernels:
raise ValueError(
Expand All @@ -355,7 +351,7 @@ def update_existing(idx):
# use the first available kernel
# find the language that has the kernel
lan_name = list({x: y for x, y in plugin.supported_kernels.items(
) if avail_kernels[0] in y}.keys())[0]
) if avail_kernels[0] in y or any(fnmatch.fnmatch(avail_kernels[0], z) for z in y)}.keys())[0]
if color == 'default':
color = self.get_background_color(plugin, lan_name)
new_def = self.add_or_replace(subkernel(name, avail_kernels[0], lan_name, self.get_background_color(plugin, lan_name) if color is None else color,
Expand All @@ -369,11 +365,13 @@ def update_existing(idx):
#
plugin = self.language_info[language]
if language in plugin.supported_kernels:
avail_kernels = [x for x in plugin.supported_kernels[language] if
x in [y.kernel for y in self._kernel_list]]
avail_kernels = [y.kernel for y in self._kernel_list if
y.kernel in plugin.supported_kernels[language] or
any(fnmatch.fnmatch(y.kernel, x) for x in plugin.supported_kernels[language]) ]
else:
avail_kernels = [x for x in sum(plugin.supported_kernels.values(), []) if
x in [y.kernel for y in self._kernel_list]]
avail_kernels = [y.kernel for y in self._kernel_list if
y.kernel in sum(plugin.supported_kernels.values(), []) or
any(fnmatch.fnmatch(y.kernel, x) for x in sum(plugin.supported_kernels.values(), [])) ]
if not avail_kernels:
raise ValueError(
'Failed to find any of the kernels {} supported by language {}. Please make sure it is properly installed and appear in the output of command "jupyter kenelspec list"'.format(
Expand Down

0 comments on commit a72268b

Please sign in to comment.