Skip to content

Commit

Permalink
Changing current directory of subkernels with magic %cd vatlab/jupyte…
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Peng committed May 8, 2018
1 parent 4db4548 commit fab0281
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@
'markdown',
'pandas',
# language modules
'sos-bash',
'sos-javascript',
'sos-julia',
'sos-matlab',
'sos-python',
'sos-r',
'sos-sas',
'sos-bash>=0.9.12.2',
'sos-javascript>=0.9.12.2',
'sos-julia>=0.9.12.1',
'sos-matlab>=0.9.12.1',
'sos-python>=0.9.12.1',
'sos-r>=0.9.12.1',
'sos-sas>=0.9.12.2',
],
entry_points='''
[sos_functions]
Expand Down
24 changes: 24 additions & 0 deletions src/sos_notebook/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,30 @@ def handle_magic_cd(self, option):
except Exception as e:
self.warn(
f'Failed to change dir to {os.path.expanduser(to_dir)}: {e}')
return
#
cur_kernel = self.kernel
try:
for kernel in self.kernels.keys():
kinfo = self.subkernels.find(kernel)
if kernel not in self.supported_languages:
self.warn(f'Current directory of kernel {kernel} is not changed: unsupported language')
continue
lan = self.supported_languages[kernel]
if hasattr(lan, 'cd_command'):
try:
self.switch_kernel(kernel)
cmd = interpolate(lan.cd_command, {'dir': to_dir})
self.run_cell(cmd, True, False, on_error=f'Failed to execute {cmd} in {kernel}')
except Exception as e:
self.warn(
f'Current directory of kernel {kernel} is not changed: {e}')
else:
self.warn(
f'Current directory of kernel {kernel} is not changed: cd_command not defined')
finally:
self.switch_kernel(cur_kernel)


def handle_shell_command(self, cmd):
# interpolate command
Expand Down

0 comments on commit fab0281

Please sign in to comment.