Skip to content

Commit

Permalink
STYLE: Use a dedicated function to parse script input arguments (#79)
Browse files Browse the repository at this point in the history
Use a dedicated function to parse script input arguments: improves
readaibility, and reduces the complexity of the `main` method.
  • Loading branch information
jhlegarreta authored Jan 13, 2025
1 parent 3db573d commit eb218f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 11 additions & 4 deletions scripts/tract_math
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import warnings
import os, sys
# sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

from tract_querier.tract_math import operations


def tract_math_operation(help_text, needs_one_tract=True):
'''
Expand All @@ -29,10 +31,7 @@ def tract_math_operation(help_text, needs_one_tract=True):
return internal_decorator


def main():
from tract_querier.tract_math import operations
from tract_querier.tract_math import TractMathWrongArgumentsError

def _build_arg_parser():
usage = r"""
usage: %(prog)s <tract1.vtk> ... <tractN.vtk> operation <operation parameter1> ... <operation parameterN> <output_tract.vtk> \
[ optional flags ]
Expand Down Expand Up @@ -84,7 +83,15 @@ def main():
parser.add_argument('operation_parameters', type=str, nargs=REMAINDER,
help="operation parameters")

return parser


def main():
from tract_querier.tract_math import TractMathWrongArgumentsError

parser = _build_arg_parser()
args = parser.parse_args()

# Load the global modules after the parsing of parameters
from tract_querier.tractography import tractography_from_files

Expand Down
8 changes: 7 additions & 1 deletion scripts/tract_querier
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def affine_transform_tract(affine_transform, tract):
return tract


def main():
def _build_arg_parser():

parser = OptionParser(
version=0.1,
usage="usage: %prog -t tractography_file -a atlas_file "
Expand Down Expand Up @@ -101,6 +102,11 @@ def main():
"to put both in AC-PC coordinate space"
)

return parser


def main():
parser = _build_arg_parser()
(options, args) = parser.parse_args()

if (
Expand Down

0 comments on commit eb218f5

Please sign in to comment.