Skip to content

Commit 7d22590

Browse files
authored
Merge pull request #464 from common-workflow-language/unicode_literal_usage
turn on Python 3 on travis CI
2 parents afda757 + eeb85d9 commit 7d22590

File tree

16 files changed

+63
-226
lines changed

16 files changed

+63
-226
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ sudo: false
22
language: python
33
python:
44
- 2.7
5-
# - 3.4
5+
- 3.3
6+
- 3.4
67
- 3.5
7-
# - 3.6
8+
- 3.6
89
os:
910
- linux
10-
1111
install:
1212
- pip install tox-travis
1313
script: tox
14-
notifications:
15-
email: false
1614
branches:
1715
only:
1816
- master
17+
notifications:
18+
email: false

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ mypy2: ${PYSOURCES}
161161
ln -s $(shell python -c 'from __future__ import print_function; import schema_salad; import os.path; print(os.path.dirname(schema_salad.__file__))') \
162162
typeshed/2and3/schema_salad
163163
MYPYPATH=$MYPYPATH:typeshed/2.7:typeshed/2and3 mypy --py2 --disallow-untyped-calls \
164-
--warn-redundant-casts --warn-unused-ignores \
164+
--warn-redundant-casts \
165165
cwltool
166166

167167
mypy3: ${PYSOURCES}
@@ -172,7 +172,7 @@ mypy3: ${PYSOURCES}
172172
ln -s $(shell python3 -c 'from __future__ import print_function; import schema_salad; import os.path; print(os.path.dirname(schema_salad.__file__))') \
173173
typeshed/2and3/schema_salad
174174
MYPYPATH=$MYPYPATH:typeshed/3:typeshed/2and3 mypy --disallow-untyped-calls \
175-
--warn-redundant-casts --warn-unused-ignores \
175+
--warn-redundant-casts \
176176
cwltool
177177

178178
FORCE:

cwltool/builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def __init__(self): # type: () -> None
6060
self.job_script_provider = None # type: Any
6161

6262
def build_job_script(self, commands):
63-
# type: (List[str]) -> Text
64-
build_job_script_method = getattr(self.job_script_provider, "build_job_script", None) # type: Callable[[Builder, List[str]], Text]
63+
# type: (List[bytes]) -> Text
64+
build_job_script_method = getattr(self.job_script_provider, "build_job_script", None) # type: Callable[[Builder, List[bytes]], Text]
6565
if build_job_script_method:
6666
return build_job_script_method(self, commands)
6767
else:

cwltool/docker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import subprocess
66
import sys
77
import tempfile
8+
from io import open
89
from typing import Dict, List, Text
910

1011
import requests
@@ -56,7 +57,7 @@ def get_image(dockerRequirement, pull_image, dry_run=False):
5657
found = True
5758
elif "dockerFile" in dockerRequirement:
5859
dockerfile_dir = str(tempfile.mkdtemp())
59-
with open(os.path.join(dockerfile_dir, "Dockerfile"), str("w")) as df:
60+
with open(os.path.join(dockerfile_dir, "Dockerfile"), "wb") as df:
6061
df.write(dockerRequirement["dockerFile"].encode('utf-8'))
6162
cmd = ["docker", "build", "--tag=%s" %
6263
str(dockerRequirement["dockerImageId"]), dockerfile_dir]
@@ -70,7 +71,7 @@ def get_image(dockerRequirement, pull_image, dry_run=False):
7071
if not dry_run:
7172
if os.path.exists(dockerRequirement["dockerLoad"]):
7273
_logger.info(u"Loading docker image from %s", dockerRequirement["dockerLoad"])
73-
with open(dockerRequirement["dockerLoad"], str("rb")) as f:
74+
with open(dockerRequirement["dockerLoad"], "rb") as f:
7475
loadproc = subprocess.Popen(cmd, stdin=f, stdout=sys.stderr)
7576
else:
7677
loadproc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=sys.stderr)

cwltool/expression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def jshead(engineConfig, rootvars):
2222
# TODO: need to make sure the `rootvars dict`
2323
# contains no bytes type in the first place.
2424
if six.PY3:
25-
rootvars = bytes2str_in_dicts(rootvars) # type -> ignore
25+
rootvars = bytes2str_in_dicts(rootvars) # type: ignore
2626

2727
return u"\n".join(engineConfig + [u"var %s = %s;" % (k, json.dumps(v, indent=4)) for k, v in rootvars.items()])
2828

cwltool/job.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import subprocess
1111
import sys
1212
import tempfile
13+
from io import open
1314
from typing import (IO, Any, Callable, Dict, Iterable, List, MutableMapping, Text,
1415
Tuple, Union, cast)
1516

@@ -22,6 +23,7 @@
2223
from .pathmapper import PathMapper
2324
from .process import (UnsupportedRequirement, empty_subtree, get_feature,
2425
stageFiles)
26+
from .utils import bytes2str_in_dicts
2527

2628
_logger = logging.getLogger("cwltool")
2729

@@ -222,6 +224,7 @@ def _execute(self, runtime, env, rm_tmpdir=True, move_outputs="move"):
222224
relink_initialworkdir(self.generatemapper, inplace_update=self.inplace_update)
223225

224226
outputs = self.collect_outputs(self.outdir)
227+
outputs = bytes2str_in_dicts(outputs) # type: ignore
225228

226229
except OSError as e:
227230
if e.errno == 2:
@@ -400,7 +403,7 @@ def run(self, pull_image=True, rm_container=True,
400403

401404

402405
def _job_popen(
403-
commands, # type: List[str]
406+
commands, # type: List[bytes]
404407
stdin_path, # type: Text
405408
stdout_path, # type: Text
406409
stderr_path, # type: Text
@@ -463,9 +466,8 @@ def _job_popen(
463466
job_script_contents = SHELL_COMMAND_TEMPLATE
464467

465468
env_copy = {}
466-
key = None # type: Union[Text, bytes]
469+
key = None # type: Any
467470
for key in env:
468-
key = key.encode("utf-8")
469471
env_copy[key] = env[key]
470472

471473
job_description = dict(

cwltool/load_tool.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def fetch_document(argsworkflow, # type: Union[Text, Dict[Text, Any]]
4141
# type: (...) -> Tuple[Loader, CommentedMap, Text]
4242
"""Retrieve a CWL document."""
4343

44-
document_loader = Loader(jobloaderctx,
45-
fetcher_constructor=fetcher_constructor)
44+
document_loader = Loader(jobloaderctx, fetcher_constructor=fetcher_constructor) # type: ignore
4645

4746
uri = None # type: Text
4847
workflowobj = None # type: CommentedMap

cwltool/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ def load_job_order(args, t, stdin, print_input_deps=False, relative_deps=False,
504504

505505
_jobloaderctx = jobloaderctx.copy()
506506
_jobloaderctx.update(t.metadata.get("$namespaces", {}))
507-
loader = Loader(_jobloaderctx, fetcher_constructor=fetcher_constructor)
507+
loader = Loader(_jobloaderctx, fetcher_constructor=fetcher_constructor) # type: ignore
508508

509509
if len(args.job_order) == 1 and args.job_order[0][0] != "-":
510510
job_order_file = args.job_order[0]

cwltool/process.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import tempfile
1414
import uuid
1515
from collections import Iterable
16+
from io import open
1617
from functools import cmp_to_key
1718
from typing import (Any, Callable, Dict, Generator, List, Set, Text,
1819
Tuple, Union, cast)

cwltool/stdfsaccess.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import absolute_import
22
import glob
33
import os
4-
from typing import BinaryIO, List, Text, IO
4+
from typing import BinaryIO, List, Union, Text, IO, overload
55

66
import six
77
from six.moves import urllib
@@ -24,7 +24,17 @@ def _abs(self, p): # type: (Text) -> Text
2424
def glob(self, pattern): # type: (Text) -> List[Text]
2525
return [file_uri(str(self._abs(l))) for l in glob.glob(self._abs(pattern))]
2626

27-
def open(self, fn, mode): # type: (Text, str) -> IO[bytes]
27+
# overload is related to mypy type checking and in no way
28+
# modifies the behaviour of the function.
29+
@overload
30+
def open(self, fn, mode='rb'): # type: (Text, str) -> IO[bytes]
31+
pass
32+
33+
@overload
34+
def open(self, fn, mode='r'): # type: (Text, str) -> IO[str]
35+
pass
36+
37+
def open(self, fn, mode):
2838
return open(self._abs(fn), mode)
2939

3040
def exists(self, fn): # type: (Text) -> bool

0 commit comments

Comments
 (0)