nireports.assembler.misc module

Miscellaneous utilities.

nireports.assembler.misc.dict2html(indict, table_id)[source]

Convert a dictionary into an HTML table.

nireports.assembler.misc.read_crashfile(path, root=None, root_replace='<workdir>')[source]

Prepare crashfiles for rendering into a report.

Parameters:
  • path (str or Path) – The path where the crash-file is located.

  • root (str or Path) – The root folder. If provided, the path will be replaced with root_replace.

  • root_replace (str) – A replacement for the absolute root path.

Examples

>>> info = read_crashfile(test_data_path / 'crashfile.txt')
>>> info['node']  
'...func_preproc_task_machinegame_run_02_wf.carpetplot_wf.conf_plot'
>>> info['traceback']  
'...ValueError: zero-size array to reduction operation minimum which has no identity'
>>> info['file']
'...nireports/assembler/data/tests/crashfile.txt'
>>> read_crashfile(
...     test_data_path / 'crashfile.txt',
...     root=test_data_path,
...     root_replace="<outdir>",
... )['file']
'<outdir>/crashfile.txt'
nireports.assembler.misc.unfold_columns(indict, prefix=None, delimiter='_')[source]

Convert an input dict with flattened keys to an list of rows expanding columns.

Parameters:
  • indict (dict) – Input dictionary to be expanded as a list of lists.

  • prefix (str or list) – A string or list of strings to expand columns on the left (that is, all rows will be added these prefixes to the left side).

  • delimiter (str) – The delimiter string.

Examples

>>> unfold_columns({
...     "key1": "val1",
...     "nested_key1": "nested value",
...     "nested_key2": "another value",
... })
[['key1', 'val1'],
['nested', 'key1', 'nested value'],
['nested', 'key2', 'another value']]

If nested keys do not share prefixes, they should not be unfolded.

>>> unfold_columns({
...     "key1": "val1",
...     "key1_split": "nonnested value",
...     "key2_singleton": "another value",
... })
[['key1', 'val1'],
['key1_split', 'nonnested value'],
['key2_singleton', 'another value']]

Nested/non-nested keys can be combined (see the behavior for key1):

>>> unfold_columns({
...     "key1": "val1",
...     "key1_split1": "nested value",
...     "key1_split2": "nested value",
...     "key2_singleton": "another value",
... })
[['key1', 'val1'],
['key1', 'split1', 'nested value'],
['key1', 'split2', 'nested value'],
['key2_singleton', 'another value']]
>>> unfold_columns({
...     "key1": "val1",
...     "nested_key1": "nested value",
...     "nested_key2": "another value",
... }, prefix="prefix")
[['prefix', 'key1', 'val1'],
['prefix', 'nested', 'key1', 'nested value'],
['prefix', 'nested', 'key2', 'another value']]
>>> unfold_columns({
...     "key1": "val1",
...     "nested_key1": "nested value",
...     "nested_key2": "another value",
... }, prefix=["name", "lastname"])
[['name', 'lastname', 'key1', 'val1'],
['name', 'lastname', 'nested', 'key1', 'nested value'],
['name', 'lastname', 'nested', 'key2', 'another value']]
>>> unfold_columns({
...     "key1": "val1",
...     "nested_key1_sub1": "val2",
...     "nested_key1_sub2": "val3",
...     "nested_key2": "another value",
... })
[['key1', 'val1'], ['nested', 'key2', 'another value'],
['nested', 'key1', 'sub1', 'val2'],
['nested', 'key1', 'sub2', 'val3']]