Skip to content

Commit

Permalink
fix issue with result with same id
Browse files Browse the repository at this point in the history
  • Loading branch information
giannisdoukas committed Jun 8, 2020
1 parent 2af1110 commit b8cc1df
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 2 additions & 0 deletions cwlkernel/CWLKernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,15 @@ def _execute_workflow(self, code_path: Path) -> Optional[Exception]:
if isinstance(results[output], list):
for i, output_i in enumerate(results[output]):
results[output][i]['id'] = f'{output}_{i + 1}'
results[output][i]['result_counter'] = self._results_manager.files_counter
self._results_manager.append_files(
[results[output][i]['location']],
output_directory_for_that_run,
metadata=results[output][i]
)
else:
results[output]['id'] = output
results[output]['result_counter'] = self._results_manager.files_counter
self._results_manager.append_files(
[results[output]['location']],
output_directory_for_that_run,
Expand Down
4 changes: 4 additions & 0 deletions cwlkernel/IOManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def __init__(self, root_directory: str):
self.ROOT_DIRECTORY = root_directory
self._files_registry = {}

@property
def files_counter(self):
return len(self._files_registry)

def read(self, relative_path: str) -> bytes:
full_path = os.path.join(self.ROOT_DIRECTORY, relative_path)

Expand Down
10 changes: 6 additions & 4 deletions cwlkernel/kernel_magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ def display_data(kernel: CWLKernel, data_name: str):
'ERROR: you must select an output to display. Correct format:\n % display_data [output name]'
)
return
results = list(
filter(lambda item: item[1]['id'] == data_name, kernel._results_manager.get_files_registry().items()))
if len(results) != 1:
results = sorted(
filter(lambda item: item[1]['id'] == data_name, kernel._results_manager.get_files_registry().items()),
key=lambda item: item[1]['result_counter']
)
if len(results) == 0:
kernel.send_response(kernel.iopub_socket, 'stream', {'name': 'stderr', 'text': 'Result not found'})
return
results = results[0]
results = results[-1]
with open(results[0]) as f:
data = f.read()
kernel.send_response(kernel.iopub_socket, 'stream', {'name': 'stdout', 'text': data})
Expand Down
19 changes: 17 additions & 2 deletions tests/test_CWLKernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ def test_display_data_magic_command(self):
responses[-1][0][2]['text']
)

self.assertDictEqual(
{'status': 'ok', 'execution_count': 0, 'payload': [], 'user_expressions': {}},
kernel.do_execute(data, False)
)
self.assertEqual(
{'status': 'ok', 'execution_count': 0, 'payload': [], 'user_expressions': {}},
kernel.do_execute('% display_data echo_output')
)
self.assertEqual(
'Hello world!\n',
responses[-1][0][2]['text']
)

def test_send_invalid_yaml(self):
from cwlkernel.CWLKernel import CWLKernel
kernel = CWLKernel()
Expand Down Expand Up @@ -315,7 +328,8 @@ def test_display_json_output_after_execution(self):
'nameroot': 'hello', 'nameext': '.txt', 'class': 'File',
'checksum': 'sha1$2aae6c35c94fcfb415dbe95f408b9ce91ee846ed', 'size': 11,
'http://commonwl.org/cwltool#generation': 0,
'id': 'example_out'
'id': 'example_out',
"result_counter": 0
}
}),
'application/json': {
Expand All @@ -324,7 +338,8 @@ def test_display_json_output_after_execution(self):
'nameroot': 'hello', 'nameext': '.txt', 'class': 'File',
'checksum': 'sha1$2aae6c35c94fcfb415dbe95f408b9ce91ee846ed', 'size': 11,
'http://commonwl.org/cwltool#generation': 0,
'id': 'example_out'
'id': 'example_out',
"result_counter": 0
}
}
},
Expand Down

0 comments on commit b8cc1df

Please sign in to comment.