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

Permit calling cwltool.main with preparsed args only even with provenance #1964

Merged
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
6 changes: 2 additions & 4 deletions cwltool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,8 @@ def formatTime(self, record: logging.LogRecord, datefmt: Optional[str] = None) -

def setup_provenance(
args: argparse.Namespace,
argsl: List[str],
runtimeContext: RuntimeContext,
argsl: Optional[List[str]] = None,
) -> Tuple[ProvOut, "logging.StreamHandler[ProvOut]"]:
if not args.compute_checksum:
_logger.error("--provenance incompatible with --no-compute-checksum")
Expand Down Expand Up @@ -1049,10 +1049,8 @@ def main(

prov_log_stream: Optional[Union[io.TextIOWrapper, WritableBagFile]] = None
if args.provenance:
if argsl is None:
raise Exception("argsl cannot be None")
try:
prov_log_stream, prov_log_handler = setup_provenance(args, argsl, runtimeContext)
prov_log_stream, prov_log_handler = setup_provenance(args, runtimeContext, argsl)
except ArgumentException:
return 1

Expand Down
40 changes: 40 additions & 0 deletions tests/test_main_parsed_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import io
from pathlib import Path

from cwltool.argparser import arg_parser
from cwltool.main import main

from .util import get_data


def test_main_parsed_args(tmp_path: Path) -> None:
"""Affirm that main can be called with parsed args only."""
stdout = io.StringIO()
stderr = io.StringIO()

unparsed_args = [get_data("tests/echo.cwl"), "--inp", "Hello"]
parsed_args = arg_parser().parse_args(unparsed_args)

try:
assert main(args=parsed_args, stdout=stdout, stderr=stderr) == 0
except SystemExit as err:
assert err.code == 0


def test_main_parsed_args_provenance(tmp_path: Path) -> None:
"""Affirm that main can be called with parsed args only, requesting provenance."""
stdout = io.StringIO()
stderr = io.StringIO()

prov_folder = tmp_path / "provenance" # will be created if necessary

unparsed_args = ["--provenance", str(prov_folder), get_data("tests/echo.cwl"), "--inp", "Hello"]
parsed_args = arg_parser().parse_args(unparsed_args)

try:
assert main(args=parsed_args, stdout=stdout, stderr=stderr) == 0
except SystemExit as err:
assert err.code == 0

manifest_file = prov_folder / "metadata" / "manifest.json"
assert manifest_file.is_file(), f"Can't find RO-Crate manifest {manifest_file}"
Loading