Skip to content

Commit f48d3c7

Browse files
author
Peter Amstutz
committed
Make override identifiers are relative to the toplevel workflow uri.
1 parent c55cdb0 commit f48d3c7

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

README.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,9 @@ that should be applied.
405405
406406
407407
Overrides can be specified either on the command line, or as part of the job
408-
input document.
408+
input document. Workflow steps are identified using the name of the workflow
409+
file followed by the step name as a document fragment identifier "#id".
410+
Override identifiers are relative to the toplevel workflow document.
409411

410412
.. code:: bash
411413
@@ -416,7 +418,7 @@ input document.
416418
input_parameter1: value1
417419
input_parameter2: value2
418420
cwltool:overrides:
419-
echo.cwl:
421+
workflow.cwl#step1:
420422
- class: EnvVarRequirement
421423
envDef:
422424
MESSAGE: override_value

cwltool/load_tool.py

+28-18
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,31 @@
5454
}
5555
})
5656

57+
def resolve_tool_uri(argsworkflow, # type: Union[Text, Dict[Text, Any]]
58+
resolver=None, # type: Callable[[Loader, Union[Text, Dict[Text, Any]]], Text]
59+
):
60+
# type: (...) -> Tuple[Text, Text]
61+
62+
uri = None # type: Text
63+
split = urllib.parse.urlsplit(argsworkflow)
64+
# In case of Windows path, urlsplit misjudge Drive letters as scheme, here we are skipping that
65+
if split.scheme and split.scheme in [u'http',u'https',u'file']:
66+
uri = argsworkflow
67+
elif os.path.exists(os.path.abspath(argsworkflow)):
68+
uri = file_uri(str(os.path.abspath(argsworkflow)))
69+
elif resolver:
70+
uri = resolver(document_loader, argsworkflow)
71+
72+
if uri is None:
73+
raise ValidationException("Not found: '%s'" % argsworkflow)
74+
75+
if argsworkflow != uri:
76+
_logger.info("Resolved '%s' to '%s'", argsworkflow, uri)
77+
78+
fileuri = urllib.parse.urldefrag(uri)[0]
79+
return (uri, fileuri)
80+
81+
5782
def fetch_document(argsworkflow, # type: Union[Text, Dict[Text, Any]]
5883
resolver=None, # type: Callable[[Loader, Union[Text, Dict[Text, Any]]], Text]
5984
fetcher_constructor=None
@@ -67,22 +92,7 @@ def fetch_document(argsworkflow, # type: Union[Text, Dict[Text, Any]]
6792
uri = None # type: Text
6893
workflowobj = None # type: CommentedMap
6994
if isinstance(argsworkflow, string_types):
70-
split = urllib.parse.urlsplit(argsworkflow)
71-
# In case of Windows path, urlsplit misjudge Drive letters as scheme, here we are skipping that
72-
if split.scheme and split.scheme in [u'http',u'https',u'file']:
73-
uri = argsworkflow
74-
elif os.path.exists(os.path.abspath(argsworkflow)):
75-
uri = file_uri(str(os.path.abspath(argsworkflow)))
76-
elif resolver:
77-
uri = resolver(document_loader, argsworkflow)
78-
79-
if uri is None:
80-
raise ValidationException("Not found: '%s'" % argsworkflow)
81-
82-
if argsworkflow != uri:
83-
_logger.info("Resolved '%s' to '%s'", argsworkflow, uri)
84-
85-
fileuri = urllib.parse.urldefrag(uri)[0]
95+
uri, fileuri = resolve_tool_uri(argsworkflow, resolver)
8696
workflowobj = document_loader.fetch(fileuri)
8797
elif isinstance(argsworkflow, dict):
8898
uri = "#" + Text(id(argsworkflow))
@@ -326,6 +336,6 @@ def resolve_overrides(ov, baseurl): # type: (CommentedMap, Text) -> List[Dict[T
326336
raise Exception("Expected CommentedMap, got %s" % type(ret))
327337
return ret["overrides"]
328338

329-
def load_overrides(ov): # type: (Text) -> List[Dict[Text, Any]]
339+
def load_overrides(ov, base_url): # type: (Text, Text) -> List[Dict[Text, Any]]
330340
ovloader = Loader(overrides_ctx)
331-
return resolve_overrides(ovloader.fetch(ov), ov)
341+
return resolve_overrides(ovloader.fetch(ov), base_url)

cwltool/main.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from .builder import Builder
2828
from .cwlrdf import printdot, printrdf
2929
from .errors import UnsupportedRequirement, WorkflowException
30-
from .load_tool import (fetch_document, make_tool, validate_document,
30+
from .load_tool import (resolve_tool_uri, fetch_document, make_tool, validate_document,
3131
jobloaderctx, resolve_overrides, load_overrides)
3232
from .mutation import MutationManager
3333
from .pack import pack
@@ -519,7 +519,8 @@ def generate_input_template(tool):
519519
def load_job_order(args, # type: argparse.Namespace
520520
stdin, # type: IO[Any]
521521
fetcher_constructor, # Fetcher
522-
overrides # type: List[Dict[Text, Any]]
522+
overrides, # type: List[Dict[Text, Any]]
523+
tool_file_uri # type: Text
523524
):
524525
# type: (...) -> Tuple[Dict[Text, Any], Text, Loader]
525526

@@ -543,8 +544,8 @@ def load_job_order(args, # type: argparse.Namespace
543544
job_order_object, _ = loader.resolve_ref(job_order_file, checklinks=False)
544545

545546
if job_order_object and "http://commonwl.org/cwltool#overrides" in job_order_object:
546-
overrides.extend(resolve_overrides(job_order_object, file_uri(job_order_file)))
547-
del job_order_object["http://commonwl.org/cwltool#overrides"]
547+
overrides.extend(resolve_overrides(job_order_object, tool_file_uri))
548+
del job_order_object["http://commonwl.org/cwltool#overrides"]
548549

549550
if not job_order_object:
550551
input_basedir = args.basedir if args.basedir else os.getcwd()
@@ -834,18 +835,24 @@ def main(argsl=None, # type: List[str]
834835
else:
835836
use_standard_schema("v1.0")
836837

838+
uri, tool_file_uri = resolve_tool_uri(args.workflow, resolver)[1]
839+
837840
overrides = [] # type: List[Dict[Text, Any]]
838841

839842
try:
840-
job_order_object, input_basedir, jobloader = load_job_order(args, stdin, fetcher_constructor, overrides)
843+
job_order_object, input_basedir, jobloader = load_job_order(args,
844+
stdin,
845+
fetcher_constructor,
846+
overrides,
847+
tool_file_uri)
841848
except Exception as e:
842849
_logger.error(Text(e), exc_info=args.debug)
843850

844851
if args.overrides:
845-
overrides.extend(load_overrides(file_uri(os.path.abspath(args.overrides))))
852+
overrides.extend(load_overrides(file_uri(os.path.abspath(args.overrides)), tool_file_uri))
846853

847854
try:
848-
document_loader, workflowobj, uri = fetch_document(args.workflow, resolver=resolver,
855+
document_loader, workflowobj, uri = fetch_document(uri, resolver=resolver,
849856
fetcher_constructor=fetcher_constructor)
850857

851858
if args.print_deps:

0 commit comments

Comments
 (0)