From 319c464c17f521e25aabb36b487301e4ec0eeffe Mon Sep 17 00:00:00 2001 From: Tom Close Date: Thu, 10 Aug 2023 16:31:18 +1000 Subject: [PATCH 01/20] added some patterns to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 1e89810048..00819589e2 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,6 @@ testing/src/project_version.h .__tmp.log .check_syntax.tmp .check_syntax2.tmp +*.venv +__pycache__ +.DS_Store \ No newline at end of file From 2e024eec879a02ddbbdc8d7a5337dc80e3d2f443 Mon Sep 17 00:00:00 2001 From: Tom Close Date: Thu, 10 Aug 2023 16:42:48 +1000 Subject: [PATCH 02/20] added MRTRIX_PARSE_ONLY environment variable to change behaviour so that commands quit afte parsing the inputs (for use in CI) --- core/command.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/command.h b/core/command.h index be5681fe42..87947797ad 100644 --- a/core/command.h +++ b/core/command.h @@ -98,6 +98,14 @@ int main (int cmdline_argc, char** cmdline_argv) ::MR::GUI::App app (cmdline_argc, cmdline_argv); #endif ::MR::App::parse (); + + //ENVVAR name: MRTRIX_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 ones + int parse_only = getenv("MRTRIX_PARSE_ONLY") + if (parse_only) + return 0; run (); } catch (::MR::Exception& E) { From 329cd09e391268fc2a3243e50123c9aff96a3fc1 Mon Sep 17 00:00:00 2001 From: Tom Close Date: Fri, 11 Aug 2023 13:11:31 +1000 Subject: [PATCH 03/20] Added parse to int of PARSE_ONLY env var --- core/command.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/command.h b/core/command.h index 87947797ad..68f84d4f94 100644 --- a/core/command.h +++ b/core/command.h @@ -24,6 +24,7 @@ #include "app.h" #include "exec_version.h" +#include "mrtrix.h" #ifdef MRTRIX_PROJECT namespace MR { namespace App { @@ -103,7 +104,7 @@ int main (int cmdline_argc, char** cmdline_argv) //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 ones - int parse_only = getenv("MRTRIX_PARSE_ONLY") + int parse_only = MR::to(getenv("MRTRIX_PARSE_ONLY")); if (parse_only) return 0; run (); From f3ef857ef9ace870eebeb1cdbe60a6ca3a0183ac Mon Sep 17 00:00:00 2001 From: Tom Close Date: Mon, 14 Aug 2023 07:42:59 +1000 Subject: [PATCH 04/20] added MR namespace to internal method calls in logging macros to allow them to be called from the top-level namespace --- core/exception.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/exception.h b/core/exception.h index 2d474b1876..94292c1cff 100644 --- a/core/exception.h +++ b/core/exception.h @@ -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) From 8f78456c0d3e2104dd8bb7fced2b63b6f8685feb Mon Sep 17 00:00:00 2001 From: Tom Close Date: Mon, 14 Aug 2023 07:43:37 +1000 Subject: [PATCH 05/20] added warning message to indicate that command is quitting due to MRTRIX_PARSE_ONLY being set --- core/command.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/command.h b/core/command.h index 68f84d4f94..278377b9b8 100644 --- a/core/command.h +++ b/core/command.h @@ -106,6 +106,10 @@ int main (int cmdline_argc, char** cmdline_argv) //ENVVAR such as the automatically generated Pydra ones int parse_only = MR::to(getenv("MRTRIX_PARSE_ONLY")); if (parse_only) + WARN( + "Quitting after parsing command-line arguments for " + MR::str(cmdline_argv[0]) + + " successfully because environment variable 'MRTRIX_PARSE_ONLY' is set" + ); return 0; run (); } From 568e0de843c8772f876f17cbb01ac04b3c836e6e Mon Sep 17 00:00:00 2001 From: Tom Close Date: Mon, 14 Aug 2023 09:03:17 +1000 Subject: [PATCH 06/20] removed argv[0] from parse_only warning message --- core/command.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/command.h b/core/command.h index 278377b9b8..89df76c6b1 100644 --- a/core/command.h +++ b/core/command.h @@ -104,13 +104,13 @@ int main (int cmdline_argc, char** cmdline_argv) //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 ones - int parse_only = MR::to(getenv("MRTRIX_PARSE_ONLY")); - if (parse_only) + char* parse_only = std::getenv("MRTRIX_PARSE_ONLY"); + if (parse_only && ::MR::to(parse_only)) { WARN( - "Quitting after parsing command-line arguments for " + MR::str(cmdline_argv[0]) - + " successfully because environment variable 'MRTRIX_PARSE_ONLY' is set" + "Quitting after parsing command-line arguments successfully because environment variable 'MRTRIX_PARSE_ONLY' is set to '1'" ); return 0; + } run (); } catch (::MR::Exception& E) { From 79044b0a52dbf9f0f76c0eec05f88c8df0f81e01 Mon Sep 17 00:00:00 2001 From: Tom Close Date: Fri, 18 Aug 2023 20:59:37 +1000 Subject: [PATCH 07/20] added MRTRIX_PARSE_ONLY to list of environment variables --- core/command.h | 2 +- docs/reference/environment_variables.rst | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/command.h b/core/command.h index 89df76c6b1..27ce406fbf 100644 --- a/core/command.h +++ b/core/command.h @@ -103,7 +103,7 @@ int main (int cmdline_argc, char** cmdline_argv) //ENVVAR name: MRTRIX_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 ones + //ENVVAR such as the automatically generated Pydra interfaces char* parse_only = std::getenv("MRTRIX_PARSE_ONLY"); if (parse_only && ::MR::to(parse_only)) { WARN( diff --git a/docs/reference/environment_variables.rst b/docs/reference/environment_variables.rst index 29f968b6af..73224047ae 100644 --- a/docs/reference/environment_variables.rst +++ b/docs/reference/environment_variables.rst @@ -53,6 +53,12 @@ List of MRtrix3 environment variables :option:`NumberOfThreads` setting in the configuration file, but will be overridden by the ENVVAR ``-nthreads`` command-line option. +.. envvar:: MRTRIX_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_PRESERVE_PHILIPS_ISO Do not remove the synthetic isotropically-weighted diffusion From c033eb2462ac2206be96abd41f011d745a3f224c Mon Sep 17 00:00:00 2001 From: Tom Close Date: Tue, 22 Aug 2023 17:04:06 +1000 Subject: [PATCH 08/20] renamed MRTRIX_PARSE_ONLY to MRTRIX_CLI_PARSE_ONLY --- core/command.h | 6 +- docs/reference/environment_variables.rst | 2 +- .../fileformats/mrtrix3/_version.py | 4 + pydra/src/pydra/tasks/mrtrix3/_version.py | 4 + .../mrtrix3/v3_0/fivetissuetype2gmwmi.py | 161 ++++++++++++++++++ 5 files changed, 173 insertions(+), 4 deletions(-) create mode 100644 pydra/fileformats-mrtrix3/fileformats/mrtrix3/_version.py create mode 100644 pydra/src/pydra/tasks/mrtrix3/_version.py create mode 100644 pydra/src/pydra/tasks/mrtrix3/v3_0/fivetissuetype2gmwmi.py diff --git a/core/command.h b/core/command.h index 27ce406fbf..e9c8dc6ce9 100644 --- a/core/command.h +++ b/core/command.h @@ -100,14 +100,14 @@ int main (int cmdline_argc, char** cmdline_argv) #endif ::MR::App::parse (); - //ENVVAR name: MRTRIX_PARSE_ONLY + //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_PARSE_ONLY"); + char* parse_only = std::getenv("MRTRIX_CLI_PARSE_ONLY"); if (parse_only && ::MR::to(parse_only)) { WARN( - "Quitting after parsing command-line arguments successfully because environment variable 'MRTRIX_PARSE_ONLY' is set to '1'" + "Quitting after parsing command-line arguments successfully because environment variable 'MRTRIX_CLI_PARSE_ONLY' is set to '1'" ); return 0; } diff --git a/docs/reference/environment_variables.rst b/docs/reference/environment_variables.rst index 73224047ae..8827c5f2d9 100644 --- a/docs/reference/environment_variables.rst +++ b/docs/reference/environment_variables.rst @@ -53,7 +53,7 @@ List of MRtrix3 environment variables :option:`NumberOfThreads` setting in the configuration file, but will be overridden by the ENVVAR ``-nthreads`` command-line option. -.. envvar:: MRTRIX_PARSE_ONLY +.. 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, diff --git a/pydra/fileformats-mrtrix3/fileformats/mrtrix3/_version.py b/pydra/fileformats-mrtrix3/fileformats/mrtrix3/_version.py new file mode 100644 index 0000000000..55e5cfd50a --- /dev/null +++ b/pydra/fileformats-mrtrix3/fileformats/mrtrix3/_version.py @@ -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') diff --git a/pydra/src/pydra/tasks/mrtrix3/_version.py b/pydra/src/pydra/tasks/mrtrix3/_version.py new file mode 100644 index 0000000000..2f1900a260 --- /dev/null +++ b/pydra/src/pydra/tasks/mrtrix3/_version.py @@ -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') diff --git a/pydra/src/pydra/tasks/mrtrix3/v3_0/fivetissuetype2gmwmi.py b/pydra/src/pydra/tasks/mrtrix3/v3_0/fivetissuetype2gmwmi.py new file mode 100644 index 0000000000..e078818c3a --- /dev/null +++ b/pydra/src/pydra/tasks/mrtrix3/v3_0/fivetissuetype2gmwmi.py @@ -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 (robert.smith@florey.edu.au) + + 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 From 449c596438633cb665851c104dfcc343f23af401 Mon Sep 17 00:00:00 2001 From: Tom Close Date: Tue, 22 Aug 2023 17:04:23 +1000 Subject: [PATCH 09/20] implemented MRTRIX_CLI_PARSE_ONLY for python commands --- lib/mrtrix3/app.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/mrtrix3/app.py b/lib/mrtrix3/app.py index 5792207121..8ac8262e80 100644 --- a/lib/mrtrix3/app.py +++ b/lib/mrtrix3/app.py @@ -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: From d5f3dd8e140d43493f31304ba0c3bca0bb5caa4e Mon Sep 17 00:00:00 2001 From: Tom Close Date: Tue, 22 Aug 2023 17:43:15 +1000 Subject: [PATCH 10/20] reordered CLI_PARSE_ONLY env var in docs reference --- docs/reference/environment_variables.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/reference/environment_variables.rst b/docs/reference/environment_variables.rst index 8827c5f2d9..a294583e84 100644 --- a/docs/reference/environment_variables.rst +++ b/docs/reference/environment_variables.rst @@ -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 @@ -53,12 +59,6 @@ List of MRtrix3 environment variables :option:`NumberOfThreads` setting in the configuration file, but will be overridden by the ENVVAR ``-nthreads`` command-line option. -.. 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_PRESERVE_PHILIPS_ISO Do not remove the synthetic isotropically-weighted diffusion From c70cec728cbea62ea7c7a166c678fa9c314a85ab Mon Sep 17 00:00:00 2001 From: Tom Close Date: Fri, 25 Aug 2023 13:42:46 +1000 Subject: [PATCH 11/20] removed generated files from pydra branch --- .../fileformats/mrtrix3/_version.py | 4 - pydra/src/pydra/tasks/mrtrix3/_version.py | 4 - .../mrtrix3/v3_0/fivetissuetype2gmwmi.py | 161 ------------------ 3 files changed, 169 deletions(-) delete mode 100644 pydra/fileformats-mrtrix3/fileformats/mrtrix3/_version.py delete mode 100644 pydra/src/pydra/tasks/mrtrix3/_version.py delete mode 100644 pydra/src/pydra/tasks/mrtrix3/v3_0/fivetissuetype2gmwmi.py diff --git a/pydra/fileformats-mrtrix3/fileformats/mrtrix3/_version.py b/pydra/fileformats-mrtrix3/fileformats/mrtrix3/_version.py deleted file mode 100644 index 55e5cfd50a..0000000000 --- a/pydra/fileformats-mrtrix3/fileformats/mrtrix3/_version.py +++ /dev/null @@ -1,4 +0,0 @@ -# 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') diff --git a/pydra/src/pydra/tasks/mrtrix3/_version.py b/pydra/src/pydra/tasks/mrtrix3/_version.py deleted file mode 100644 index 2f1900a260..0000000000 --- a/pydra/src/pydra/tasks/mrtrix3/_version.py +++ /dev/null @@ -1,4 +0,0 @@ -# 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') diff --git a/pydra/src/pydra/tasks/mrtrix3/v3_0/fivetissuetype2gmwmi.py b/pydra/src/pydra/tasks/mrtrix3/v3_0/fivetissuetype2gmwmi.py deleted file mode 100644 index e078818c3a..0000000000 --- a/pydra/src/pydra/tasks/mrtrix3/v3_0/fivetissuetype2gmwmi.py +++ /dev/null @@ -1,161 +0,0 @@ -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 (robert.smith@florey.edu.au) - - 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 From fd2dfa4cbd4090392898e54f90d1f989c023beb9 Mon Sep 17 00:00:00 2001 From: Tom Close Date: Fri, 25 Aug 2023 13:44:15 +1000 Subject: [PATCH 12/20] WARN -> INFO for MRTRIX_CLI_PARSE_ONLY Co-authored-by: Robert Smith --- core/command.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/command.h b/core/command.h index e9c8dc6ce9..9c40ab7abe 100644 --- a/core/command.h +++ b/core/command.h @@ -106,8 +106,8 @@ int main (int cmdline_argc, char** cmdline_argv) //ENVVAR such as the automatically generated Pydra interfaces char* parse_only = std::getenv("MRTRIX_CLI_PARSE_ONLY"); if (parse_only && ::MR::to(parse_only)) { - WARN( - "Quitting after parsing command-line arguments successfully because environment variable 'MRTRIX_CLI_PARSE_ONLY' is set to '1'" + INFO( + "Quitting after parsing command-line arguments successfully due to environment variable 'MRTRIX_CLI_PARSE_ONLY'" ); return 0; } From c7d8f526ff160b1f3317edb164768fad39f493f2 Mon Sep 17 00:00:00 2001 From: Tom Close Date: Fri, 25 Aug 2023 13:45:16 +1000 Subject: [PATCH 13/20] relax value for MRTRIX_CLI_PARSE_ONLY to include yes/no in app.py Co-authored-by: Robert Smith --- lib/mrtrix3/app.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/mrtrix3/app.py b/lib/mrtrix3/app.py index 8ac8262e80..7fb5102044 100644 --- a/lib/mrtrix3/app.py +++ b/lib/mrtrix3/app.py @@ -193,12 +193,18 @@ def _execute(module): #pylint: disable=unused-variable 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'" - ) + 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): + info( + '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: From 486041ed73ca803a45d3914bd641a824439b7faf Mon Sep 17 00:00:00 2001 From: Tom Close Date: Fri, 25 Aug 2023 13:45:43 +1000 Subject: [PATCH 14/20] convert parse_only to bool from int Co-authored-by: Robert Smith --- core/command.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/command.h b/core/command.h index 9c40ab7abe..827d63f69e 100644 --- a/core/command.h +++ b/core/command.h @@ -105,7 +105,7 @@ int main (int cmdline_argc, char** cmdline_argv) //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(parse_only)) { + if (parse_only && ::MR::to(parse_only)) { INFO( "Quitting after parsing command-line arguments successfully due to environment variable 'MRTRIX_CLI_PARSE_ONLY'" ); From 1daa867f2605f49221896fd956514b843f4cf9e3 Mon Sep 17 00:00:00 2001 From: Tom Close Date: Fri, 25 Aug 2023 13:57:38 +1000 Subject: [PATCH 15/20] made reference to report_to_user_func from logging macros reference from root namespace --- core/exception.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/exception.h b/core/exception.h index ec9c5817e1..39a27ebadc 100644 --- a/core/exception.h +++ b/core/exception.h @@ -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) \ - MR::report_to_user_func(msg, -1) + ::MR::report_to_user_func(msg, -1) #define FAIL(msg) \ if (MR::App::log_level >= 0) \ - MR::report_to_user_func(msg, 0) + ::MR::report_to_user_func(msg, 0) #define WARN(msg) \ if (MR::App::log_level >= 1) \ - MR::report_to_user_func(msg, 1) + ::MR::report_to_user_func(msg, 1) #define INFO(msg) \ if (MR::App::log_level >= 2) \ - MR::report_to_user_func(msg, 2) + ::MR::report_to_user_func(msg, 2) #define DEBUG(msg) \ if (MR::App::log_level >= 3) \ - MR::report_to_user_func(msg, 3) + ::MR::report_to_user_func(msg, 3) class Exception { public: From 25fd0da8b54ec4b4ae55d609caa2e60dcd7535e4 Mon Sep 17 00:00:00 2001 From: Tom Close Date: Fri, 25 Aug 2023 14:01:33 +1000 Subject: [PATCH 16/20] fixed up syntax error and change info() to console() --- lib/mrtrix3/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mrtrix3/app.py b/lib/mrtrix3/app.py index 7fb5102044..41a2794b15 100644 --- a/lib/mrtrix3/app.py +++ b/lib/mrtrix3/app.py @@ -197,14 +197,14 @@ def _execute(module): #pylint: disable=unused-variable if cli_parse_only: try: if cli_parse_only.lower() in ['yes', 'true'] or int(cli_parse_only): - info( + 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') + '= "' + cli_parse_only + '; ignoring') sys.exit(return_code) try: From 349d27f67267916def7312154d20a4dc3da28cfa Mon Sep 17 00:00:00 2001 From: Tom Close Date: Fri, 25 Aug 2023 14:13:19 +1000 Subject: [PATCH 17/20] updated env var description to note that PARSE_ONLY doesn't work for R interfaces --- core/command.h | 5 +++-- docs/reference/environment_variables.rst | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/command.h b/core/command.h index 2e8d9f9fbb..cad28002b6 100644 --- a/core/command.h +++ b/core/command.h @@ -96,8 +96,9 @@ int main(int cmdline_argc, char **cmdline_argv) { //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 + //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(parse_only)) { INFO( diff --git a/docs/reference/environment_variables.rst b/docs/reference/environment_variables.rst index a294583e84..e98197a68c 100644 --- a/docs/reference/environment_variables.rst +++ b/docs/reference/environment_variables.rst @@ -27,8 +27,9 @@ List of MRtrix3 environment variables .. 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 + 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 From b05e55f3a3bcc02411d4f2320800c4cceab1cd7f Mon Sep 17 00:00:00 2001 From: Tom Close Date: Fri, 25 Aug 2023 14:23:03 +1000 Subject: [PATCH 18/20] clang formatted command.h --- core/command.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/core/command.h b/core/command.h index cad28002b6..39fd5b9f39 100644 --- a/core/command.h +++ b/core/command.h @@ -92,18 +92,17 @@ int main(int cmdline_argc, char **cmdline_argv) { #ifdef __gui_app_h__ ::MR::GUI::App app(cmdline_argc, cmdline_argv); #endif - ::MR::App::parse (); + ::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"); + // 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(parse_only)) { - INFO( - "Quitting after parsing command-line arguments successfully due to environment variable 'MRTRIX_CLI_PARSE_ONLY'" - ); + INFO("Quitting after parsing command-line arguments successfully due to environment variable " + "'MRTRIX_CLI_PARSE_ONLY'"); return 0; } run(); From 2afcc3ae3e6a6f547660f8e4e48270a51d315f8e Mon Sep 17 00:00:00 2001 From: Tom Close Date: Fri, 25 Aug 2023 16:12:46 +1000 Subject: [PATCH 19/20] Switch CLI_PARSE_ONLY message to CONSOLE Co-authored-by: Robert Smith --- core/command.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/command.h b/core/command.h index 39fd5b9f39..621df57acd 100644 --- a/core/command.h +++ b/core/command.h @@ -101,8 +101,8 @@ int main(int cmdline_argc, char **cmdline_argv) { // 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(parse_only)) { - INFO("Quitting after parsing command-line arguments successfully due to environment variable " - "'MRTRIX_CLI_PARSE_ONLY'"); + CONSOLE("Quitting after parsing command-line arguments successfully due to environment variable " + "'MRTRIX_CLI_PARSE_ONLY'"); return 0; } run(); From 93d17e24b7c012156d5c29262a96ac7cc6b65043 Mon Sep 17 00:00:00 2001 From: Tom Close Date: Fri, 25 Aug 2023 16:13:09 +1000 Subject: [PATCH 20/20] added in quote to cli_parse_only message Co-authored-by: Robert Smith --- lib/mrtrix3/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mrtrix3/app.py b/lib/mrtrix3/app.py index 41a2794b15..c80a413ad5 100644 --- a/lib/mrtrix3/app.py +++ b/lib/mrtrix3/app.py @@ -204,7 +204,7 @@ def _execute(module): #pylint: disable=unused-variable sys.exit(return_code) except ValueError: warn('Potentially corrupt environment variable "MRTRIX_CLI_PARSE_ONLY" ' - '= "' + cli_parse_only + '; ignoring') + '= "' + cli_parse_only + '"; ignoring') sys.exit(return_code) try: