New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce logging from intermediate CLI scripts by setting -v 0
in main()
calls
#3881
Conversation
0f26168
to
c882a73
Compare
This is a precursor for adding the `verbose` parameter from the `main` context.
This is a precursor for adding the `verbose` parameter from the `main` context.
I've left the `testing/` calls to `main()` alone.
c882a73
to
ab01d6a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this large undertaking!
Could you also make verbose
a non-optional argument of display_viewer_syntax()
while you're at it? (That is, removing the default value in the function signature?) That would be a kind of automated test to make sure we don't introduce verbose-less calls in the future.
I agree that fixing printv
verbosity is an even larger undertaking, and doesn't need to happen in this PR, which is a well-scoped improvement.
Good call! This caught one instance of a verbose-less call in |
Ah! It looks like it did more than just catch 1 verbose-less call:
Sorry about that! I was sure I had run Either way, I'll take a closer look at the |
Just as one last sanity check here, I was hoping to compare the output of The trouble is, there are no image viewers (e.g. Still, we can at least use this diff to see the effect that this PR has on non-
This is an acceptable (perhaps even welcome) change to me. The intermediate logging from I'm also pleased to see that the changes from this PR have a (relatively) insignificant effect on CLI script logging, meaning that users aren't going to see wildly reduced output from their scripts. Things will be more or less business as usual, sans the (unwanted) |
If the above looks good to you, @mguaypaq, feel free to merge! |
Description
Context
In many places in SCT's codebase, a CLI script (e.g.
sct_label_vertebrae
) will call another CLI script (e.g.sct_straighten_spinalcord
).Historically, the secondary CLI script will be called using a subprocess (via the
run_proc
function). Over the past year, however, SCT has migrated from usingrun_proc("sct_script")
toimport sct_script; sct_script.main()
.Problem
While there have been benefits to this change, one unintended outcome of this change has been an increase in logging:
run_proc
is quiet; it prints only the command that was run, but outputs nothing else by default.sct_script.main()
is noisy; it outputs everything exactly as it would if the CLI script was run from the terminal.As a result, the logs for a CLI script now include additional nested logs for any intermediate CLI scripts called, too.
This problem is partially highlighted in #3877, but beyond
display_viewer_syntax
, anyprintv
commands will be included in the output, too.Solution
To fix this problem, this PR:
-v 0
is set for every intermediatesct_script.main()
call.display_viewer_syntax()
calls, too.Caveats
The main caveat with setting
-v 0
for intermediate calls is that SCT is not consistent with how it propagatesarguments.v
(i.e.verbose
) toprintv
.There are 272 instances of
printv
with verbose:Compared to 215 instances of
printv
without verbose:Meaning that
-v 0
will silence some, but not all output from intermediate scripts.For this reason, it might be better to leave
-v
andprintv
alone, temporarily accept the increasedprintv
output, and instead focus solely ondisplay_viewer_syntax
, as per #3877 (comment).Linked issues
Fixes #3877.