Skip to content

Commit db05d33

Browse files
authored
Add outline of cwltool archicture. (#297)
* Add outline of cwltool archicture.
1 parent 2210cd3 commit db05d33

File tree

1 file changed

+126
-9
lines changed

1 file changed

+126
-9
lines changed

README.rst

Lines changed: 126 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,6 @@ the default cwl-runner use::
5252

5353
cwltool [tool-or-workflow-description] [input-job-settings]
5454

55-
Import as a module
56-
----------------
57-
58-
Add::
59-
60-
import cwltool
61-
62-
to your script.
63-
6455
Use with boot2docker
6556
--------------------
6657
boot2docker is running docker inside a virtual machine and it only mounts ``Users``
@@ -86,3 +77,129 @@ documents using absolute or relative local filesytem paths. If a relative path
8677
is referenced and that document isn't found in the current directory then the
8778
following locations will be searched:
8879
http://www.commonwl.org/v1.0/CommandLineTool.html#Discovering_CWL_documents_on_a_local_filesystem
80+
81+
Import as a module
82+
------------------
83+
84+
Add::
85+
86+
import cwltool
87+
88+
to your script.
89+
90+
The easiest way to use cwltool to run a tool or workflow from Python is to use a Factory::
91+
92+
import cwltool.factory
93+
fac = cwltool.factory.Factory()
94+
95+
echo = f.make("echo.cwl")
96+
result = echo(inp="foo")
97+
98+
# result["out"] == "foo"
99+
100+
101+
Cwltool control flow
102+
--------------------
103+
104+
#. Use CWL `load_tool()` to load document.
105+
106+
#. Fetches the document from file or URL
107+
#. Applies preprocessing (syntax/identifier expansion and normalization)
108+
#. Validates the document based on cwlVersion
109+
#. If necessary, updates the document to latest spec
110+
#. Constructs a Process object using `make_tool()` callback. This yields a
111+
CommandLineTool, Workflow, or ExpressionTool. For workflows, this
112+
recursively constructs each workflow step.
113+
#. To construct custom types for CommandLineTool, Workflow, or
114+
ExpressionTool, provide a custom `make_tool()`
115+
116+
#. Iterate on the `job()` method of the Process object to get back runnable jobs.
117+
118+
#. `job()` is a generator method (uses the Python iterator protocol)
119+
#. Each time the `job()` method is invoked in an iteration, it returns one
120+
of: a runnable item (an object with a `run()` method), `None` (indicating
121+
there is currently no work ready to run) or end of iteration (indicating
122+
the process is complete.)
123+
#. Invoke the runnable item by calling `run()`. This runs the tool and gets output.
124+
#. Output of a process is reported by an output callback.
125+
#. `job()` may be iterated over multiple times. It will yield all the work
126+
that is currently ready to run and then yield None.
127+
128+
#. "Workflow" objects create a corresponding "WorkflowJob" and "WorkflowJobStep" objects to hold the workflow state for the duration of the job invocation.
129+
130+
#. The WorkflowJob iterates over each WorkflowJobStep and determines if the
131+
inputs the step are ready.
132+
#. When a step is ready, it constructs an input object for that step and
133+
iterates on the `job()` method of the workflow job step.
134+
#. Each runnable item is yielded back up to top level run loop
135+
#. When a step job completes and receives an output callback, the
136+
job outputs are assigned to the output of the workflow step.
137+
#. When all steps are complete, the intermediate files are moved to a final
138+
workflow output, intermediate directories are deleted, and the output
139+
callback for the workflow is called.
140+
141+
#. "CommandLineTool" job() objects yield a single runnable object.
142+
143+
#. The CommandLineTool `job()` method calls `makeJobRunner()` to create a
144+
`CommandLineJob` object
145+
#. The job method configures the CommandLineJob object by setting public
146+
attributes
147+
#. The job method iterates over file and directories inputs to the
148+
CommandLineTool and creates a "path map".
149+
#. Files are mapped from their "resolved" location to a "target" path where
150+
they will appear at tool invocation (for example, a location inside a
151+
Docker container.) The target paths are used on the command line.
152+
#. Files are staged to targets paths using either Docker volume binds (when
153+
using containers) or symlinks (if not). This staging step enables files
154+
to be logically rearranged or renamed independent of their source layout.
155+
#. The run() method of CommandLineJob executes the command line tool or
156+
Docker container, waits for it to complete, collects output, and makes
157+
the output callback.
158+
159+
160+
Extension points
161+
----------------
162+
163+
The following functions can be provided to main(), to load_tool(), or to the
164+
executor to override or augment the listed behaviors.
165+
166+
executor(tool, job_order_object, **kwargs)
167+
(Process, Dict[Text, Any], **Any) -> Tuple[Dict[Text, Any], Text]
168+
169+
A toplevel workflow execution loop, should synchronously execute a process
170+
object and return an output object.
171+
172+
makeTool(toolpath_object, **kwargs)
173+
(Dict[Text, Any], **Any) -> Process
174+
175+
Construct a Process object from a document.
176+
177+
selectResources(request)
178+
(Dict[Text, int]) -> Dict[Text, int]
179+
180+
Take a resource request and turn it into a concrete resource assignment.
181+
182+
versionfunc()
183+
() -> Text
184+
185+
Return version string.
186+
187+
make_fs_access(basedir)
188+
(Text) -> StdFsAccess
189+
190+
Return a file system access object.
191+
192+
fetcher_constructor(cache, session)
193+
(Dict[unicode, unicode], requests.sessions.Session) -> Fetcher
194+
195+
Construct a Fetcher object with the supplied cache and HTTP session.
196+
197+
resolver(document_loader, document)
198+
(Loader, Union[Text, dict[Text, Any]]) -> Text
199+
200+
Resolve a relative document identifier to an absolute one which can be fetched.
201+
202+
logger_handler
203+
logging.Handler
204+
205+
Handler object for logging.

0 commit comments

Comments
 (0)