Skip to content

Commit a39f336

Browse files
committed
add documentation
1 parent 3982260 commit a39f336

File tree

2 files changed

+160
-9
lines changed

2 files changed

+160
-9
lines changed

docs/index.rst

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,53 @@ IPython2CWL is a tool for converting `IPython <https://ipython.org/>`_ Jupyter N
3030
------------------------------------------------------------------------------------------
3131

3232
IPython2CWL is based on `repo2docker <https://github.com/jupyter/repo2docker>`_, the same tool
33-
used by `mybinder <https://mybinder.org/>`_. Now, by writing Jupyter Notebook and publish them, including repo2docker
34-
configuration, the community can not only execute the notebooks remotely but also to use them as steps in scientific
33+
used by `mybinder <https://mybinder.org/>`_. Now, by writing Jupyter Notebook and publishing them, including repo2docker
34+
configuration, the community can not only execute the notebooks remotely but can also use them as steps in scientific
3535
workflows.
3636

37-
* Install ipython2cwl: :code:`pip install python2cwl`
37+
* `Install ipython2cwl <https://pypi.org/project/ipython2cwl/>`_: :code:`pip install ipython2cwl`
3838
* Ensure that you have docker running
3939
* Create a directory to store the generated cwl files, for example cwlbuild
4040
* Execute :code:`jupyter repo2cwl https://github.com/giannisdoukas/cwl-annotated-jupyter-notebook.git -o cwlbuild`
4141

42-
Indices and tables
43-
==================
42+
HOW IT WORKS?
43+
------------------
44+
45+
IPython2CWL parses each IPython notebook and finds the variables with the typing annotations. For each input variable,
46+
the assigment of that variable will be generalised as a command line argument. Each output variable will be mapped
47+
in the cwl description as an output file.
48+
49+
SUPPORTED TYPES
50+
------------------
51+
52+
.. automodule:: ipython2cwl.iotypes
53+
:members:
54+
55+
56+
THAT'S COOL! WHAT ABOUT LIST & OPTIONAL ARGUMENTS?
57+
"""""""""""""""""""""""""""""""""""""""""""""""""""
58+
59+
The basic input data types can be combined with the List and Optional annotations. For example, write the following
60+
annotation:
61+
62+
.. code-block:: python
63+
64+
file_inputs: List[CWLFilePathInput] = ['data1.txt', 'data2.txt', 'data3.txt']
65+
example: Optional[CWLStringInput] = None
66+
67+
68+
SEEMS INTERESTING! WHAT ABOUT A DEMO?
69+
----------------------------------------
70+
71+
If you would like to see a demo before you want to start annotating your notebooks check here!
72+
`github.com/giannisdoukas/ipython2cwl-demo <https://github.com/giannisdoukas/ipython2cwl-demo>`_
73+
74+
75+
WHAT IF I WANT TO VALIDATE THAT THE GENERATED SCRIPTS ARE CORRECT?
76+
------------------------------------------------------------------
77+
78+
All the generated scripts are stored in the docker image under the directory :code:`/app/cwl/bin`. You can see the list
79+
of the files by running :code:`docker run [IMAGE_ID] find /app/cwl/bin/ -type f`.
80+
81+
4482

45-
* :ref:`genindex`
46-
* :ref:`modindex`
47-
* :ref:`search`

ipython2cwl/iotypes.py

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
"""
2+
3+
Basic Data Types
4+
^^^^^^^^^^^^^^^^^
5+
6+
Each variable can be an input or an output. The basic data types are:
7+
8+
* Inputs:
9+
10+
* CWLFilePathInput
11+
12+
* CWLBooleanInput
13+
14+
* CWLStringInput
15+
16+
* CWLIntInput
17+
18+
* Outputs:
19+
20+
* CWLFilePathOutput
21+
22+
* CWLDumpableFile
23+
24+
* CWLDumpableBinaryFile
25+
26+
27+
Complex Dumpables Types
28+
^^^^^^^^^^^^^^^^^^^^^^^^
29+
30+
Dumpables are variables which are able to be written to a file, but the jupyter notebook developer
31+
does not want to write it, for example to avoid the IO overhead. To bypass that, you can use
32+
Dumpables annotation. See :func:`~iotypes.CWLDumpable.dump` for more details.
33+
34+
"""
135
from typing import Callable
236

337

@@ -6,18 +40,50 @@ class _CWLInput:
640

741

842
class CWLFilePathInput(str, _CWLInput):
43+
"""Use that hint to annotate that a variable is a string-path input. You can use the typing annotation
44+
as a string by importing it. At the generated script a command line argument with the name of the variable
45+
will be created and the assignment of value will be generalised.
46+
47+
>>> dataset1: CWLFilePathInput = './data/data.csv'
48+
>>> dataset2: 'CWLFilePathInput' = './data/data.csv'
49+
50+
"""
951
pass
1052

1153

1254
class CWLBooleanInput(_CWLInput):
55+
"""Use that hint to annotate that a variable is a boolean input. You can use the typing annotation
56+
as a string by importing it. At the generated script a command line argument with the name of the variable
57+
will be created and the assignment of value will be generalised.
58+
59+
>>> dataset1: CWLBooleanInput = True
60+
>>> dataset2: 'CWLBooleanInput' = False
61+
62+
"""
1363
pass
1464

1565

1666
class CWLStringInput(str, _CWLInput):
67+
"""Use that hint to annotate that a variable is a string input. You can use the typing annotation
68+
as a string by importing it. At the generated script a command line argument with the name of the variable
69+
will be created and the assignment of value will be generalised.
70+
71+
>>> dataset1: CWLBooleanInput = 'this is a message input'
72+
>>> dataset2: 'CWLBooleanInput' = 'yet another message input'
73+
74+
"""
1775
pass
1876

1977

2078
class CWLIntInput(_CWLInput):
79+
"""Use that hint to annotate that a variable is a integer input. You can use the typing annotation
80+
as a string by importing it. At the generated script a command line argument with the name of the variable
81+
will be created and the assignment of value will be generalised.
82+
83+
>>> dataset1: CWLBooleanInput = 1
84+
>>> dataset2: 'CWLBooleanInput' = 2
85+
86+
"""
2187
pass
2288

2389

@@ -26,19 +92,69 @@ class _CWLOutput:
2692

2793

2894
class CWLFilePathOutput(str, _CWLOutput):
95+
"""Use that hint to annotate that a variable is a string-path to an output file. You can use the typing annotation
96+
as a string by importing it. The generated file will be mapped as a CWL output.
97+
98+
>>> filename: CWLBooleanInput = 'data.csv'
99+
100+
"""
29101
pass
30102

31103

32104
class CWLDumpable(_CWLOutput):
105+
"""Use that class to define custom Dumpables variables."""
33106

34107
@classmethod
35-
def dump(cls, dumper: Callable, *args, **kwargs):
108+
def dump(cls, dumper: Callable, filename, *args, **kwargs):
109+
"""
110+
Set the function to be used to dump the variable to a file.
111+
112+
>>> import pandas
113+
>>> d: CWLDumpable.dump(d.to_csv, "dumpable.csv", sep="\\t", index=False) = pandas.DataFrame(
114+
... [[1,2,3], [4,5,6], [7,8,9]]
115+
... )
116+
117+
In that example the converter will add at the end of the script the following line:
118+
>>> d.to_csv("dumpable.csv", sep="\\t", index=False)
119+
120+
:param dumper: The function that has to be called to write the variable to a file.
121+
:param filename: The name of the generated file. That string must be the first argument
122+
in the dumper function. That file will also be mapped as an output in
123+
the CWL file.
124+
:param args: Any positional arguments you want to pass to dumper after the filename
125+
:param kwargs: Any keyword arguments you want to pass to dumper
126+
"""
36127
return _CWLOutput
37128

38129

39130
class CWLDumpableFile(CWLDumpable):
131+
"""Use that annotation to define that a variable should be dumped to a text file. For example for the annotation:
132+
133+
>>> data: CWLDumpableFile = "this is text data"
134+
135+
136+
the converter will append at the end of the script the following lines:
137+
138+
139+
>>> with open('data', 'w') as f:
140+
... f.write(data)
141+
142+
143+
and at the CWL, the data, will be mapped as a output.
144+
"""
40145
pass
41146

42147

43148
class CWLDumpableBinaryFile(CWLDumpable):
149+
"""Use that annotation to define that a variable should be dumped to a binary file. For example for the annotation:
150+
151+
>>> data: CWLDumpableBinaryFile = b"this is text data"
152+
153+
the converter will append at the end of the script the following lines:
154+
155+
>>> with open('data', 'wb') as f:
156+
... f.write(data)
157+
158+
and at the CWL, the data, will be mapped as a output.
159+
"""
44160
pass

0 commit comments

Comments
 (0)