Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion src/toil/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ def parser_with_common_options(
def addOptions(
parser: ArgumentParser,
jobstore_as_flag: bool = False,
config_option: Optional[str] = None,
cwl: bool = False,
wdl: bool = False,
) -> None:
Expand All @@ -748,11 +749,15 @@ def addOptions(

Support for config files if using configargparse. This will also check and set up the default config file.

User code should consider using Job.Runner.getDefaultArgumentParser() or Job.Runner.addToilOptions() instead.

:param jobstore_as_flag: make the job store option a --jobStore flag instead of a required jobStore positional argument.

:param cwl: Whether CWL options are expected. If so, CWL options won't be suppressed.

:param wdl: Whether WDL options are expected. If so, WDL options won't be suppressed.

:param config_option: If set, use this string for the Toil --config option instead of "config".
"""
if cwl and wdl:
raise RuntimeError(
Expand Down Expand Up @@ -801,7 +806,7 @@ def addOptions(
raise

# Add base toil options
add_base_toil_options(parser, jobstore_as_flag, cwl)
add_base_toil_options(parser, jobstore_as_flag, cwl, config_option)
# Add CWL and WDL options
# This is done so the config file can hold all available options
add_cwl_options(parser, suppress=not cwl)
Expand Down
22 changes: 18 additions & 4 deletions src/toil/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -2485,14 +2485,18 @@ class Runner:
"""Used to setup and run Toil workflow."""

@staticmethod
def getDefaultArgumentParser(jobstore_as_flag: bool = False) -> ArgParser:
def getDefaultArgumentParser(
jobstore_as_flag: bool = False,
config_option: Optional[str] = None,
) -> ArgParser:
"""
Get argument parser with added toil workflow options.

This is the Right Way to get an argument parser in a Toil Python
workflow.

:param jobstore_as_flag: make the job store option a --jobStore flag instead of a required jobStore positional argument.
:param config_option: If set, use this string for the Toil --config option instead of "config".
:returns: The argument parser used by a toil workflow with added Toil options.
"""
parser = ArgParser(formatter_class=ArgumentDefaultsHelpFormatter)
Expand All @@ -2501,14 +2505,17 @@ def getDefaultArgumentParser(jobstore_as_flag: bool = False) -> ArgParser:

@staticmethod
def getDefaultOptions(
jobStore: Optional[StrPath] = None, jobstore_as_flag: bool = False
jobStore: Optional[StrPath] = None,
jobstore_as_flag: bool = False,
config_option: Optional[str] = None,
) -> Namespace:
"""
Get default options for a toil workflow.

:param jobStore: A string describing the jobStore \
for the workflow.
:param jobstore_as_flag: make the job store option a --jobStore flag instead of a required jobStore positional argument.
:param config_option: If set, use this string for the Toil --config option instead of "config".
:returns: The options used by a toil workflow.
"""
# setting jobstore_as_flag to True allows the user to declare the jobstore in the config file instead
Expand All @@ -2518,7 +2525,8 @@ def getDefaultOptions(
"to False!"
)
parser = Job.Runner.getDefaultArgumentParser(
jobstore_as_flag=jobstore_as_flag
jobstore_as_flag=jobstore_as_flag,
config_option=config_option,
)
arguments = []
if jobstore_as_flag and jobStore is not None:
Expand All @@ -2531,6 +2539,7 @@ def getDefaultOptions(
def addToilOptions(
parser: Union["OptionParser", ArgumentParser],
jobstore_as_flag: bool = False,
config_option: Optional[str] = None,
) -> None:
"""
Adds the default toil options to an :mod:`optparse` or :mod:`argparse`
Expand All @@ -2545,8 +2554,13 @@ def addToilOptions(

:param parser: Options object to add toil options to.
:param jobstore_as_flag: make the job store option a --jobStore flag instead of a required jobStore positional argument.
:param config_option: If set, use this string for the Toil --config option instead of "config".
"""
addOptions(parser, jobstore_as_flag=jobstore_as_flag)
addOptions(
parser,
jobstore_as_flag=jobstore_as_flag,
config_option=config_option,
)

@staticmethod
def startToil(job: "Job", options) -> Any:
Expand Down
7 changes: 4 additions & 3 deletions src/toil/options/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,14 @@ def parse_jobstore(jobstore_uri: str) -> str:


def add_base_toil_options(
parser: ArgumentParser, jobstore_as_flag: bool = False, cwl: bool = False
parser: ArgumentParser, jobstore_as_flag: bool = False, cwl: bool = False, config_option: Optional[str] = None
) -> None:
"""
Add base Toil command line options to the parser.
:param parser: Argument parser to add options to
:param jobstore_as_flag: make the job store option a --jobStore flag instead of a required jobStore positional argument.
:param cwl: whether CWL should be included or not
:param config_option: If set, use this string for the Toil --config option instead of "config".
"""

# This is necessary as the config file must have at least one valid key to parse properly and we want to use a
Expand All @@ -215,8 +216,8 @@ def add_base_toil_options(
# If using argparse instead of configargparse, this should just not parse when calling parse_args()
# default config value is set to none as defaults should already be populated at config init
config.add_argument(
"--config",
dest="config",
f"--{config_option or 'config'}",
dest="_toil_config_file",
is_config_file_arg=True,
default=None,
metavar="PATH",
Expand Down