Skip to content
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

Quit after command-line parses env var #2694

Merged
merged 21 commits into from
Aug 25, 2023
Merged

Conversation

tclose
Copy link
Contributor

@tclose tclose commented Aug 11, 2023

This PR addresses #2679 by defining an environment variable ("MRTRIX_PARSE_ONLY"), which if set to "1", will cause all commands to terminate after successful completion of the command-line parsing with a "warning" stating that the CL args have been parsed successfully.

@Lestropie @jdtournier

@tclose tclose changed the title [WIP] Quit-after-usage Quit after command-line parses option Aug 13, 2023
@tclose tclose changed the title Quit after command-line parses option Quit after command-line parses env var Aug 13, 2023
@tclose
Copy link
Contributor Author

tclose commented Aug 20, 2023

@Lestropie @jdtournier this PR is ready for review if you have a moment

@tclose
Copy link
Contributor Author

tclose commented Aug 20, 2023

NB: Just rebased it onto dev instead of master

@Lestropie Lestropie changed the base branch from master to dev August 21, 2023 00:08
@Lestropie Lestropie self-requested a review August 21, 2023 00:09
Copy link
Member

@Lestropie Lestropie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched PR target branch to match rebasing to dev.

  1. Currently early exit does not apply when running in an R environment. I don't know the extent to which that is used beyond the original implementer... nevertheless, given the definition and claimed implementation of the environment variable, it should probably be doing the same thing there also.
  2. Not sure if "parse only" is adequately descriptive. In the context of CLI / workflow engine, sure, but in the context of the software as a whole, maybe something more verbose like "CLI parse only"? @jdtournier?

@tclose
Copy link
Contributor Author

tclose commented Aug 22, 2023

Switched PR target branch to match rebasing to dev.

  1. Currently early exit does not apply when running in an R environment. I don't know the extent to which that is used beyond the original implementer... nevertheless, given the definition and claimed implementation of the environment variable, it should probably be doing the same thing there also.
  2. Not sure if "parse only" is adequately descriptive. In the context of CLI / workflow engine, sure, but in the context of the software as a whole, maybe something more verbose like "CLI parse only"? @jdtournier?

Added support for Python commands that I had forgotten todo, renamed env var to MRTRIX_CLI_PARSE_ONLY. Which commands are R based?

@jdtournier
Copy link
Member

Currently early exit does not apply when running in an R environment. I don't know the extent to which that is used beyond the original implementer...

Not at all used as far as I know... I don't think the original implementer is even still working in the field! I've been meaning to remove support for R integration, it always felt like a bit of a hack. I'll work on that when I have a minute. But in the meantime, I really wouldn't worry a great deal about this!

@Lestropie
Copy link
Member

Which commands are R based?

All C++ commands; see parallel functions in core/command.h.

@tclose
Copy link
Contributor Author

tclose commented Aug 23, 2023

Which commands are R based?

All C++ commands; see parallel functions in core/command.h.

Ah, I misunderstood. You mean all mrtrix commands can be called from R, rather than R-based mrtrix commands. If it is an issue, we could just add a disclaimer that it won't work when calling from R, but it sounds like it will be dropped in any case.

Is it good to merge now? Did you request a change somewhere in the code @Lestropie? Because I can't see where that is if so

@Lestropie Lestropie self-requested a review August 25, 2023 03:01
core/command.h Outdated Show resolved Hide resolved
core/command.h Outdated Show resolved Hide resolved
lib/mrtrix3/app.py Outdated Show resolved Hide resolved
@Lestropie
Copy link
Member

Given the absence of interest in the R interface, perhaps just clarify very briefly in the description for the new environment variable that it only applies to the shell interface and not to R?

I've left a bunch of comments in the code, and you will need to resolve conflicts with latest dev; I'll take another look after that.

@tclose
Copy link
Contributor Author

tclose commented Aug 25, 2023

@Lestropie Ok, I have made those changes now so I believe it should be good to re-review. Note that there is a difference in behaviour in the message printing between the c++ and python, i.e. it shows up by default in python commands but only when the -info flag is passed to c++ commands, but this seems to be the case with other "info" messages as well.

(NB: I can't see the "1 change requested", do you know what that is referring to)

@Lestropie Lestropie self-requested a review August 25, 2023 05:55
@Lestropie
Copy link
Member

it shows up by default in python commands but only when the -info flag is passed to c++ commands, but this seems to be the case with other "info" messages as well.

Uh, I suggested calling function info() here rather than warn(), thinking it was an analogue to C++ INFO() macro, but function app.info() doesn't actually exist. So I'm honestly not sure what that is even calling...

My intention was for nothing to be printed to stderr unless -info was specified. I think that if the environment variable has been set, the command is being run in a setting where they don't need to read a user-friendly message to know that parsing completed successfully and the command is exiting prematurely. There's an argument to be made that perhaps this message should be CONSOLE() / app.console()-level in case a user somehow has this envvar set unexpectedly and needs to be notified of such. And that would also make it easier to get consistent behaviour between the two languages. I'm not feeling terribly strongly either way.

I can't see the "1 change requested", do you know what that is referring to

This comment was made as a review. It'll resolve once I re-review.

lib/mrtrix3/app.py Outdated Show resolved Hide resolved
core/command.h Outdated Show resolved Hide resolved
@tclose
Copy link
Contributor Author

tclose commented Aug 25, 2023

it shows up by default in python commands but only when the -info flag is passed to c++ commands, but this seems to be the case with other "info" messages as well.

Uh, I suggested calling function info() here rather than warn(), thinking it was an analogue to C++ INFO() macro, but function app.info() doesn't actually exist. So I'm honestly not sure what that is even calling...

My intention was for nothing to be printed to stderr unless -info was specified. I think that if the environment variable has been set, the command is being run in a setting where they don't need to read a user-friendly message to know that parsing completed successfully and the command is exiting prematurely.

Maybe the code could be refactored to use Python's std logger, which would give you the behaviour you are after, but that seems like a fair bit of work for not much gain.

There's an argument to be made that perhaps this message should be CONSOLE() / app.console()-level in case a user somehow has this envvar set unexpectedly and needs to be notified of such. And that would also make it easier to get consistent behaviour between the two languages. I'm not feeling terribly strongly either way.

This was my thinking with the warning, but in either case it probably isn't worth worrying about too much

I can't see the "1 change requested", do you know what that is referring to

This comment was made as a review. It'll resolve once I re-review.

tclose and others added 2 commits August 25, 2023 16:12
Co-authored-by: Robert Smith <robert.smith@florey.edu.au>
Co-authored-by: Robert Smith <robert.smith@florey.edu.au>
Copy link
Member

@Lestropie Lestropie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only thing that still catches my eye is that if the contents of the envvar can't be converted to bool, the exception won't be handled neatly in C++. But realistically it's not an issue, this is a feature purely for developers anyway. So should be good to go from here.

@Lestropie Lestropie merged commit d7fedca into MRtrix3:dev Aug 25, 2023
6 checks passed
@tclose tclose deleted the quit-after-usage branch August 28, 2023 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants