Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ script:
- pycodestyle --max-line-length=119 $(find ipython2cwl -name '*.py')
- coverage run --source ipython2cwl -m unittest discover tests
- coveralls
- make mypy
matrix:
include:
- name: "Python 3.7 on macOS 10.13"
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mypy:
mypy $$(find ipython2cwl -name '*.py')
26 changes: 15 additions & 11 deletions ipython2cwl/cwltoolextractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from collections import namedtuple
from copy import deepcopy
from pathlib import Path
from typing import Dict, Any, List
from typing import Dict, Any, List, Tuple

import astor
import nbconvert
import astor # type: ignore
import nbconvert # type: ignore
import yaml
from nbformat.notebooknode import NotebookNode
from nbformat.notebooknode import NotebookNode # type: ignore

from .iotypes import CWLFilePathInput, CWLBooleanInput, CWLIntInput, CWLStringInput, CWLFilePathOutput, \
CWLDumpableFile, CWLDumpableBinaryFile, CWLDumpable
Expand All @@ -30,7 +30,7 @@


class AnnotatedVariablesExtractor(ast.NodeTransformer):
input_type_mapper = {
input_type_mapper: Dict[Tuple[str, ...], Tuple[str, str]] = {
(CWLFilePathInput.__name__,): (
'File',
'pathlib.Path',
Expand Down Expand Up @@ -177,7 +177,7 @@ def visit_Import(self, node: ast.Import):
return None

def visit_ImportFrom(self, node: ast.ImportFrom) -> Any:
if node.module == 'ipython2cwl' or node.module.startswith('ipython2cwl.'):
if node.module == 'ipython2cwl' or (node.module is not None and node.module.startswith('ipython2cwl.')):
return None
return node

Expand Down Expand Up @@ -299,14 +299,18 @@ def compile(self, filename: Path = Path('notebookAsCWLTool.tar')) -> str:
"""
workdir = tempfile.mkdtemp()
script_path = os.path.join(workdir, 'notebookTool')
cwl_path = os.path.join(workdir, 'tool.cwl')
cwl_path: str = os.path.join(workdir, 'tool.cwl')
dockerfile_path = os.path.join(workdir, 'Dockerfile')
setup_path = os.path.join(workdir, 'setup.py')
requirements_path = os.path.join(workdir, 'requirements.txt')
with open(script_path, 'wb') as f:
f.write(self._wrap_script_to_method(self._tree, self._variables).encode())
with open(cwl_path, 'w') as f:
yaml.safe_dump(self.cwl_command_line_tool(), f, encoding='utf-8')
with open(script_path, 'wb') as script_fd:
script_fd.write(self._wrap_script_to_method(self._tree, self._variables).encode())
with open(cwl_path, 'w') as cwl_fd:
yaml.safe_dump(
self.cwl_command_line_tool(),
cwl_fd,
encoding='utf-8'
)
dockerfile = DOCKERFILE_TEMPLATE.format(
python_version=f'python:{".".join(platform.python_version_tuple())}'
)
Expand Down
12 changes: 6 additions & 6 deletions ipython2cwl/repo2cwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
from typing import List, Optional, Tuple, Dict
from urllib.parse import urlparse, ParseResult

import git
import nbformat
import git # type: ignore
import nbformat # type: ignore
import yaml
from git import Repo
from repo2docker import Repo2Docker
from repo2docker import Repo2Docker # type: ignore

from .cwltoolextractor import AnnotatedIPython2CWLToolConverter

Expand Down Expand Up @@ -68,8 +68,8 @@ def _store_jn_as_script(notebook_path: str, git_directory_absolute_path: str, bi
return tool, script_relative_path


def existing_path(path: str):
path = Path(path)
def existing_path(path_str: str):
path: Path = Path(path_str)
if not path.is_dir():
raise argparse.ArgumentTypeError(f'Directory: {str(path)} does not exists')
return path
Expand Down Expand Up @@ -159,7 +159,7 @@ def _repo2cwl(git_directory_path: Repo) -> Tuple[str, List[Dict]]:
bin_path,
r2d.output_image_spec
)
if cwl_command_line_tool is None:
if cwl_command_line_tool is None or script_name is None:
continue
cwl_command_line_tool['baseCommand'] = os.path.join('/app', 'cwl', 'bin', script_name)
tools.append(cwl_command_line_tool)
Expand Down
2 changes: 1 addition & 1 deletion ipython2cwl/requirements_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List

from pip._internal.operations import freeze
from pip._internal.operations import freeze # type: ignore


class RequirementsManager:
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ gitpython>=3.1.3
docker>=4.2.1
git+https://github.com/giannisdoukas/cwltool.git#egg=cwltool
pandas==1.0.5
mypy
2 changes: 1 addition & 1 deletion tests/repo-like/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PyYAML==5.3.1
PyYAML==5.3.1