-
Notifications
You must be signed in to change notification settings - Fork 967
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
An assortment of tweaks and fixes to tool parsing and cwltool handling used by planemo and down stream CWL fork of Galaxy.
- Loading branch information
Showing
7 changed files
with
85 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,72 @@ | ||
"""Abstraction around cwltool and related libraries for loading a CWL artifact.""" | ||
from collections import namedtuple | ||
import os | ||
|
||
from six.moves.urllib.parse import urldefrag | ||
|
||
from .cwltool_deps import ( | ||
process, | ||
ensure_cwltool_available, | ||
schema_salad, | ||
workflow, | ||
load_tool, | ||
) | ||
|
||
ProcessDefinition = namedtuple("ProcessObject", ["process_object", "metadata"]) | ||
RawProcessReference = namedtuple("RawProcessReference", ["process_object", "uri"]) | ||
ProcessDefinition = namedtuple("ProcessDefinition", ["process_object", "metadata", "document_loader", "avsc_names", "raw_process_reference"]) | ||
|
||
|
||
class SchemaLoader(object): | ||
|
||
def __init__(self, strict=True): | ||
self._strict = strict | ||
self._document_loader = None | ||
self._avsc_names = None | ||
self._raw_document_loader = None | ||
|
||
def _lazy_init(self): | ||
if self._document_loader is not None: | ||
return | ||
@property | ||
def raw_document_loader(self): | ||
if self._raw_document_loader is None: | ||
ensure_cwltool_available() | ||
self._raw_document_loader = schema_salad.ref_resolver.Loader({"cwl": "https://w3id.org/cwl/cwl#", "id": "@id"}) | ||
|
||
document_loader, avsc_names, _ = process.get_schema() | ||
self._document_loader = document_loader | ||
self._avsc_names = avsc_names | ||
return self._raw_document_loader | ||
|
||
if isinstance(avsc_names, Exception): | ||
raise avsc_names | ||
|
||
def raw_object(self, path): | ||
self._lazy_init() | ||
self._document_loader.idx.clear() | ||
def raw_process_reference(self, path): | ||
uri = "file://" + os.path.abspath(path) | ||
fileuri, _ = urldefrag(uri) | ||
return self._document_loader.fetch(fileuri) | ||
return RawProcessReference(self.raw_document_loader.fetch(fileuri), uri) | ||
|
||
def process_definition(self, raw_object): | ||
self._lazy_init() | ||
process_object, metadata = schema_salad.schema.load_and_validate( | ||
self._document_loader, | ||
self._avsc_names, | ||
raw_object, | ||
self._strict, | ||
def process_definition(self, raw_reference): | ||
document_loader, avsc_names, process_object, metadata, uri = load_tool.validate_document( | ||
self.raw_document_loader, | ||
raw_reference.process_object, | ||
raw_reference.uri, | ||
) | ||
process_def = ProcessDefinition( | ||
process_object, | ||
metadata, | ||
document_loader, | ||
avsc_names, | ||
raw_reference, | ||
) | ||
return ProcessDefinition(process_object, metadata) | ||
return process_def | ||
|
||
def tool(self, **kwds): | ||
self._lazy_init() | ||
process_definition = kwds.get("process_definition", None) | ||
if process_definition is None: | ||
raw_object = kwds.get("raw_object", None) | ||
if raw_object is None: | ||
raw_object = self.raw_object(kwds["path"]) | ||
process_definition = self.process_definition(raw_object) | ||
raw_process_reference = kwds.get("raw_process_reference", None) | ||
if raw_process_reference is None: | ||
raw_process_reference = self.raw_process_reference(kwds["path"]) | ||
process_definition = self.process_definition(raw_process_reference) | ||
|
||
make_tool = kwds.get("make_tool", workflow.defaultMakeTool) | ||
tool = make_tool( | ||
tool = load_tool.make_tool( | ||
process_definition.document_loader, | ||
process_definition.avsc_names, | ||
process_definition.process_object, | ||
strict=self._strict, | ||
makeTool=make_tool, | ||
loader=self._document_loader, | ||
avsc_names=self._avsc_names, | ||
process_definition.metadata, | ||
process_definition.raw_process_reference.uri, | ||
make_tool, | ||
{"strict": self._strict}, | ||
) | ||
if process_definition.metadata: | ||
metadata = process_definition.metadata | ||
else: | ||
metadata = { | ||
"$namespaces": tool.tool.get("$namespaces", {}), | ||
"$schemas": tool.tool.get("$schemas", []) | ||
} | ||
|
||
tool.metadata = metadata | ||
return tool | ||
|
||
schema_loader = SchemaLoader() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters