Skip to content

Commit

Permalink
add data magic command
Browse files Browse the repository at this point in the history
  • Loading branch information
giannisdoukas committed Mar 4, 2020
1 parent ace9530 commit 85639ac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cwlkernel/CWLKernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CWLKernel(Kernel):
}
banner = "Common Workflow Language"

_magic_commands = frozenset(['logs'])
_magic_commands = frozenset(['logs', 'data'])

def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand Down Expand Up @@ -132,6 +132,25 @@ def _execute_magic_logs(self, limit=None):
}
)

def _execute_magic_data(self, *args):
data = "<ul>\n" + '\n'.join(
[f'\t<li><a href="file://{d}" target="_empty">{d}</a></li>' for d in self.get_past_results()]) + "\n</ul>"
self.send_response(
self.iopub_socket,
'display_data',
{
'data': {
'text/html': data
},
'metadata': {
'application/json': {
'expanded': False,
'root': 'root'
}
}
}
)

def _accumulate_data(self, code: str):
cwl = self._cwl_executor.file_manager.get_files_uri().path
self._cwl_executor.validate_input_files(yaml.load(code, Loader=yaml.Loader), cwl)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_CWLKernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from ruamel import yaml

from cwlkernel.CWLKernel import CWLKernel


class TestCWLKernel(unittest.TestCase):
data_directory: str
Expand Down Expand Up @@ -185,6 +187,13 @@ def test_handle_input_data_files(self):
os.chdir(tmp_dir)
data['example_file']['path'] = os.path.basename(data['example_file']['path'])

def test_all_magic_commands_have_methods(self):
kernel = CWLKernel()
for magic in kernel._magic_commands:
try:
kernel.__getattribute__(f'_execute_magic_{magic}')
except AttributeError as e:
self.fail(f'Missing function for magic command: {magic}. \nAttribute error raises: {e}')


if __name__ == '__main__':
Expand Down

0 comments on commit 85639ac

Please sign in to comment.