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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
319c464
added some patterns to gitignore
tclose Aug 10, 2023
2e024ee
added MRTRIX_PARSE_ONLY environment variable to change behaviour so t…
tclose Aug 10, 2023
329cd09
Added parse to int of PARSE_ONLY env var
tclose Aug 11, 2023
f3ef857
added MR namespace to internal method calls in logging macros
tclose Aug 13, 2023
8f78456
added warning message to indicate that command is
tclose Aug 13, 2023
568e0de
removed argv[0] from parse_only warning message
tclose Aug 13, 2023
79044b0
added MRTRIX_PARSE_ONLY to list of environment variables
tclose Aug 18, 2023
c033eb2
renamed MRTRIX_PARSE_ONLY to MRTRIX_CLI_PARSE_ONLY
tclose Aug 22, 2023
449c596
implemented MRTRIX_CLI_PARSE_ONLY for python commands
tclose Aug 22, 2023
d5f3dd8
reordered CLI_PARSE_ONLY env var in docs reference
tclose Aug 22, 2023
c70cec7
removed generated files from pydra branch
tclose Aug 25, 2023
fd2dfa4
WARN -> INFO for MRTRIX_CLI_PARSE_ONLY
tclose Aug 25, 2023
c7d8f52
relax value for MRTRIX_CLI_PARSE_ONLY to include yes/no in app.py
tclose Aug 25, 2023
486041e
convert parse_only to bool from int
tclose Aug 25, 2023
6ec824d
Merge branch 'dev' into quit-after-usage
tclose Aug 25, 2023
1daa867
made reference to report_to_user_func from logging macros reference f…
tclose Aug 25, 2023
25fd0da
fixed up syntax error and change info() to console()
tclose Aug 25, 2023
349d27f
updated env var description to note that PARSE_ONLY doesn't work for …
tclose Aug 25, 2023
b05e55f
clang formatted command.h
tclose Aug 25, 2023
2afcc3a
Switch CLI_PARSE_ONLY message to CONSOLE
tclose Aug 25, 2023
93d17e2
added in quote to cli_parse_only message
tclose Aug 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ testing/src/project_version.h
.__tmp.log
.check_syntax.tmp
.check_syntax2.tmp
*.venv
__pycache__
.DS_Store
13 changes: 13 additions & 0 deletions core/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "app.h"
#include "exec_version.h"
#include "mrtrix.h"
#ifdef MRTRIX_PROJECT
namespace MR {
namespace App {
Expand Down Expand Up @@ -92,6 +93,18 @@ int main(int cmdline_argc, char **cmdline_argv) {
::MR::GUI::App app(cmdline_argc, cmdline_argv);
#endif
::MR::App::parse();

// ENVVAR name: MRTRIX_CLI_PARSE_ONLY
// ENVVAR Set the command to parse the provided inputs and then quit
// ENVVAR if it is set. This can be used in the CI of wrapping code,
// ENVVAR such as the automatically generated Pydra interfaces.
// ENVVAR Note that it will have no effect for R interfaces
char *parse_only = std::getenv("MRTRIX_CLI_PARSE_ONLY");
if (parse_only && ::MR::to<bool>(parse_only)) {
CONSOLE("Quitting after parsing command-line arguments successfully due to environment variable "
"'MRTRIX_CLI_PARSE_ONLY'");
return 0;
}
run();
} catch (::MR::Exception &E) {
E.display();
Expand Down
10 changes: 5 additions & 5 deletions core/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ extern void (*report_to_user_func)(const std::string &msg, int type);

#define CONSOLE(msg) \
if (MR::App::log_level >= 1) \
report_to_user_func(msg, -1)
::MR::report_to_user_func(msg, -1)
#define FAIL(msg) \
if (MR::App::log_level >= 0) \
report_to_user_func(msg, 0)
::MR::report_to_user_func(msg, 0)
#define WARN(msg) \
if (MR::App::log_level >= 1) \
report_to_user_func(msg, 1)
::MR::report_to_user_func(msg, 1)
#define INFO(msg) \
if (MR::App::log_level >= 2) \
report_to_user_func(msg, 2)
::MR::report_to_user_func(msg, 2)
#define DEBUG(msg) \
if (MR::App::log_level >= 3) \
report_to_user_func(msg, 3)
::MR::report_to_user_func(msg, 3)

class Exception {
public:
Expand Down
7 changes: 7 additions & 0 deletions docs/reference/environment_variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ List of MRtrix3 environment variables
when reading DICOM data, match the StudyName entry against
the string provided

.. envvar:: MRTRIX_CLI_PARSE_ONLY

Set the command to parse the provided inputs and then quit
if it is set. This can be used in the CI of wrapping code,
such as the automatically generated Pydra interfaces.
Note that it will have no effect for R interfaces

.. envvar:: MRTRIX_CONFIGFILE

This can be used to set the location of the system-wide
Expand Down
15 changes: 15 additions & 0 deletions lib/mrtrix3/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ def _execute(module): #pylint: disable=unused-variable
CMDLINE.print_citation_warning()

return_code = 0

cli_parse_only = os.getenv('MRTRIX_CLI_PARSE_ONLY')
if cli_parse_only:
try:
if cli_parse_only.lower() in ['yes', 'true'] or int(cli_parse_only):
console(
'Quitting after parsing command-line arguments successfully due to '
'environment variable "MRTRIX_CLI_PARSE_ONLY"'
)
sys.exit(return_code)
except ValueError:
warn('Potentially corrupt environment variable "MRTRIX_CLI_PARSE_ONLY" '
'= "' + cli_parse_only + '"; ignoring')
sys.exit(return_code)

try:
module.execute()
except (run.MRtrixCmdError, run.MRtrixFnError) as exception:
Expand Down