con / duct

A helper to run a command, capture stdout/stderr and details about running
https://pypi.org/project/con-duct/
MIT License
3 stars 2 forks source link

Add custom formatter conversion flags and colors based on datalad ls #183

Closed yarikoptic closed 1 month ago

yarikoptic commented 2 months ago

In principle works, here is current outputs

❯ duct sleep 2
2024-09-20T10:16:52-0400 [INFO    ] con-duct: duct is executing 'sleep 2'...
2024-09-20T10:16:52-0400 [INFO    ] con-duct: Log files will be written to .duct/logs/2024.09.20T10.16.52-182670_
2024-09-20T10:16:54-0400 [INFO    ] con-duct: Summary:
Exit Code: 0
Command: sleep 2
Log files location: .duct/logs/2024.09.20T10.16.52-182670_
Wall Clock Time: 2.001 sec
Memory Peak Usage (RSS): 2.0 MB
Memory Average Usage (RSS): 2.0 MB
Virtual Memory Peak Usage (VSZ): 5.7 MB
Virtual Memory Average Usage (VSZ): 5.7 MB
Memory Peak Percentage: 0.0%
Memory Average Percentage: 0.0%
CPU Peak Usage: 0.0%
Average CPU Usage: 0.0%
Samples Collected: 3
Reports Written: 2

❯ duct echo 1
2024-09-20T10:16:58-0400 [INFO    ] con-duct: duct is executing 'echo 1'...
2024-09-20T10:16:58-0400 [INFO    ] con-duct: Log files will be written to .duct/logs/2024.09.20T10.16.58-182729_
1
2024-09-20T10:16:58-0400 [INFO    ] con-duct: Summary:
Exit Code: 0
Command: echo 1
Log files location: .duct/logs/2024.09.20T10.16.58-182729_
Wall Clock Time: 0.001 sec
Memory Peak Usage (RSS): -
Memory Average Usage (RSS): -
Virtual Memory Peak Usage (VSZ): -
Virtual Memory Average Usage (VSZ): -
Memory Peak Percentage: ✗%
Memory Average Percentage: ✗%
CPU Peak Usage: ✗%
Average CPU Usage: ✗%
Samples Collected: 0
Reports Written: 1

[EDIT asmacdo] I've made some tweaks to how the individual conversion flags work. The biggest user-interface difference is that I've made colors off by default.

duct --colors sleep 2

image

duct --colors echo 1

image

duct --colors false

image

And of course the user can specify --summary-format and use the custom conversion flags (documented in --help)

duct --colors --summary-format "JUST EXIT CODE: {exit_code\!E}" false

image

duct --summary-format "                              
exit: {exit_code\!E}
walltime: {wall_clock_time:.3f}" sleep 1.1111111111

image

asmacdo commented 2 months ago

When we dont get measurements, use red.

duct -p Z_ --s-i 0.1 --r-i 1 --clobber ls

image

When we do get measurements, use green

duct -p Z_ --s-i 0.1 --r-i 1 --clobber sleep 1

image

asmacdo commented 2 months ago

Next up, need to add lots of tests.

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.49%. Comparing base (7f5a3ae) to head (58a1ff1). Report is 42 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #183 +/- ## ========================================== + Coverage 94.97% 95.49% +0.51% ========================================== Files 2 2 Lines 478 533 +55 Branches 73 84 +11 ========================================== + Hits 454 509 +55 Misses 12 12 Partials 12 12 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

asmacdo commented 1 month ago

@yarikoptic If the user provides an invalid value, we shouldnt be returning a tb to them, so I added [No user-facing tb even with invalid summary-format](https://github.com/con/duct/pull/183/commits/264ae8b7d57ee4f9da6ddef28edf5a8cb98e2927)

yarikoptic commented 1 month ago

@yarikoptic If the user provides an invalid value, we shouldnt be returning a tb to them

why?

yarikoptic commented 1 month ago

Let's proceed. thank you @asmacdo !