Skip to content

Commit 0b0b68c

Browse files
committed
editing input_spec, adding a short output_spec section
1 parent 7ea9477 commit 0b0b68c

File tree

3 files changed

+107
-5
lines changed

3 files changed

+107
-5
lines changed

docs/input_spec.rst

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ Let's start from the previous example:
3535
3636
3737
In order to create an input specification, a new `SpecInfo` object has to be created.
38-
The field `name` specifiest the typo of the spec and it should be always "Input" for
38+
The field `name` specifies the type of the spec and it should be always "Input" for
3939
the input specification.
4040
The field `bases` specifies the "base specification" you want to use (can think about it as a
4141
`parent class`) and it will usually contains `ShellSpec` only, unless you want to build on top of
4242
your other specification (this will not be cover in this section).
4343
The part that should be always customised is the `fields` part.
4444
Each element of the `fields` is a separate input field that is added to the specification.
45-
In this example, a three-elements tuples - with name, type and dictionary with additional
45+
In this example, three-elements tuples - with name, type and dictionary with additional
4646
information - are used.
4747
But this is only one of the supported syntax, more options will be described below.
4848

@@ -86,9 +86,25 @@ However, we allow for shorter syntax, that does not include `attr.ib`:
8686
8787
Each of the shorter versions will be converted to the `(name, attr.ib(...)`.
8888
89+
90+
Types
91+
-----
92+
8993
Type can be provided as a simple python type (e.g. `str`, `int`, `float`, etc.)
9094
or can be more complex by using `typing.List`, `typing.Dict` and `typing.Union`.
9195
96+
There are also special types provided by Pydra:
97+
98+
- `File` and `Directory` - should be used in `input_spec` if the field is an existing file
99+
or directory.
100+
Pydra checks if the file or directory exists, and returns an error if it doesn't exist.
101+
102+
103+
- `MultiInputObj` - a special type that takes a any value and if the value is not a list it
104+
converts value to a 1-element list (it could be used together with `MultiOutputObj`
105+
in the `output_spec` to reverse the conversion of the output values).
106+
107+
92108
93109
Metadata
94110
--------
@@ -126,9 +142,6 @@ In the example we used multiple keys in the metadata dictionary including `help_
126142
`xor` (`list`):
127143
List of field names that are mutually exclusive with the field.
128144
129-
`keep_extension` (`bool`, default: `True`):
130-
A flag that specifies if the file extension should be removed from the field value.
131-
132145
`copyfile` (`bool`, default: `False`):
133146
If `True`, a hard link is created for the input file in the output directory.
134147
If hard link not possible, the file is copied to the output directory.
@@ -139,9 +152,16 @@ In the example we used multiple keys in the metadata dictionary including `help_
139152
`output_file_template` (`str`):
140153
If provided, the field is treated also as an output field and it is added to the output spec.
141154
The template can use other fields, e.g. `{file1}`.
155+
Used in order to create an output specification.
142156
143157
`output_field_name` (`str`, used together with `output_file_template`)
144158
If provided the field is added to the output spec with changed name.
159+
Used in order to create an output specification.
160+
161+
`keep_extension` (`bool`, default: `True`):
162+
A flag that specifies if the file extension should be removed from the field value.
163+
Used in order to create an output specification.
164+
145165
146166
`readonly` (`bool`, default: `False`):
147167
If `True` the input field can't be provided by the user but it aggregates other input fields

docs/output_spec.rst

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
.. _Output Specification section:
2+
3+
Output Specification
4+
====================
5+
6+
As it was mentioned in :ref:`shell_command_task`, the user can customize the input and output
7+
for the `ShellCommandTask`.
8+
In this section, the output specification will be covered.
9+
10+
11+
Instead of using field with `output_file_template` in the customized `input_spec` to specify an output field,
12+
a customized `output_spec` can be used, e.g.:
13+
14+
15+
.. code-block:: python
16+
17+
output_spec = SpecInfo(
18+
name="Output",
19+
fields=[
20+
(
21+
"out1",
22+
attr.ib(
23+
type=File,
24+
metadata={
25+
"output_file_template": "{inp1}",
26+
"help_string": "output file",
27+
"requires": ["inp1", "inp2"]
28+
},
29+
),
30+
)
31+
],
32+
bases=(ShellOutSpec,),
33+
)
34+
35+
ShellCommandTask(executable=executable,
36+
output_spec=output_spec)
37+
38+
39+
40+
Similarly as for `input_spec`, in order to create an output specification,
41+
a new `SpecInfo` object has to be created.
42+
The field `name` specifies the type of the spec and it should be always "Output" for
43+
the output specification.
44+
The field `bases` specifies the "base specification" you want to use (can think about it as a
45+
`parent class`) and it will usually contains `ShellOutSpec` only, unless you want to build on top of
46+
your other specification (this will not be cover in this section).
47+
The part that should be always customised is the `fields` part.
48+
Each element of the `fields` is a separate output field that is added to the specification.
49+
In this example, a three-elements tuple - with name, type and dictionary with additional
50+
information - is used.
51+
See :ref:`Input Specification section` for other recognized syntax for specification's fields
52+
and possible types.
53+
54+
55+
56+
Metadata
57+
--------
58+
59+
The metadata dictionary for `output_spec` can include:
60+
61+
`help_string` (`str`, mandatory):
62+
A short description of the input field. The same as in `input_spec`.
63+
64+
`output_file_template` (`str`):
65+
If provided, the field is treated also as an output field and it is added to the output spec.
66+
The template can use other fields, e.g. `{file1}`. The same as in `input_spec`.
67+
68+
`output_field_name` (`str`, used together with `output_file_template`)
69+
If provided the field is added to the output spec with changed name.
70+
The same as in `input_spec`.
71+
72+
`keep_extension` (`bool`, default: `True`):
73+
A flag that specifies if the file extension should be removed from the field value.
74+
The same as in `input_spec`.
75+
76+
77+
`requires` (`list`):
78+
List of field names that are required to create a specific output.
79+
The fields do not have to be a part of the `output_file_template` and
80+
if any field from the list is not provided in the input, a `NOTHING` is returned for the specific output.
81+
This has a different meaning than the `requires` form the `input_spec`.

docs/user_guide.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ User Guide
99
state
1010
combiner
1111
input_spec
12+
output_spec

0 commit comments

Comments
 (0)