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 10 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 @@ -24,6 +24,7 @@

#include "app.h"
#include "exec_version.h"
#include "mrtrix.h"
#ifdef MRTRIX_PROJECT
namespace MR {
namespace App {
Expand Down Expand Up @@ -98,6 +99,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 1. This can be used in the CI of wrapping code,
//ENVVAR such as the automatically generated Pydra interfaces
char* parse_only = std::getenv("MRTRIX_CLI_PARSE_ONLY");
if (parse_only && ::MR::to<int>(parse_only)) {
WARN(
"Quitting after parsing command-line arguments successfully because environment variable 'MRTRIX_CLI_PARSE_ONLY' is set to '1'"
);
return 0;
}
run ();
}
catch (::MR::Exception& E) {
Expand Down
10 changes: 5 additions & 5 deletions core/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ namespace MR
* debugging information; anything else: none. */
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)
#define FAIL(msg) if (MR::App::log_level >= 0) report_to_user_func (msg, 0)
#define WARN(msg) if (MR::App::log_level >= 1) report_to_user_func (msg, 1)
#define INFO(msg) if (MR::App::log_level >= 2) report_to_user_func (msg, 2)
#define DEBUG(msg) if (MR::App::log_level >= 3) report_to_user_func (msg, 3)
#define CONSOLE(msg) if (MR::App::log_level >= 1) MR::report_to_user_func (msg, -1)
#define FAIL(msg) if (MR::App::log_level >= 0) MR::report_to_user_func (msg, 0)
#define WARN(msg) if (MR::App::log_level >= 1) MR::report_to_user_func (msg, 1)
#define INFO(msg) if (MR::App::log_level >= 2) MR::report_to_user_func (msg, 2)
#define DEBUG(msg) if (MR::App::log_level >= 3) MR::report_to_user_func (msg, 3)



Expand Down
6 changes: 6 additions & 0 deletions docs/reference/environment_variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ 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 1. This can be used in the CI of wrapping code,
such as the automatically generated Pydra interfaces

.. envvar:: MRTRIX_CONFIGFILE

This can be used to set the location of the system-wide
Expand Down
9 changes: 9 additions & 0 deletions lib/mrtrix3/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ 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 == "1":
warn(
"Quitting after parsing command-line arguments successfully because "
"environment variable 'MRTRIX_CLI_PARSE_ONLY' is set to '1'"
)
sys.exit(return_code)

try:
module.execute()
except (run.MRtrixCmdError, run.MRtrixFnError) as exception:
Expand Down
4 changes: 4 additions & 0 deletions pydra/fileformats-mrtrix3/fileformats/mrtrix3/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# file generated by setuptools_scm
# don't change, don't track in version control
__version__ = version = '3.0.5.dev628+g49e520c06.d20230822'
__version_tuple__ = version_tuple = (3, 0, 5, 'dev628', 'g49e520c06.d20230822')
4 changes: 4 additions & 0 deletions pydra/src/pydra/tasks/mrtrix3/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# file generated by setuptools_scm
# don't change, don't track in version control
__version__ = version = '3.0.5.dev589+g9e2806609.d20230817'
__version_tuple__ = version_tuple = (3, 0, 5, 'dev589', 'g9e2806609.d20230817')
161 changes: 161 additions & 0 deletions pydra/src/pydra/tasks/mrtrix3/v3_0/fivetissuetype2gmwmi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import typing as ty
from pathlib import Path # noqa: F401
from fileformats.generic import File, Directory # noqa: F401
from fileformats.mrtrix3 import TrackFile # noqa: F401
from pydra import ShellCommandTask
from pydra.engine import specs
from pydra.tasks.mrtrix3.fileformats import ImageIn, ImageOut # noqa: F401


input_fields = [
# Arguments
(
"in_5tt",
ImageIn,
{
"argstr": "",
"position": 0,
"help_string": """the input 5TT segmented anatomical image""",
"mandatory": True,
},
),
(
"mask_out",
Path,
{
"argstr": "",
"position": 1,
"output_file_template": "mask_out.mif",
"help_string": """the output mask image""",
},
),
(
"mask_in",
ImageIn,
{
"argstr": "-mask_in",
"help_string": """Filter an input mask image according to those voxels that lie upon the grey matter - white matter boundary. If no input mask is provided, the output will be a whole-brain mask image calculated using the anatomical image only.""",
},
),
# Standard options
(
"info",
bool,
{
"argstr": "-info",
"help_string": """display information messages.""",
},
),
(
"quiet",
bool,
{
"argstr": "-quiet",
"help_string": """do not display information messages or progress status; alternatively, this can be achieved by setting the MRTRIX_QUIET environment variable to a non-empty string.""",
},
),
(
"debug",
bool,
{
"argstr": "-debug",
"help_string": """display debugging messages.""",
},
),
(
"force",
bool,
{
"argstr": "-force",
"help_string": """force overwrite of output files (caution: using the same file as input and output might cause unexpected behaviour).""",
},
),
(
"nthreads",
int,
{
"argstr": "-nthreads",
"help_string": """use this number of threads in multi-threaded applications (set to 0 to disable multi-threading).""",
},
),
(
"config",
specs.MultiInputObj[ty.Tuple[str, str]],
{
"argstr": "-config",
"help_string": """temporarily set the value of an MRtrix config file entry.""",
},
),
(
"help",
bool,
{
"argstr": "-help",
"help_string": """display this information page and exit.""",
},
),
(
"version",
bool,
{
"argstr": "-version",
"help_string": """display version information and exit.""",
},
),
]

fivetissuetype2gmwmi_input_spec = specs.SpecInfo(
name="Input", fields=input_fields, bases=(specs.ShellSpec,)
)


output_fields = [
(
"mask_out",
ImageOut,
{
"help_string": """the output mask image""",
},
),
]
fivetissuetype2gmwmi_output_spec = specs.SpecInfo(
name="Output", fields=output_fields, bases=(specs.ShellOutSpec,)
)


class fivetissuetype2gmwmi(ShellCommandTask):
"""
References
----------

Smith, R. E.; Tournier, J.-D.; Calamante, F. & Connelly, A. Anatomically-constrained tractography:Improved diffusion MRI streamlines tractography through effective use of anatomical information. NeuroImage, 2012, 62, 1924-1938

Tournier, J.-D.; Smith, R. E.; Raffelt, D.; Tabbara, R.; Dhollander, T.; Pietsch, M.; Christiaens, D.; Jeurissen, B.; Yeh, C.-H. & Connelly, A. MRtrix3: A fast, flexible and open software framework for medical image processing and visualisation. NeuroImage, 2019, 202, 116137


MRtrix
------

Version:3.0.4-624-g4fb87551-dirty, built Aug 21 2023

Author: Robert E. Smith ([email protected])

Copyright: Copyright (c) 2008-2023 the MRtrix3 contributors.

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

Covered Software is provided under this License on an "as is"
basis, without warranty of any kind, either expressed, implied, or
statutory, including, without limitation, warranties that the
Covered Software is free of defects, merchantable, fit for a
particular purpose or non-infringing.
See the Mozilla Public License v. 2.0 for more details.

For more details, see http://www.mrtrix.org/.
"""

executable = "fivetissuetype2gmwmi"
input_spec = fivetissuetype2gmwmi_input_spec
output_spec = fivetissuetype2gmwmi_output_spec