Skip to content

Commit b40033f

Browse files
committed
better pass --skip-schemas
1 parent 02366ff commit b40033f

File tree

6 files changed

+141
-7
lines changed

6 files changed

+141
-7
lines changed

cwltool/context.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def __init__(self, kwargs: Optional[Dict[str, Any]] = None) -> None:
120120
self.codegen_idx: Dict[str, Tuple[Any, "LoadingOptions"]] = {}
121121
self.fast_parser = False
122122
self.skip_resolve_all = False
123+
self.skip_schemas = False
123124

124125
super().__init__(kwargs)
125126

cwltool/load_tool.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from cwl_utils.parser import cwl_v1_2, cwl_v1_2_utils
2424
from schema_salad.exceptions import ValidationException
25+
from schema_salad.fetcher import Fetcher
2526
from schema_salad.ref_resolver import Loader, file_uri
2627
from schema_salad.schema import validate_doc
2728
from schema_salad.sourceline import SourceLine, cmap
@@ -32,7 +33,6 @@
3233
ResolveType,
3334
json_dumps,
3435
)
35-
from schema_salad.fetcher import Fetcher
3636

3737
from ruamel.yaml.comments import CommentedMap, CommentedSeq
3838

@@ -395,7 +395,6 @@ def resolve_and_validate_document(
395395
workflowobj: Union[CommentedMap, CommentedSeq],
396396
uri: str,
397397
preprocess_only: bool = False,
398-
skip_schemas: Optional[bool] = None,
399398
) -> Tuple[LoadingContext, str]:
400399
"""Validate a CWL document."""
401400
if not loadingContext.loader:
@@ -502,7 +501,7 @@ def resolve_and_validate_document(
502501
idx=loader.idx,
503502
cache=sch_document_loader.cache,
504503
fetcher_constructor=loadingContext.fetcher_constructor,
505-
skip_schemas=skip_schemas,
504+
skip_schemas=loadingContext.skip_schemas,
506505
doc_cache=loadingContext.doc_cache,
507506
)
508507

@@ -652,7 +651,9 @@ def load_tool(
652651
loadingContext, workflowobj, uri = fetch_document(argsworkflow, loadingContext)
653652

654653
loadingContext, uri = resolve_and_validate_document(
655-
loadingContext, workflowobj, uri
654+
loadingContext,
655+
workflowobj,
656+
uri,
656657
)
657658

658659
return make_tool(uri, loadingContext)
@@ -682,15 +683,13 @@ def recursive_resolve_and_validate_document(
682683
workflowobj: Union[CommentedMap, CommentedSeq],
683684
uri: str,
684685
preprocess_only: bool = False,
685-
skip_schemas: Optional[bool] = None,
686686
) -> Tuple[LoadingContext, str, Process]:
687687
"""Validate a CWL document, checking that a tool object can be built."""
688688
loadingContext, uri = resolve_and_validate_document(
689689
loadingContext,
690690
workflowobj,
691691
uri,
692692
preprocess_only=preprocess_only,
693-
skip_schemas=skip_schemas,
694693
)
695694
tool = make_tool(uri, loadingContext)
696695
return loadingContext, uri, tool

cwltool/main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,6 @@ def main(
11361136
workflowobj,
11371137
uri,
11381138
preprocess_only=(args.print_pre or args.pack),
1139-
skip_schemas=args.skip_schemas,
11401139
)
11411140

11421141
if loadingContext.loader is None:

tests/test_misc_cli.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,23 @@ def test_error_graph_with_no_default() -> None:
6767
"Tool file contains graph of multiple objects, must specify one of #echo, #cat, #collision"
6868
in stderr
6969
)
70+
71+
72+
def test_skip_schemas_external_step() -> None:
73+
"""Test that --skip-schemas works even for bad schemas in external docs."""
74+
exit_code, stdout, stderr = get_main_output(
75+
[
76+
"--print-rdf",
77+
"--skip-schemas",
78+
get_data("tests/wf/revsort_step_bad_schema.cwl"),
79+
]
80+
)
81+
assert exit_code == 0
82+
assert (
83+
"Repeat node-elements inside property elements: "
84+
"http://www.w3.org/1999/xhtmlmeta"
85+
) not in stderr
86+
assert (
87+
"Could not load extension schema https://bad.example.com/missing.ttl: "
88+
"Error fetching https://bad.example.com/missing.ttl"
89+
) not in stderr

tests/wf/revsort_step_bad_schema.cwl

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env cwl-runner
2+
#
3+
# This is a two-step workflow which uses "revtool" and "sorttool" defined above.
4+
#
5+
class: Workflow
6+
doc: "Reverse the lines in a document, then sort those lines."
7+
cwlVersion: v1.0
8+
9+
# Requirements & hints specify prerequisites and extensions to the workflow.
10+
# In this example, DockerRequirement specifies a default Docker container
11+
# in which the command line tools will execute.
12+
hints:
13+
- class: DockerRequirement
14+
dockerPull: docker.io/debian:stable-slim
15+
16+
17+
# The inputs array defines the structure of the input object that describes
18+
# the inputs to the workflow.
19+
#
20+
# The "reverse_sort" input parameter demonstrates the "default" field. If the
21+
# field "reverse_sort" is not provided in the input object, the default value will
22+
# be used.
23+
inputs:
24+
workflow_input:
25+
type: File
26+
doc: "The input file to be processed."
27+
format: iana:text/plain
28+
default:
29+
class: File
30+
location: hello.txt
31+
reverse_sort:
32+
type: boolean
33+
default: true
34+
doc: "If true, reverse (descending) sort"
35+
36+
# The "outputs" array defines the structure of the output object that describes
37+
# the outputs of the workflow.
38+
#
39+
# Each output field must be connected to the output of one of the workflow
40+
# steps using the "outputSource" field. Here, the parameter "sorted_output" of the
41+
# workflow comes from the "sorted_output" output of the "sorted" step.
42+
outputs:
43+
sorted_output:
44+
type: File
45+
outputSource: sorted/sorted_output
46+
doc: "The output with the lines reversed and sorted."
47+
48+
# The "steps" array lists the executable steps that make up the workflow.
49+
# The tool to execute each step is listed in the "run" field.
50+
#
51+
# In the first step, the "in" field of the step connects the upstream
52+
# parameter "workflow_input" of the workflow to the input parameter of the tool
53+
# "revtool_input"
54+
#
55+
# In the second step, the "in" field of the step connects the output
56+
# parameter "revtool_output" from the first step to the input parameter of the
57+
# tool "sorted_input".
58+
steps:
59+
rev:
60+
in:
61+
revtool_input: workflow_input
62+
out: [revtool_output]
63+
run: revtool_bad_schema.cwl
64+
65+
sorted:
66+
in:
67+
sorted_input: rev/revtool_output
68+
reverse: reverse_sort
69+
out: [sorted_output]
70+
run: sorttool.cwl
71+
72+
$namespaces:
73+
iana: https://www.iana.org/assignments/media-types/

tests/wf/revtool_bad_schema.cwl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env cwl-runner
2+
#
3+
# Simplest example command line program wrapper for the Unix tool "rev".
4+
#
5+
class: CommandLineTool
6+
cwlVersion: v1.0
7+
doc: "Reverse each line using the `rev` command"
8+
$schemas:
9+
- https://bad.example.com/missing.ttl
10+
- https://schema.org/docs/
11+
- https://schema.org/docs/schema_org_rdfa.html
12+
13+
# The "inputs" array defines the structure of the input object that describes
14+
# the inputs to the underlying program. Here, there is one input field
15+
# defined that will be called "input" and will contain a "File" object.
16+
#
17+
# The input binding indicates that the input value should be turned into a
18+
# command line argument. In this example inputBinding is an empty object,
19+
# which indicates that the file name should be added to the command line at
20+
# a default location.
21+
inputs:
22+
revtool_input:
23+
type: File
24+
inputBinding: {}
25+
26+
# The "outputs" array defines the structure of the output object that
27+
# describes the outputs of the underlying program. Here, there is one
28+
# output field defined that will be called "output", must be a "File" type,
29+
# and after the program executes, the output value will be the file
30+
# output.txt in the designated output directory.
31+
outputs:
32+
revtool_output:
33+
type: File
34+
outputBinding:
35+
glob: output.txt
36+
37+
# The actual program to execute.
38+
baseCommand: rev
39+
40+
# Specify that the standard output stream must be redirected to a file called
41+
# output.txt in the designated output directory.
42+
stdout: output.txt

0 commit comments

Comments
 (0)