Skip to content

Commit

Permalink
job loading: allow inputs named "id"
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Gene Gottlieb <[email protected]>
  • Loading branch information
mr-c and SGSSGene committed Oct 13, 2023
1 parent 5e5615b commit 51c5fb7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
13 changes: 11 additions & 2 deletions cwltool/load_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,23 @@
from .update import ALLUPDATES
from .utils import CWLObjectType, ResolverType, visit_class

jobloaderctx: ContextType = {
docloaderctx: ContextType = {
"cwl": "https://w3id.org/cwl/cwl#",
"cwltool": "http://commonwl.org/cwltool#",
"path": {"@type": "@id"},
"location": {"@type": "@id"},
"id": "@id",
}

jobloader_id_name = "__id"
jobloaderctx: ContextType = {
"cwl": "https://w3id.org/cwl/cwl#",
"cwltool": "http://commonwl.org/cwltool#",
"path": {"@type": "@id"},
"location": {"@type": "@id"},
jobloader_id_name: "@id",
}


overrides_ctx: ContextType = {
"overrideTarget": {"@type": "@id"},
Expand All @@ -72,7 +81,7 @@ def default_loader(
doc_cache: bool = True,
) -> Loader:
return Loader(
jobloaderctx,
docloaderctx,
fetcher_constructor=fetcher_constructor,
allow_attachments=lambda r: enable_dev,
doc_cache=doc_cache,
Expand Down
9 changes: 5 additions & 4 deletions cwltool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
from .load_tool import (
default_loader,
fetch_document,
jobloader_id_name,
jobloaderctx,
load_overrides,
make_tool,
Expand Down Expand Up @@ -446,7 +447,7 @@ def init_job_order(
_logger.exception("Failed to resolv job_order: %s", cmd_line["job_order"])
exit(1)
else:
job_order_object = {"id": args.workflow}
job_order_object = {jobloader_id_name: args.workflow}

del cmd_line["job_order"]

Expand Down Expand Up @@ -506,7 +507,7 @@ def expand_formats(p: CWLObjectType) -> None:
process.inputs_record_schema, job_order_object, discover_secondaryFiles=True
)
basedir: Optional[str] = None
uri = cast(str, job_order_object["id"])
uri = cast(str, job_order_object[jobloader_id_name])
if uri == args.workflow:
basedir = os.path.dirname(uri)
uri = ""
Expand All @@ -529,8 +530,8 @@ def expand_formats(p: CWLObjectType) -> None:

if "cwl:tool" in job_order_object:
del job_order_object["cwl:tool"]
if "id" in job_order_object:
del job_order_object["id"]
if jobloader_id_name in job_order_object:
del job_order_object[jobloader_id_name]
return job_order_object


Expand Down
13 changes: 13 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -1859,3 +1859,16 @@ def test_invalid_nested_array() -> None:
assert (
"tests/nested-array.cwl:6:5: Field 'type' references unknown identifier 'string[][]'"
) in stderr


def test_input_named_id() -> None:
"""Confirm that it is valid to have an input named "id"."""
exit_code, stdout, stderr = get_main_output(
[
"--validate",
"--debug",
get_data("tests/wf/input_named_id.cwl"),
get_data("tests/wf/input_named_id.yaml"),
]
)
assert exit_code == 0, stderr
13 changes: 13 additions & 0 deletions tests/wf/input_named_id.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
label: FeatureFinderIdentification
doc: ""
inputs:
id:
doc: featureXML or consensusXML file
type: File
outputs:
[]
cwlVersion: v1.2
class: CommandLineTool
baseCommand:
- FeatureFinderIdentification

3 changes: 3 additions & 0 deletions tests/wf/input_named_id.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id:
class: File
path: ../2.fastq

0 comments on commit 51c5fb7

Please sign in to comment.