Source code for shapepipe.pipeline.args


This module defines methods for handling the pipeline arguments.

:Author: Samuel Farrens <>


import argparse as ap

from import __version__, shapepipe_logo
from shapepipe.modules import __module_list__

[docs]class cutomFormatter( ap.ArgumentDefaultsHelpFormatter, ap.RawDescriptionHelpFormatter, ): """Custom Formatter. This class combines the argparse ``ArgumentDefaultsHelpFormatter`` and ``RawDescriptionHelpFormatter`` formatters. """ pass
[docs]def module_str(): """Format Module String. Format the list of modules as a single string. Returns ------- str Formatted string of module names """ string = '' for module in __module_list__: string += f' - {module}\n' return string
[docs]def create_arg_parser(): """Create Argument Parser. This method returns an argument parser. Returns ------- argparse.Namespace Argument parser """ # Create parser parser = ap.ArgumentParser( add_help=False, description=shapepipe_logo(), formatter_class=cutomFormatter, ) optional = parser.add_argument_group('Optional Arguments') # Add arguments optional.add_argument( '-h', '--help', action='help', help='show this help message and exit', ) optional.add_argument( '-v', '--version', action='version', version=f'%(prog)s v{__version__}' ) optional.add_argument( '-l', '--list_modules', action=print_message( f'ShapePipe modules currently available:\n{module_str()}' ), help='list modules currently available and exit', ) optional.add_argument( '-c', '--config', default='config.ini', help='configuration file name', ) # Return parser return parser.parse_args()