|
7 | 7 | from collections import namedtuple
|
8 | 8 | from copy import deepcopy
|
9 | 9 | from pathlib import Path
|
10 |
| -from typing import Dict, Any, List |
| 10 | +from typing import Dict, Any, List, Tuple |
11 | 11 |
|
12 |
| -import astor |
13 |
| -import nbconvert |
| 12 | +import astor # type: ignore |
| 13 | +import nbconvert # type: ignore |
14 | 14 | import yaml
|
15 |
| -from nbformat.notebooknode import NotebookNode |
| 15 | +from nbformat.notebooknode import NotebookNode # type: ignore |
16 | 16 |
|
17 | 17 | from .iotypes import CWLFilePathInput, CWLBooleanInput, CWLIntInput, CWLStringInput, CWLFilePathOutput, \
|
18 | 18 | CWLDumpableFile, CWLDumpableBinaryFile, CWLDumpable
|
|
30 | 30 |
|
31 | 31 |
|
32 | 32 | class AnnotatedVariablesExtractor(ast.NodeTransformer):
|
33 |
| - input_type_mapper = { |
| 33 | + input_type_mapper: Dict[Tuple[str, ...], Tuple[str, str]] = { |
34 | 34 | (CWLFilePathInput.__name__,): (
|
35 | 35 | 'File',
|
36 | 36 | 'pathlib.Path',
|
@@ -177,7 +177,7 @@ def visit_Import(self, node: ast.Import):
|
177 | 177 | return None
|
178 | 178 |
|
179 | 179 | def visit_ImportFrom(self, node: ast.ImportFrom) -> Any:
|
180 |
| - if node.module == 'ipython2cwl' or node.module.startswith('ipython2cwl.'): |
| 180 | + if node.module == 'ipython2cwl' or (node.module is not None and node.module.startswith('ipython2cwl.')): |
181 | 181 | return None
|
182 | 182 | return node
|
183 | 183 |
|
@@ -299,14 +299,18 @@ def compile(self, filename: Path = Path('notebookAsCWLTool.tar')) -> str:
|
299 | 299 | """
|
300 | 300 | workdir = tempfile.mkdtemp()
|
301 | 301 | script_path = os.path.join(workdir, 'notebookTool')
|
302 |
| - cwl_path = os.path.join(workdir, 'tool.cwl') |
| 302 | + cwl_path: str = os.path.join(workdir, 'tool.cwl') |
303 | 303 | dockerfile_path = os.path.join(workdir, 'Dockerfile')
|
304 | 304 | setup_path = os.path.join(workdir, 'setup.py')
|
305 | 305 | requirements_path = os.path.join(workdir, 'requirements.txt')
|
306 |
| - with open(script_path, 'wb') as f: |
307 |
| - f.write(self._wrap_script_to_method(self._tree, self._variables).encode()) |
308 |
| - with open(cwl_path, 'w') as f: |
309 |
| - yaml.safe_dump(self.cwl_command_line_tool(), f, encoding='utf-8') |
| 306 | + with open(script_path, 'wb') as script_fd: |
| 307 | + script_fd.write(self._wrap_script_to_method(self._tree, self._variables).encode()) |
| 308 | + with open(cwl_path, 'w') as cwl_fd: |
| 309 | + yaml.safe_dump( |
| 310 | + self.cwl_command_line_tool(), |
| 311 | + cwl_fd, |
| 312 | + encoding='utf-8' |
| 313 | + ) |
310 | 314 | dockerfile = DOCKERFILE_TEMPLATE.format(
|
311 | 315 | python_version=f'python:{".".join(platform.python_version_tuple())}'
|
312 | 316 | )
|
|
0 commit comments