Skip to content

Commit 93c36c7

Browse files
committed
First working version with DataDumper and CollectionDumper
Take it from here
1 parent f9d0978 commit 93c36c7

File tree

12 files changed

+1756
-103
lines changed

12 files changed

+1756
-103
lines changed

src/aiida/cmdline/commands/cmd_process.py

Lines changed: 76 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -558,42 +558,19 @@ def process_repair(manager, broker, dry_run):
558558
echo.echo_report(f'Revived process `{pid}`')
559559

560560

561-
@verdi_process.command('dump')
561+
@verdi_process.command("dump")
562562
@arguments.PROCESS()
563563
@options.PATH()
564564
@options.OVERWRITE()
565-
@click.option(
566-
'--include-inputs/--exclude-inputs',
567-
default=True,
568-
show_default=True,
569-
help='Include the linked input nodes of the `CalculationNode`(s).',
570-
)
571-
@click.option(
572-
'--include-outputs/--exclude-outputs',
573-
default=False,
574-
show_default=True,
575-
help='Include the linked output nodes of the `CalculationNode`(s).',
576-
)
577-
@click.option(
578-
'--include-attributes/--exclude-attributes',
579-
default=True,
580-
show_default=True,
581-
help='Include attributes in the `.aiida_node_metadata.yaml` written for every `ProcessNode`.',
582-
)
583-
@click.option(
584-
'--include-extras/--exclude-extras',
585-
default=True,
586-
show_default=True,
587-
help='Include extras in the `.aiida_node_metadata.yaml` written for every `ProcessNode`.',
588-
)
589-
@click.option(
590-
'-f',
591-
'--flat',
592-
is_flag=True,
593-
default=False,
594-
show_default=True,
595-
help='Dump files in a flat directory for every step of the workflow.',
596-
)
565+
@options.FLAT()
566+
@options.INCLUDE_INPUTS()
567+
@options.INCLUDE_OUTPUTS()
568+
@options.INCLUDE_ATTRIBUTES()
569+
@options.INCLUDE_EXTRAS()
570+
@options.ALSO_RAW()
571+
@options.ALSO_RICH()
572+
@options.RICH_SPEC()
573+
@options.RICH_DUMP_ALL()
597574
@click.option(
598575
'--dump-unsealed',
599576
is_flag=True,
@@ -602,17 +579,23 @@ def process_repair(manager, broker, dry_run):
602579
help='Also allow the dumping of unsealed process nodes.',
603580
)
604581
@options.INCREMENTAL()
582+
# TODO: Also add CONFIG_FILE option here
583+
# TODO: Currently, setting rich options is not supported here directly
605584
def process_dump(
606585
process,
607586
path,
608587
overwrite,
588+
flat,
609589
include_inputs,
610590
include_outputs,
611591
include_attributes,
612592
include_extras,
613-
flat,
614593
dump_unsealed,
615594
incremental,
595+
also_raw,
596+
also_rich,
597+
rich_spec,
598+
rich_dump_all,
616599
) -> None:
617600
"""Dump process input and output files to disk.
618601
@@ -630,29 +613,74 @@ def process_dump(
630613
node data for further inspection.
631614
"""
632615

633-
from aiida.tools.archive.exceptions import ExportValidationError
616+
from aiida.tools.dumping.data import DataDumper
634617
from aiida.tools.dumping.processes import ProcessDumper
618+
from aiida.tools.archive.exceptions import ExportValidationError
619+
620+
# from aiida.tools.dumping.utils import validate_rich_options
621+
from aiida.tools.dumping.rich import rich_from_cli
622+
623+
processdumper_kwargs = {
624+
"include_inputs": include_inputs,
625+
"include_outputs": include_outputs,
626+
"include_attributes": include_attributes,
627+
"include_extras": include_extras,
628+
"flat": flat,
629+
"dump_unsealed": dump_unsealed,
630+
"incremental": incremental,
631+
}
632+
633+
rich_kwargs = {
634+
"rich_dump_all": rich_dump_all,
635+
}
636+
637+
datadumper_kwargs = {
638+
"also_raw": also_raw,
639+
"also_rich": also_rich,
640+
}
641+
642+
# if also_rich:
643+
# try:
644+
# validate_rich_options(
645+
# rich_options=rich_options, rich_config_file=rich_config_file
646+
# )
647+
# except ValueError as exc:
648+
# echo.echo_critical(f"{exc!s}")
649+
650+
if rich_spec is not None:
651+
rich_spec_dict = rich_from_cli(rich_spec=rich_spec, **rich_kwargs)
652+
else:
653+
rich_spec_dict = {}
654+
655+
data_dumper = DataDumper(
656+
overwrite=overwrite,
657+
rich_spec_dict=rich_spec_dict,
658+
**datadumper_kwargs,
659+
**rich_kwargs,
660+
)
635661

636662
process_dumper = ProcessDumper(
637-
include_inputs=include_inputs,
638-
include_outputs=include_outputs,
639-
include_attributes=include_attributes,
640-
include_extras=include_extras,
641663
overwrite=overwrite,
642-
flat=flat,
643-
dump_unsealed=dump_unsealed,
644-
incremental=incremental,
664+
**processdumper_kwargs,
665+
**rich_kwargs,
666+
data_dumper=data_dumper,
645667
)
646668

647669
try:
648-
dump_path = process_dumper.dump(process_node=process, output_path=path)
670+
dump_path = process_dumper.dump(
671+
process_node=process,
672+
output_path=path,
673+
)
674+
echo.echo_success(
675+
f"Raw files for {process.__class__.__name__} <{process.pk}> dumped into folder `{dump_path}`."
676+
)
649677
except FileExistsError:
650678
echo.echo_critical(
651-
'Dumping directory exists and overwrite is False. Set overwrite to True, or delete directory manually.'
679+
"Dumping directory exists and overwrite is False. Set overwrite to True, or delete directory manually."
652680
)
653681
except ExportValidationError as e:
654-
echo.echo_critical(f'{e!s}')
682+
echo.echo_critical(f"{e!s}")
655683
except Exception as e:
656-
echo.echo_critical(f'Unexpected error while dumping {process.__class__.__name__} <{process.pk}>:\n ({e!s}).')
657-
658-
echo.echo_success(f'Raw files for {process.__class__.__name__} <{process.pk}> dumped into folder `{dump_path}`.')
684+
echo.echo_critical(
685+
f"Unexpected error while dumping {process.__class__.__name__} <{process.pk}>:\n ({e!s})."
686+
)

0 commit comments

Comments
 (0)