Skip to content

refactor!: retire wic_loader; parse() is the only .wic reader - #525

Merged
vjaganat90 merged 6 commits into
PolusAI:masterfrom
vjaganat90:fix/yaml-layer-is-yaml
Oct 13, 2026
Merged

vjaganat90 merged 6 commits into
PolusAI:masterfrom
vjaganat90:fix/yaml-layer-is-yaml

Conversation

@vjaganat90

Copy link
Copy Markdown
Member

Stacked on #516 (refactor/drawing-is-a-projection). Merge that first; this PR's own changes are the commits above it.

What

  • parse() is the only reader of .wic:
    • sophios.utils_yaml.wic_loader(), WicLoader and its four tag constructors are deleted.
    • The parser builds YAML with yaml.SafeLoader, and the Sophios tags mean only what the parser says.
    • The converter writes the wic_* mappings itself. The wic_* spelling stays supported.
  • Two diagnostics change:
    • An !ii scalar that YAML cannot read (!ii 2020-13-45) is now wic009, as the same plain value is. It used to become text silently.
    • A Sophios tag on a mapping key (!ii a: b) is now wic005, not "unhashable key".
  • Tests read .wic through parse() and YAML through yaml.SafeLoader, with the Sophios tags opaque. No test gives a tag a meaning of its own. !cwl joins the repository's VS Code yaml.customTags.

Why
wic_loader was a second implementation of our own tags, and it kept becoming the authority: it is why #493 took three rounds. Nothing in the workflow corpus uses it. Emitted CWL is byte-identical at the base and here over the external corpus (mm-workflows, image-workflows, the repository's docs and examples: 9,370 files), which CI does not compile.

@darkclad darkclad left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parser side matches the description. I probed it against #516's head: a tagged key (!ii a: b, !cwl a: b, {!* k: v} inside !ii) is now one wic005 per key, not "unhashable key". !ii 2020-13-45 is wic009 with the same message as the plain value, the quoted form stays text, and !ii cycles are still wic030. tests/core + tests/contrib fail on the same 83 docker/cwltool-run tests at #516 and here on this Windows box, and the PR adds 2 passing tests. wfb_to_wic output is identical over every payload in tests/contrib. One comment on the converter, non-blocking.

for nkey in node['in']:
if str(node['in'][nkey]) != "":
node['in'][nkey] = _tag_value(Tag.INLINE_INPUT, node['in'][nkey])
node['in'][nkey] = {Key.INLINE_INPUT: node['in'][nkey]}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes what the REST converter produces, and the CHANGELOG doesn't mention it. _tag_value re-read str(value) as YAML, so a WFB setting went through YAML a second time. Now it's kept as sent, which is a fix in most cases: *.tif, @x or %p used to crash the converter (ScannerError), {row:c}... became a mapping, x # y was cut to x, and a null became the string 'None'. But string settings that look like scalars change type: "5", "0.5", "true" and "2020-01-02" used to become int/float/bool/date, and now they stay strings. The fixtures send numbers as JSON numbers, so none of them changes. Could you add a CHANGELOG line, and a small wfb_to_wic test that pins a value like *.tif or {row:c}?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I added a line to the 0.7.0 upgrade section of the CHANGELOG. It says the converter keeps each WFB setting as sent. It lists the old crashes and mangling (*.tif, @x, %p, {row:c}, x # y, null becoming 'None'). It also says that string settings like "5", "0.5", "true" and "2020-01-02" now stay strings, so a client that wants a typed value should send a JSON number or boolean. I also added a wfb_to_wic test that pins *.tif, {row:c}, 'x # y', '5', 'true' and null as kept unchanged in the inline input.

Fixed in daf1b53.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A closer look found the entry incomplete, so I amended the commit (now 70da6e2). Keeping a setting as sent also means a typed value sent as text stays text: "[1, 2]" used to become a list and "null" a null, and "yes", "0x1F" or "12:30" used to become a boolean or a number. On a typed input those are now reported (wic020). The entry now says that, lists what the second YAML read used to do to text (line breaks folded, quotes and spaces dropped as well), and tells a client to send 5, true, null or [1, 2] as the JSON value. The REST fixtures already send numbers as numbers. The test also pins "[1, 2]" staying text while a real number and list stay typed. Could you take another look?

@vjaganat90
vjaganat90 force-pushed the fix/yaml-layer-is-yaml branch from 777c60e to daf1b53 Compare October 13, 2026 16:43
@vjaganat90

Copy link
Copy Markdown
Member Author

Thanks for probing it. The one converter comment is handled: the CHANGELOG now documents the converter change, and a wfb_to_wic test pins values like *.tif and {row:c}.

Fixed in daf1b53.

@vjaganat90
vjaganat90 force-pushed the fix/yaml-layer-is-yaml branch from daf1b53 to 70da6e2 Compare October 13, 2026 16:56
@vjaganat90
vjaganat90 requested a review from darkclad October 13, 2026 16:56

@darkclad darkclad left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The converter comment is resolved by 70da6e2. The CHANGELOG entry covers the change, and test_wfb_to_wic_keeps_settings_as_sent passes here and fails against the old converter. The other five commits are unchanged by the rebase, and tests/core + tests/contrib fail on the same 83 docker/cwltool-run tests as before on this Windows box. One small wording fix in the new entry.

Comment thread CHANGELOG.md Outdated
and is no longer read as YAML a second time. That second read crashed on
`*.tif`, `@x` or `%p`, turned `{row:c}` into a mapping, cut `x # y` to `x`,
folded line breaks, dropped surrounding quotes and spaces, and wrote a null
inside a list as the text `None`. A typed value sent as text now stays text:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old converter wrote a top-level null as the text None too, not only one inside a list: {'none': None} came out as {wic_inline_input: 'None'}, and [1, None] as [1, 'None']. Your new test pins the top-level case. Something like "wrote a null, alone or inside a list, as the text None" would match.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the old converter wrote a top-level null as None too, and the new test pins that case. The entry now reads "wrote a null, alone or inside a list, as the text None".

Fixed in d13835b.

@vjaganat90
vjaganat90 force-pushed the fix/yaml-layer-is-yaml branch from 70da6e2 to 6a3b4be Compare October 13, 2026 17:35
@vjaganat90

Copy link
Copy Markdown
Member Author

Thanks for checking. I made the wording fix to the new entry: it now says the old converter wrote a null, alone or inside a list, as the text None.

Fixed in d13835b.

The parser's loader copied wic_loader's constructors, so a second
implementation of our own tags decided what they mean. It showed twice:
`!ii 2020-13-45` silently became text, where the plain `2020-13-45` is
wic009, and `!ii a: b` as a key was "found unhashable key", an artifact of
wic_loader building the tag to a dict.

The loader now takes SafeLoader's constructors only. A `!` tag builds
nothing there; the content of a tagged collection is still built, so YAML
keeps judging it. A plain `!ii` scalar YAML cannot read is wic009, as the
untagged value is; a quoted one stays the text it quotes. A Sophios tag on
a mapping key is wic005: a key is a name, and the tag belongs on the value.
_tag_value built `{wic_anchor: v}` and friends by YAML-loading a
"!tag value" string through wic_loader. We write the mapping directly
now, so the converter no longer depends on a second reader of our tags.
Its output over the REST fixtures is unchanged.
The tests used wic_loader as their oracle for what a written .wic
says and for what YAML accepts. A document's meaning now comes from
parse() (read back in to_json's spelling by read_wic), and YAML's
verdict from yaml.SafeLoader with the Sophios tags opaque
(YamlWithSophiosTagsOpaque), which gives them no meaning. Tests named
after "the loader" are named after YAML, and the ones that pinned
wic_loader itself are gone.
parse() is the only reader of .wic, and it builds YAML with
yaml.SafeLoader. WicLoader and its four tag constructors were a second
implementation of our tags with no user left. Tag and Key stay: the
desugared spelling is still part of the language.
The YAML extension flagged every !cwl as an unknown tag. !cwl tags a
scalar (a raw CWL reference) or a mapping (a step-input record), as the
language spec's construct table says; it takes no sequence.
@vjaganat90
vjaganat90 force-pushed the fix/yaml-layer-is-yaml branch from d13835b to 8a70a8d Compare October 13, 2026 17:42

@darkclad darkclad left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

The converter no longer re-reads a string setting as YAML, which changes
what a REST client gets for values such as *.tif, {row:c} or "5". I pin
that with a wfb_to_wic test and note it in the 0.7.0 upgrade section.
@vjaganat90
vjaganat90 force-pushed the fix/yaml-layer-is-yaml branch from 8a70a8d to dcf74a0 Compare October 13, 2026 17:45
@vjaganat90
vjaganat90 merged commit 125fea7 into PolusAI:master Oct 13, 2026
2 checks passed
@vjaganat90
vjaganat90 deleted the fix/yaml-layer-is-yaml branch October 13, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants