con / duct

A helper to run a command, capture stdout/stderr and details about running
MIT License
1 stars 1 forks source link

Add to _info.json a final record + use it to render report #64

Closed yarikoptic closed 1 week ago

yarikoptic commented 3 weeks ago

Pretty much a summary of what it took process to run. From that record/information is where from that final message duct outputs should be rendered via f-string formatting pretty much. I.e. for

Command: singularity run -B /mnt/DATA/data/yoh/1076_spacetop:/mnt/DATA/data/yoh/1076_spacetop:ro -B /mnt/DATA/data/yoh/1076_spacetop/derivatives:/mnt/DATA/data/yoh/1076_spacetop/derivatives:rw -B /mnt/DATA/data/yoh/1076_spacetop/scratch:/mnt/DATA/data/yoh/1076_spacetop/scratch:rw -B /mnt/DATA/data/yoh/1076_spacetop/../dsst-defacing-pipeline/src:/opt/dsst-defacing-pipeline:ro --scratch /mnt/DATA/data/yoh/1076_spacetop/scratch --pwd /mnt/DATA/data/yoh/1076_spacetop --net --network none ../dsst-defacing-pipeline/dsst-defacing-pipeline-0.0.5.sif -p 0001 -s 01 -- . derivatives/dss-defacing-0.0.5-1
Log files location: .duct/logs/2024.06.09T10.58.56-1623046_
Wall Clock Time: 2884.758 sec
Memory Peak Usage: 0.0%
CPU Peak Usage: 303.0%

Should be

fmt =f"""\
Exit code: {exit_code}
Command: {command}
Log files location: {logfile_prefix}
Wall Clock Time: {wall_clock} sec
Memory Peak Usage: {stats["memory_peak_perc"]}%
CPU Peak Usage: {stats["cpu_peak_perc"]}%
"""
print(fmt.format(final_record))

and we should add CLI option --report-format (`DUCT_REPORT_FORMAT) or alike so people could tune to their desires.

NB I know that exit code is not changing colors etc, but for that we might want to adopt/provide custom formatting similarly to how we do in pyout... later or add some ad-hoc for now exit_code_ansi_color and ansi_color_reset to use in the format as {exit_code_ansi_color}Exit code: {exit_code}{ansi_color_reset} but exclude them from record dumped to .json