Repository navigation
feat(api): Workflow.check(), and a when that cannot give a boolean - #585
Conversation
c66089c to
4c7f029
Compare
89fda55 to
a96cf4a
Compare
342d0fa to
ff4d0c4
Compare
darkclad
left a comment
There was a problem hiding this comment.
Reviewed this PR's own commits (50834366..ff4d0c4c, on top of #584 at f3bab3d4). I also ran tests/core on head and on base. The RunPolicy plumbing, the shared boolean_problem check, and moving the partial-failure refusal ahead of the other findings all look right. I have one substantive comment, about check() missing the undeclared-input when warning, plus two smaller ones inline.
| result = compile_workflow_result(workflow, tool_registry=options.tool_registry, inference=options.inference) | ||
| report(result.diagnostics) | ||
| result = compile_workflow_result(workflow, tool_registry=options.tool_registry, inference=options.inference, | ||
| policy=options.policy, lang_version=options.lang_version, quiet=check) |
There was a problem hiding this comment.
quiet=check makes check() drop the one when problem it exists to catch. compile_source now gates _when_notes on quiet, and that warning is a printed line, not a Diagnostic, so check() neither returns nor prints it. Your own _warned_on_cwl test shows this: step 3's when: $(inputs.nope) shows up only in compile()'s stderr, and check() returns [wic043, wic056] with nothing for it. non_boolean_whens doesn't catch it either, because the subset can't type an unbound read, so boolean_problem returns None.
That when evaluates to null, which the new scatter-and-conditions.md text says "stops the run too". So check() comes back clean for a workflow that cwltool will stop at that step, while the docstring says it returns every note compile() would show. Could the undeclared-input case become a Diagnostic (a wic056 note, or its own code) so check() returns it? Keeping it a plain line that only a non-quiet compile prints means the Python check can't see it.
There was a problem hiding this comment.
You're right: check() missed the one when problem it exists to catch. I made the undeclared-input when a wic056 note in the compile's diagnostics instead of a printed line. It no longer depends on quiet. check() returns it, and compile() and the CLI print it through the normal diagnostics report. It is raised on both targets, since a null when is a problem for both. The tests now assert that check() returns the inputs.nope note and that a check() followed by a compile() show the same notes.
Fixed in 5bd03ef.
| try: | ||
| bundle = frontdoor.bundle_from_source(source, f'{Path(declaration.analysis).stem}_only', yml_paths, tools) | ||
| result = compiler.compile_source(bundle, compiler_options, testing=True) | ||
| result = compiler.compile_source(bundle, compiler_options, quiet=True) |
There was a problem hiding this comment.
Before this PR, testing=True here only hid the start and finish lines. quiet=True now also hides _authored_spelling_notes and _when_notes for every real-time analysis compile. So sophios --yaml ... --run_local no longer warns about a duplicate-id outputSource or an undeclared-input when inside an analysis .wic, while the same document compiled on its own still gets the warning. If that's intended, it's worth a line in the PR's "What changes for callers". If not, this call site might want to keep the old split between hiding progress lines and hiding warnings.
There was a problem hiding this comment.
Agreed on the narrowing. quiet=True here now hides the authored-spelling line (duplicate-id outputSource) for analysis compiles, and I'm leaving that as it is. The when problem is no longer part of it, because it is now a diagnostic rather than a printed line. But the analysis compile discards its diagnostics, so that note is still not shown for an analysis .wic. The PR's "What changes for callers" should say so, and I'll add the line there.
| with pytest.raises(SophiosError) as error: | ||
| workflow.check(target=target) | ||
| problem, = error.value.diagnostics | ||
| assert str(problem.code) == "wic016" and f"'{tmp_path / 'absent.txt'}', which does not exist" in problem.message |
There was a problem hiding this comment.
Nit: this fails on Windows, in both parametrizations. The wic016 message formats the path with !r, so backslashes come out doubled ('C:\\Users\\...'), and f"'{tmp_path / 'absent.txt'}'" never matches. CI's Windows lane only runs test_compile_python_workflows from this file, so CI won't catch it. Matching on {str(tmp_path / 'absent.txt')!r} would work on every OS. These two are the only failures in tests/core that are new against #584's head on my Windows box. The other 123 failures there are environmental and fail on the base too.
There was a problem hiding this comment.
Fixed. The test now matches str(path)!r, so the doubled backslashes on Windows match. I couldn't run it on Windows here, so that part is unverified.
Fixed in 1e01d2b.
It only leaves out the lines that say a compile started and finished, so the flag says that rather than who passes it.
One check over the resolved view finds a when the subset types as a number, a string or null, or one that is not one expression. The CWL target notes it as wic056, and the Nextflow target refuses it.
Workflow.check(target=...) is the Python form of --check: it compiles, lowers for the target and runs run()'s pre-flight on this machine, writes nothing, and returns every note. What the machine lacks raises SophiosError, as run() does.
The tools the view carries are written for the policy, so what the target would refuse in them is the policy's, not their author's.
policy=RunPolicy(...) on compile, run, start, run_async and check writes the CWL the partial-failure flags write for the .wic twin. The Nextflow target refuses the policy alone.
ff4d0c4 to
2700177
Compare
An undeclared input read in a when was a plain line only a printing compile showed, so check() came back clean for a run cwltool stops. It is now a wic056 note in the compile's diagnostics on either target.
The message formats the path with !r, which doubles backslashes.
darkclad
left a comment
There was a problem hiding this comment.
LGTM. 5bd03ef makes the undeclared-input when a wic056 diagnostic, so check() now returns it, and 1e01d2b fixes the Windows path match. I ran tests/core on Windows against #584's head, and nothing new fails; the two wic016 path tests pass there now. One small follow-up: the "What changes for callers" line about real-time analyses losing these notes isn't in the PR text yet.
Stacked on #584 (
feat/nextflow-step-only-inputs). Merge that first; this PR's own changes are the commits above it.What
Workflow.check(target=...)is the Python form ofsophios --check: it compiles, lowers for the target and runs the same pre-flightrun()runs (the container engine, the input paths, the directories Sophios writes, the programs it calls; under Nextflow,nextflowand a Java it can run), writes nothing, prints nothing, and returns every diagnostic. What this machine lacks raisesSophiosError, asrun()does. Until now only the command line could do this.whenmust be able to givetrueorfalse. It finds awhenthat is text rather than one$(…)or${…}expression, or one that computes a number, a string ornull, such as$(inputs.count)for anintinput. On the CWL target that is a note,wic056, at the step: it refuses nothing and changes no emitted CWL. On the Nextflow target it is the refusal it already was, now from the shared check.policy=RunPolicy(partial_failure=True, success_codes=(0, 1, 2))oncompile,run,start,run_asyncandcheckwrites the CWL that--partial_failure_enableand the success-code flags write for the.wictwin. The Nextflow target refuses the policy.RunPolicyfromsophios.api.python.workflow;NotLowered,RefusalandConstructfromsophios.api.python.nextflow.What changes for callers
sophios.compiler.compile_source(..., testing=...)is nowcompile_source(..., quiet=...): the flag only leaves out the lines that say a compile started and finished, and a quiet compile now holds back its plain warnings too, socheck()prints nothing. No docs example or corpus script calls it.whenthat reads an input its process does not declare now says what happens: it has no value there, and cwltool stops the run at awhenthat gives anything buttrueorfalse.Why
A Python user could not check a workflow without compiling it to disk, could not ask for partial failure at all, and a
whenthat cannot give a boolean was found only when cwltool stopped the run.