Repository navigation
feat(lang): write a tool in .wic - #609
Conversation
d54d2fb to
0801d5b
Compare
darkclad
left a comment
There was a problem hiding this comment.
I reviewed this PR's own commits (f2100fa..0801d5b, on top of #608). lang/tool.py is one lowering, and the builder, inline run:, run: x.wic, discovery by stem and the root-tool path all go through it. The python-script tool lowers to the same command line as before: the driver, types and script at positions 1-3, then --name flags. Discovery cannot shadow a .cwl with a .wic, and workflow steps name .wic with the suffix, so indexing tool documents by stem only reaches names that were unresolvable before. Probing the lowering directly, the script: env bindings (arrays, booleans, nulls), needs: sizes, docker: as a hint and the $(/backslash escaping all come out as the reference says. The head and base tests/core suites on Windows fail the same 64 tests, all environmental (no cwltool, Nextflow or container engine), and the head passes 53 more. mypy is clean on the changed modules. CI is green.
Two small points inline, neither blocking.
| SCRIPT_FILE: Final = '.script.sh' | ||
|
|
||
| _WORD = re.compile(r"""(?:'[^']*'|"[^"]*"|[^\s'"])+""") | ||
| _PLACEHOLDER = re.compile(r'\{\{|\}\}|\{([A-Za-z_]\w*)\}|[{}]') |
There was a problem hiding this comment.
A placeholder name is [A-Za-z_]\w*, but a CWL input id can hold - or .. With inputs: {in-file: File}, command: cat {in-file} is refused as "{ in '{in-file}' starts no placeholder; write {{ for a brace that is text", which points the author at the wrong fix. Either accept the CWL id characters here, or say that the input name cannot be a placeholder (and mention it next to the script: name rule in wic-reference.md §2.4).
There was a problem hiding this comment.
Fixed in 37fe8cc, where I rebuilt the tool reader: a placeholder names any input the tool declares, - and . included, so command: cat {in-file} with inputs: {in-file: File} lowers to cat with in-file at position 1. A {name} that names no input is wic058, and §2.4 says so. The property in tests/core/test_tools.py draws in-file and in.file among the input names.
| | ({'itemSeparator': ' '} if _kind(port.get('type'))[1] else {}) | ||
| _listing(cwl, refuse).append({'class': 'File', 'basename': SCRIPT_FILE, 'contents': text}) | ||
| cwl['baseCommand'] = 'env' | ||
| cwl['arguments'] = [*(cwl.get('arguments') or []), {'position': 1, 'valueFrom': 'bash'}, |
There was a problem hiding this comment.
An arguments: entry written beside script: without a position defaults to 0, so it is sorted before bash. With arguments: [hello], the command line is env hello x=... bash .script.sh, and env runs hello. §2.4 tells a command: author to give an argument a position, but says nothing about this for script:, where getting it wrong breaks the invocation rather than reordering words. A wic058 for a position below 3 here, or a line in the script: bullet (arguments for the script are $1... from position 3), would cover it.
There was a problem hiding this comment.
Fixed in 37fe8cc: script: owns the whole command line, so arguments: beside it is wic058, with or without a position. So are baseCommand:, an inputBinding anywhere in an input, a record input and an entry at .script.sh. The command line is always env name=value ... bash .script.sh; test_a_script_owns_its_command_line draws those keys and checks the refusal, and §2.4 lists them.
0801d5b to
b7ff224
Compare
5a29d4e to
37fe8cc
Compare
A mapping that says command: or script: is a tool, read as steps: makes a workflow, each word and port with its place. Adds wic058 and wic059, the schema and render of a tool, and lang_version 0.1.0 with wic060 for a compile pinned below it.
37fe8cc to
aef7ab9
Compare
darkclad
left a comment
There was a problem hiding this comment.
LGTM. Both points from the last round hold at aef7ab98. command: cat {in-file} {in.x} lowers to cat with the two inputs at positions 1 and 2. Any arguments: beside script: is wic058, with or without a position, and so is a record input. With the reader rebuilt on the parser's own nodes, the builder, an inline run:, run: x.wic, discovery and a root tool all reach the one command_line_tool lowering, and the python-script tool keeps its command line. I probed the other lines directly: the script: env bindings, a flag before an optional input, docker: and needs: beside their own requirements, shell characters, a type written as an output line, and the list form all come out as §2.4 says. The 0.1.0 language version and the single-pass converter insertion (wic022 retired) are both stated in the spec and in edge-inference.md. The head and base tests/core suites on Windows fail the same 64 tests, all environmental (no cwltool, Nextflow or container engine), and the head passes 15 more. mypy is clean on the 22 changed modules, and CI is green. The only new noise is five Hypothesis "overly large repr" warnings from test_a_document_the_parser_recovered_never_raises, now that its documents include tools.
One lowering writes the places a line owns and refuses any the author also wrote, in one walk. The parser lowers once and keeps the CWL on the tool.
I read a tool file when a step first asks, whether it is a .cwl or a .wic. Discovery files each tool once, so the doors, Python included, find the same tool, and a .wic root is the workflow of one step that runs it.
I build the tool from the objects that declare it, so Python and .wic lower through the one function. The python_script adapter builds Port and Word objects too, and the cookbook shows a tool written both ways.
One matching rule, one pass: a converter qualifies when an output fits the input and it reads an output upstream; the job gives the rest of its inputs. wic022 and iteration_limit go.
I add the tool document to the reference (§2.4), the steps and tool-builder pages, the spec's versioning, the architecture and the converter rule.
681d54c to
58b12d7
Compare
I check a document's own rules (step ids, names, edges, scatter, outputs) once, for a parsed and a Python-built document alike, and Resolve looks nothing up for one Check has not made a CheckedDocument of; lowering and its tests assume them. The Python-against-its-bundle law is held once, in the pairs, and no test fakes the platform.
58b12d7 to
603c219
Compare
darkclad
left a comment
There was a problem hiding this comment.
LGTM. Since aef7ab98, the lowering commit only trims fixture cases that the script property now draws, and the new commit moves the checks of a document's own nodes (step ids, names, edge producers, scatter: shape, workflow outputs) out of Lower into ir/check.py. They run once per document, after its wic: steps: contributions and before Resolve looks anything up, so a bad step id is no longer reported as a missing process. The rules and messages carry over unchanged, and Lower's dict of edge definitions is safe now that Check refuses a second producer. The preflight change is fine: _docker_processes returns 0 when pgrep is missing, so dropping the win32 guard changes nothing on Windows. The pairs now cover renaming after binding in place of test_canonical_path.py, though not its randomized file and step names. On Windows, tests/core at 603c2194 fails the same 64 tests as its base, all environmental (no cwltool, Nextflow or container engine). mypy is clean on the changed modules, and CI is green.
launch reads nothing of this machine: run_local places a local run (its paths, the default output directory, this process's environment) before the backend launches it, and a runner's own name is the program another machine runs. prepare is write, which returns the folders the runner's machine must make, then this machine's check, pulls and folders; needs says what a check judges. A CWL runner's write leaves the files its prepare leaves, the job's empty directory in the runner's own form. outcome reads through read and writes nothing, and the run writes the summary a runner printed. Local runs are what they were on #609: 39,300 launches, and the command line over the 456 .wic files of docs, examples and tests, with no difference.
What
.wicdocument whose defining key iscommand:(a command line with{input}placeholders) orscript:(a bash script that reads each input as the variable of its name) is a tool, assteps:makes a workflow. The parser reads it into its own nodes and one function lowers it to theCommandLineToolit means; the builder's.command(),.script()andOutput.of()lower through the same function..cwlor.wictool is read when a step first asks, under the one key discovery gave it, through every door (run:,id:, a PythonStep,Workflow.from_wic, a converter). A line owns its CWL places: one the author also wrote iswic058, andscript:refuses anything that would add to its command line. A tool key of the wrong shape iswic059. Tools are language 0.1.0; a compile pinned to 0.0.1 that reaches one iswic060.--insert_steps_automaticallyinserts a converter as an ordinary step, in one pass, by the rule every edge uses. The flag,inference_rules,Inference(insert_steps=True, format_rules=...)and what they compile are unchanged.Why A tool had to be written as a CWL
CommandLineToolby hand; this is the tool half of the.wiclanguage. Inference looks only backwards, so a converter inserted before a step changes nothing decided before it: the fixed-point loop,iteration_limitandwic022go.Before, the CWL an author wrote:
After, in Python and in
.wic(docs/cookbook/tally_words.pyand.wic, which lower to the CWL above):