Skip to content

Commit b16ae29

Browse files
authored
Merge pull request #244 from common-workflow-language/eliminate-dirent
Eliminate dirent
2 parents 6f9cb1c + f773701 commit b16ae29

31 files changed

+1034
-681
lines changed

draft-4/CommandLineTool.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ $graph:
630630
IRI such as an [RRID](http://www.identifiers.org/rrid/SCR_001156).
631631
Example: `http://identifiers.org/rrid/RRID:SCR_001156`
632632
633-
- name: DirentExt
633+
- name: Dirent
634634
type: record
635635
doc: |
636636
Define a file or subdirectory that must be placed in the designated output
@@ -639,11 +639,12 @@ $graph:
639639
template.
640640
fields:
641641
- name: entryname
642-
type: [string, Expression]
642+
type: ["null", string, Expression]
643643
jsonldPredicate:
644644
_id: cwl:entryname
645645
doc: |
646646
The name of the file or subdirectory to create in the output directory.
647+
If `entry` is a File or Directory, this overrides `basename`. Optional.
647648
- name: entry
648649
type: [string, Expression]
649650
jsonldPredicate:
@@ -672,6 +673,7 @@ $graph:
672673
the original file or directory. Default false (files and directories
673674
read-only by default).
674675
676+
675677
- name: InitialWorkDirRequirement
676678
type: record
677679
extends: ProcessRequirement
@@ -683,19 +685,18 @@ $graph:
683685
- name: listing
684686
type:
685687
- type: array
686-
items: [File, DirentExt]
688+
items: [File, Directory, Dirent, string, Expression]
687689
- string
688690
- Expression
689691
jsonldPredicate:
690692
_id: "cwl:listing"
691-
mapSubject: entryname
692-
mapPredicate: entry
693693
doc: |
694694
The list of files or subdirectories that must be placed in the
695695
designated output directory prior to executing the command line tool.
696696
697697
May be an expression. If so, the expression return value must validate
698-
as `{type: array, items: [File, Dirent]}`.
698+
as `{type: array, items: [File, Directory]}`.
699+
699700
700701
- name: EnvVarRequirement
701702
type: record

draft-4/Process.yml

Lines changed: 71 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ $graph:
6565
_type: "@vocab"
6666
doc: Must be `File` to indicate this object describes a file.
6767
- name: location
68-
type: string
68+
type: string?
6969
doc: |
7070
A URI that identifies the file resource. This may be a relative
7171
reference, in which case it must be resolved using the base URI of the
@@ -75,6 +75,10 @@ $graph:
7575
remote resource (due to unsupported protocol, access denied, or other
7676
issue) it must signal an error.
7777
78+
If the `location' field is not provided, the `contents` field must be
79+
provided. The implementation must assign a unique identifier for
80+
the `location` field.
81+
7882
If the `path` field is provided but the `location` field is not, an
7983
implementation may assign the value of the `path` field to `location`,
8084
then follow the rules above.
@@ -84,24 +88,34 @@ $graph:
8488
- name: path
8589
type: string?
8690
doc: |
87-
The local path where the File is made available prior to executing a
88-
CommandLineTool. This must be set by the implementation. This field
91+
The local host path where the File is available when a CommandLineTool is
92+
executed. This field must be set by the implementation. The final
93+
path component must match the value of `basename`. This field
8994
must not be used in any other context. The command line tool being
9095
executed must be able to to access the file at `path` using the POSIX
9196
`open(2)` syscall.
97+
98+
As a special case, if the `path` field is provided but the `location`
99+
field is not, an implementation may assign the value of the `path`
100+
field to `location`, and remove the `path` field.
92101
jsonldPredicate:
93102
"_id": "cwl:path"
94103
"_type": "@id"
95104
- name: basename
96105
type: string?
97106
doc: |
98-
The base name of the file, that is, the path component following the
99-
final slash in the path.
100-
101-
The implementation must set this field based on the value of `path`
102-
prior to evaluating parameter references or expressions in a
103-
CommandLineTool document. This field must not be used in any other
104-
context.
107+
The base name of the file, that is, the name of the file without any
108+
leading directory path. The base name must not contain a slash `/`.
109+
110+
If not provided, the implementation must set this field based on the
111+
`location` field by taking the final path component after parsing
112+
`location` as an IRI. If `basename` is provided, it is not required to
113+
match the value from `location`.
114+
115+
When this file is made available to a CommandLineTool, it must be named
116+
with `basename`, i.e. the final component of the `path` field must match
117+
`basename`.
118+
jsonldPredicate: "cwl:basename"
105119
- name: dirname
106120
type: string?
107121
doc: |
@@ -121,10 +135,8 @@ $graph:
121135
period. Leading periods on the basename are ignored; a basename of
122136
`.cshrc` will have a nameroot of `.cshrc`.
123137
124-
The implementation must set this field based on the value of `path`
125-
prior to evaluating parameter references or expressions in a
126-
CommandLineTool document. This field must not be used in any other
127-
context.
138+
The implementation must set this field automatically based on the value
139+
of `basename` prior to evaluating parameter references or expressions.
128140
- name: nameext
129141
type: string?
130142
doc: |
@@ -133,10 +145,8 @@ $graph:
133145
period. Leading periods on the basename are ignored; a basename of
134146
`.cshrc` will have an empty `nameext`.
135147
136-
The implementation must set this field based on the value of `path`
137-
prior to evaluating parameter references or expressions in a
138-
CommandLineTool document. This field must not be used in any other
139-
context.
148+
The implementation must set this field automatically based on the value
149+
of `basename` prior to evaluating parameter references or expressions.
140150
- name: checksum
141151
type: ["null", string]
142152
doc: |
@@ -149,7 +159,7 @@ $graph:
149159
type:
150160
- "null"
151161
- type: array
152-
items: [File, Dirent]
162+
items: [File, Directory]
153163
jsonldPredicate: "cwl:secondaryFiles"
154164
doc: |
155165
A list of additional files that are associated with the primary file
@@ -179,26 +189,26 @@ $graph:
179189
File format ontologies may be provided in the "$schema" metadata at the
180190
root of the document. If no ontologies are specified in `$schema`, the
181191
runtime may perform exact file format matches.
192+
- name: contents
193+
type: string?
194+
doc: |
195+
File contents literal. Maximum of 64 KiB.
182196
197+
If neither `location` nor `path` is provided, `contents` must be
198+
non-null. The implementation must assign a unique identifier for the
199+
`location` field. When the file is staged as input to CommandLineTool,
200+
the value of `contents` must be written to a file.
201+
202+
If `loadContents` of `inputBinding` or `outputBinding` is true and
203+
`location` is valid, the implementation must read up to the first 64
204+
KiB of text from the file and place it in the "contents" field.
183205
184-
- name: Dirent
185-
type: record
186-
fields:
187-
- name: entryname
188-
type: string
189-
jsonldPredicate:
190-
"_id": cwl:entryname
191-
- name: entry
192-
type: [File, Directory]
193-
jsonldPredicate:
194-
"_id": cwl:entry
195206
196207
- name: Directory
197208
type: record
198209
docParent: "#CWLType"
199210
doc: |
200-
Represents a directory to present to a command line tool. This could be a virtual
201-
directory, made of files assembled from multiple locations.
211+
Represents a directory to present to a command line tool.
202212
fields:
203213
- name: class
204214
type:
@@ -211,7 +221,7 @@ $graph:
211221
_type: "@vocab"
212222
doc: Must be `Directory` to indicate this object describes a Directory.
213223
- name: location
214-
type: string
224+
type: string?
215225
doc: |
216226
A URI that identifies the directory resource. This may be a relative
217227
reference, in which case it must be resolved using the base URI of the
@@ -222,6 +232,10 @@ $graph:
222232
unsupported protocol, access denied, or other issue) it must signal an
223233
error.
224234
235+
If the `location' field is not provided, the `listing` field must be
236+
provided. The implementation must assign a unique identifier for
237+
the `location` field.
238+
225239
If the `path` field is provided but the `location` field is not, an
226240
implementation may assign the value of the `path` field to `location`,
227241
then follow the rules above.
@@ -239,16 +253,36 @@ $graph:
239253
jsonldPredicate:
240254
_id: "cwl:path"
241255
_type: "@id"
256+
- name: basename
257+
type: string?
258+
doc: |
259+
The base name of the directory, that is, the name of the file without any
260+
leading directory path. The base name must not contain a slash `/`.
261+
262+
If not provided, the implementation must set this field based on the
263+
`location` field by taking the final path component after parsing
264+
`location` as an IRI. If `basename` is provided, it is not required to
265+
match the value from `location`.
266+
267+
When this file is made available to a CommandLineTool, it must be named
268+
with `basename`, i.e. the final component of the `path` field must match
269+
`basename`.
270+
jsonldPredicate: "cwl:basename"
242271
- name: listing
243272
type:
244273
- "null"
245274
- type: array
246-
items: [File, Dirent]
247-
doc: List of files or subdirectories contained in this directory
275+
items: [File, Directory]
276+
doc: |
277+
List of files or subdirectories contained in this directory. The name
278+
of each file or subdirectory is determined by the `basename` field of
279+
each `File` or `Directory` object. It is an error if a `File` shares a
280+
`basename` with any other entry in `listing`. If two or more
281+
`Directory` object share the same `basename`, this must be treated as
282+
equivalent to a single subdirectory with the listings recursively
283+
merged.
248284
jsonldPredicate:
249285
_id: "cwl:listing"
250-
mapSubject: entryname
251-
mapPredicate: entry
252286

253287
- name: SchemaBase
254288
type: record

draft-4/conformance_test_draft-4.yaml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -732,18 +732,12 @@
732732
"class": "Directory",
733733
"listing": [
734734
{
735-
"entryname": "hello.txt",
736-
"entry": {
737-
"class": "File",
738-
"location": "hello.txt"
739-
}
735+
"class": "File",
736+
"location": "hello.txt"
740737
},
741738
{
742-
"entryname": "goodbye.txt",
743-
"entry": {
744-
"class": "File",
745-
"location": "goodbye.txt"
746-
}
739+
"class": "File",
740+
"location": "goodbye.txt"
747741
}
748742
],
749743
}
@@ -785,3 +779,13 @@
785779
}
786780
tool: draft-4/stagefile.cwl
787781
doc: Test writable staged files.
782+
783+
- job: draft-4/file-literal.yml
784+
output:
785+
output_file:
786+
class: File
787+
checksum: sha1$d0e04ff6c413c7d57f9a0ca0a33cd3ab52e2dd9c
788+
location: output.txt
789+
size: 18
790+
tool: draft-4/cat3-tool.cwl
791+
doc: Test file literal as input

draft-4/draft-4/dir4-job.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ inf:
44
secondaryFiles:
55
- class: File
66
location: index.py
7-
- entryname: xtestdir
8-
entry:
9-
class: Directory
10-
location: testdir
7+
- class: Directory
8+
basename: xtestdir
9+
location: testdir

draft-4/draft-4/file-literal.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
file1:
2+
class: File
3+
contents: "Hello file literal"

draft-4/draft-4/search.cwl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ $graph:
99
requirements:
1010
- class: InitialWorkDirRequirement
1111
listing:
12-
input.txt: $(inputs.file)
12+
- entryname: input.txt
13+
entry: $(inputs.file)
1314
- class: InlineJavascriptRequirement
1415

1516
inputs:

draft-4/draft-4/stagefile.cwl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ cwlVersion: draft-4.dev3
33
requirements:
44
InitialWorkDirRequirement:
55
listing:
6-
- entryname: $(inputs.infile.basename)
7-
entry: $(inputs.infile)
6+
- entry: $(inputs.infile)
87
writable: true
98
inputs:
109
infile: File

draft-4/draft-4/template-tool.cwl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ requirements:
1010
- "var t = function(s) { return _.template(s)({'inputs': inputs}); };"
1111
- class: InitialWorkDirRequirement
1212
listing:
13-
foo.txt: >
14-
$(t("The file is <%= inputs.file1.path.split('/').slice(-1)[0] %>\n"))
13+
- entryname: foo.txt
14+
entry: $(t("The file is <%= inputs.file1.path.split('/').slice(-1)[0] %>\n"))
1515
inputs:
1616
- id: file1
1717
type: File

draft-4/salad/schema_salad/jsonld_context.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,52 @@ def salad_to_jsonld_context(j, schema_ctx):
175175
process_type(t, g, context, defaultBase, namespaces, defaultPrefix)
176176

177177
return (context, g)
178+
179+
def fix_jsonld_ids(obj, ids):
180+
# type: (Union[Dict[unicode, Any], List[Dict[unicode, Any]]], List[unicode]) -> None
181+
if isinstance(obj, dict):
182+
for i in ids:
183+
if i in obj:
184+
obj["@id"] = obj[i]
185+
for v in obj.values():
186+
fix_jsonld_ids(v, ids)
187+
if isinstance(obj, list):
188+
for entry in obj:
189+
fix_jsonld_ids(entry, ids)
190+
191+
def makerdf(workflow, wf, ctx):
192+
# type: (Union[str, unicode], Union[List[Dict[unicode, Any]], Dict[unicode, Any]], Loader.ContextType) -> Graph
193+
prefixes = {}
194+
idfields = []
195+
for k,v in ctx.iteritems():
196+
if isinstance(v, dict):
197+
url = v["@id"]
198+
else:
199+
url = v
200+
if url == "@id":
201+
idfields.append(k)
202+
doc_url, frg = urlparse.urldefrag(url)
203+
if "/" in frg:
204+
p, _ = frg.split("/")
205+
prefixes[p] = u"%s#%s/" % (doc_url, p)
206+
207+
if isinstance(wf, list):
208+
wf = {
209+
"@context": ctx,
210+
"@graph": wf
211+
}
212+
else:
213+
wf["@context"] = ctx
214+
215+
fix_jsonld_ids(wf, idfields)
216+
217+
g = Graph().parse(data=json.dumps(wf), format='json-ld', location=workflow)
218+
219+
# Bug in json-ld loader causes @id fields to be added to the graph
220+
for s,p,o in g.triples((None, URIRef("@id"), None)):
221+
g.remove((s, p, o))
222+
223+
for k2,v2 in prefixes.iteritems():
224+
g.namespace_manager.bind(k2, v2)
225+
226+
return g

0 commit comments

Comments
 (0)