Skip to content

Commit 6ebe351

Browse files
Merge pull request #14 from giannisdoukas/code-quality
improve code quality
2 parents cb64a53 + b38b995 commit 6ebe351

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

ipython2cwl/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
"""Compile IPython Jupyter Notebooks as CWL CommandLineTools"""
12
__version__ = "0.0.4"

ipython2cwl/cwltoolextractor.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131

3232
class AnnotatedVariablesExtractor(ast.NodeTransformer):
33+
"""AnnotatedVariablesExtractor removes the typing annotations
34+
from relative to ipython2cwl and identifies all the variables
35+
relative to an ipython2cwl typing annotation."""
3336
input_type_mapper: Dict[Tuple[str, ...], Tuple[str, str]] = {
3437
(CWLFilePathInput.__name__,): (
3538
'File',
@@ -67,11 +70,15 @@ class AnnotatedVariablesExtractor(ast.NodeTransformer):
6770
}
6871

6972
def __init__(self, *args, **kwargs):
73+
"""Create an AnnotatedVariablesExtractor"""
7074
super().__init__(*args, **kwargs)
7175
self.extracted_variables: List = []
7276
self.to_dump: List = []
7377

7478
def __get_annotation__(self, type_annotation):
79+
"""Parses the annotation and returns it in a canonical format.
80+
If the annotation was a string 'CWLStringInput' the function
81+
will return you the object."""
7582
annotation = None
7683
if isinstance(type_annotation, ast.Name):
7784
annotation = (type_annotation.id,)
@@ -164,7 +171,8 @@ def visit_AnnAssign(self, node):
164171
pass
165172
return node
166173

167-
def visit_Import(self, node: ast.Import):
174+
def visit_Import(self, node: ast.Import) -> Any:
175+
"""Remove ipython2cwl imports """
168176
names = []
169177
for name in node.names: # type: ast.alias
170178
if name.name == 'ipython2cwl' or name.name.startswith('ipython2cwl.'):
@@ -177,6 +185,7 @@ def visit_Import(self, node: ast.Import):
177185
return None
178186

179187
def visit_ImportFrom(self, node: ast.ImportFrom) -> Any:
188+
"""Remove ipython2cwl imports """
180189
if node.module == 'ipython2cwl' or (node.module is not None and node.module.startswith('ipython2cwl.')):
181190
return None
182191
return node
@@ -188,8 +197,7 @@ class AnnotatedIPython2CWLToolConverter:
188197
with the described inputs & outputs.
189198
"""
190199

191-
_code: str
192-
"""The annotated python code to convert."""
200+
_code: str # The annotated python code to convert.
193201

194202
def __init__(self, annotated_ipython_code: str):
195203
"""Creates an AnnotatedIPython2CWLToolConverter. If the annotated_ipython_code contains magic commands use the
@@ -198,7 +206,8 @@ def __init__(self, annotated_ipython_code: str):
198206
self._code = annotated_ipython_code
199207
extractor = AnnotatedVariablesExtractor()
200208
self._tree = extractor.visit(ast.parse(self._code))
201-
[self._tree.body.extend(d) for d in extractor.to_dump]
209+
for d in extractor.to_dump:
210+
self._tree.body.extend(d)
202211
self._tree = ast.fix_missing_locations(self._tree)
203212
self._variables = []
204213
for variable in extractor.extracted_variables: # type: _VariableNameTypePair

ipython2cwl/repo2cwl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
def _get_notebook_paths_from_dir(dir_path: str):
2525
notebooks_paths = []
26-
for path, subdirs, files in os.walk(dir_path):
26+
for path, _, files in os.walk(dir_path):
2727
for name in files:
2828
if name.endswith('.ipynb'):
2929
notebooks_paths.append(os.path.join(path, name))

0 commit comments

Comments
 (0)