Skip to content

Commit ae3d167

Browse files
committed
freshen types
1 parent 3bfe919 commit ae3d167

File tree

9 files changed

+227
-8
lines changed

9 files changed

+227
-8
lines changed

Makefile

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# This file is part of cwl-upgrader
2+
# https://github.com/common-workflow-language/cwl-upgrader/, and is
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
18+
# make pep8 to check for basic Python code compliance
19+
# make autopep8 to fix most pep8 errors
20+
# make pylint to check Python code for enhanced compliance including naming
21+
# and documentation
22+
# make coverage-report to check coverage of the python scripts by the tests
23+
24+
MODULE=cwl-upgrader
25+
26+
# `SHELL=bash` Will break Titus's laptop, so don't use BASH-isms like
27+
# `[[` conditional expressions.
28+
PYSOURCES=$(wildcard ${MODULE}/**.py tests/*.py) setup.py
29+
DEVPKGS=pep8 diff_cover autopep8 pylint coverage pep257
30+
MYPYPATH=typeshed/2or3
31+
MYPYFLAGS=--disallow-untyped-calls --disallow-untyped-defs \
32+
--warn-incomplete-stub --warn-redundant-casts
33+
34+
VERSION=$(shell git describe --tags --dirty | sed s/v//)
35+
36+
## all : default task
37+
all: ./setup.py develop
38+
39+
## help : print this help message and exit
40+
help: Makefile
41+
@sed -n 's/^##//p' $<
42+
43+
## install-dep : install most of the development dependencies via pip
44+
install-dep: install-dependencies
45+
46+
install-dependencies:
47+
pip install --upgrade $(DEVPKGS)
48+
pip install -r requirements.txt
49+
50+
## install : install the ${MODULE} module and schema-salad-tool
51+
install: FORCE
52+
./setup.py build install
53+
54+
## dist : create a module package for distribution
55+
dist: dist/${MODULE}-$(VERSION).tar.gz
56+
57+
dist/${MODULE}-$(VERSION).tar.gz: $(SOURCES)
58+
./setup.py sdist
59+
60+
## clean : clean up all temporary / machine-generated files
61+
clean: FORCE
62+
rm -f ${MODILE}/*.pyc tests/*.pyc
63+
./setup.py clean --all || true
64+
rm -Rf .coverage
65+
rm -f diff-cover.html
66+
67+
## pep8 : check Python code style
68+
pep8: $(PYSOURCES)
69+
pep8 --exclude=_version.py --show-source --show-pep8 $^ || true
70+
71+
pep8_report.txt: $(PYSOURCES)
72+
pep8 --exclude=_version.py $^ > $@ || true
73+
74+
diff_pep8_report: pep8_report.txt
75+
diff-quality --violations=pep8 pep8_report.txt
76+
77+
## pep257 : check Python code style
78+
pep257: $(PYSOURCES)
79+
pep257 --ignore=D100,D101,D102,D103 $^ || true
80+
81+
pep257_report.txt: $(PYSOURCES)
82+
pep257 setup.py $^ > $@ 2>&1 || true
83+
84+
diff_pep257_report: pep257_report.txt
85+
diff-quality --violations=pep8 pep257_report.txt
86+
87+
## autopep8 : fix most Python code indentation and formatting
88+
autopep8: $(PYSOURCES)
89+
autopep8 --recursive --in-place --ignore E309 $^
90+
91+
# A command to automatically run astyle and autopep8 on appropriate files
92+
## format : check/fix all code indentation and formatting (runs autopep8)
93+
format: autopep8
94+
# Do nothing
95+
96+
## pylint : run static code analysis on Python code
97+
pylint: $(PYSOURCES)
98+
pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \
99+
$^ || true
100+
101+
pylint_report.txt: ${PYSOURCES}
102+
pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \
103+
$^ > $@ || true
104+
105+
diff_pylint_report: pylint_report.txt
106+
diff-quality --violations=pylint pylint_report.txt
107+
108+
.coverage: $(PYSOURCES)
109+
coverage run --branch --source=${MODULE} setup.py test
110+
111+
coverage.xml: .coverage
112+
coverage xml
113+
114+
coverage.html: htmlcov/index.html
115+
116+
htmlcov/index.html: .coverage
117+
coverage html
118+
@echo Test coverage of the Python code is now in htmlcov/index.html
119+
120+
coverage-report: .coverage
121+
coverage report
122+
123+
diff-cover: coverage.xml
124+
diff-cover $^
125+
126+
diff-cover.html: coverage.xml
127+
diff-cover $^ --html-report $@
128+
129+
## test : run the ${MODULE} test suite
130+
test: FORCE
131+
python setup.py test
132+
133+
sloccount.sc: ${PYSOURCES} Makefile
134+
sloccount --duplicates --wide --details $^ > $@
135+
136+
## sloccount : count lines of code
137+
sloccount: ${PYSOURCES} Makefile
138+
sloccount $^
139+
140+
list-author-emails:
141+
@echo 'name, E-Mail Address'
142+
@git log --format='%aN,%aE' | sort -u | grep -v 'root'
143+
144+
mypy: ${PYSOURCES}
145+
MYPYPATH=${MYPYPATH} mypy ${MYPYFLAGS} cwlupgrader/
146+
MYPYPATH=${MYPYPATH} mypy --py2 ${MYPYFLAGS} cwlupgrader/
147+
148+
jenkins:
149+
rm -Rf env && virtualenv env
150+
. env/bin/activate ; \
151+
pip install -U setuptools pip wheel ; \
152+
${MAKE} install-dep coverage.html coverage.xml pep257_report.txt \
153+
sloccount.sc pep8_report.txt pylint_report.txt
154+
if ! test -d env3 ; then virtualenv -p python3 env3 ; fi
155+
. env3/bin/activate ; \
156+
pip install -U mypy-lang; ${MAKE} mypy
157+
158+
FORCE:

cwlupgrader/main.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python
22

3-
from __future__ import print_function, unicode_literals
3+
from __future__ import print_function
44
import ruamel.yaml
5-
from typing import Any, Dict
6-
from collections import Mapping, Sequence
5+
from typing import Any, Dict, Union
6+
from collections import Mapping, MutableMapping, Sequence
77
import sys
88
import copy
99

@@ -15,12 +15,12 @@ def main(): # type: () -> int
1515
print(ruamel.yaml.round_trip_dump(document))
1616
return 0
1717

18-
def draft3_to_v1_0(document): # type: (Dict[unicode, Any]) -> None
18+
def draft3_to_v1_0(document): # type: (Dict[str, Any]) -> None
1919
_draft3_to_v1_0(document)
2020
document['cwlVersion'] = 'v1.0'
2121

2222
def _draft3_to_v1_0(document):
23-
# type: (Dict[unicode, Any]) -> Dict[unicode, Any]
23+
# type: (MutableMapping[str, Any]) -> MutableMapping[str, Any]
2424
if "class" in document:
2525
if document["class"] == "Workflow":
2626
for out in document["outputs"]:
@@ -52,12 +52,12 @@ def _draft3_to_v1_0(document):
5252
del document["description"]
5353

5454
for key, value in document.items():
55-
if isinstance(value, Mapping):
55+
if isinstance(value, MutableMapping):
5656
document[key] = _draft3_to_v1_0(value)
5757

5858
return document
5959

60-
def setupCLTMappings(document): # type: (Dict[unicode, Any]) -> None
60+
def setupCLTMappings(document): # type: (MutableMapping[str, Any]) -> None
6161
for paramType in ['inputs', 'outputs']:
6262
params = {}
6363
for param in document[paramType]:
@@ -71,7 +71,7 @@ def setupCLTMappings(document): # type: (Dict[unicode, Any]) -> None
7171
document[paramType] = params
7272

7373
def shortenType(typeObj):
74-
# type: (List[Any]) -> Union[Unicode, List[Any]]
74+
# type: (List[Any]) -> Union[str, List[Any]]
7575
if isinstance(typeObj, str) or not isinstance(typeObj, Sequence):
7676
return typeObj
7777
newType = []

typeshed/2or3/ruamel/__init__.py

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Stubs for ruamel.yaml (Python 2)
2+
#
3+
# NOTE: This dynamically typed stub was automatically generated by stubgen.
4+
5+
from typing import Any
6+
from .cyaml import *
7+
from .main import *
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Stubs for ruamel.yaml.cyaml (Python 2)
2+
#
3+
# NOTE: This dynamically typed stub was automatically generated by stubgen.
4+
5+
from .loader import SafeLoader
6+
7+
class CSafeLoader(SafeLoader):
8+
pass
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Stubs for ruamel.yaml.error (Python 2)
2+
#
3+
# NOTE: This dynamically typed stub was automatically generated by stubgen.
4+
5+
from typing import Any
6+
7+
class YAMLError(Exception): ...
8+
9+
class MarkedYAMLError(YAMLError): ...
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Stubs for ruamel.yaml.loader (Python 2)
2+
#
3+
# NOTE: This dynamically typed stub was automatically generated by stubgen.
4+
5+
class Loader():
6+
pass
7+
8+
class SafeLoader(Loader):
9+
pass

typeshed/2or3/ruamel/yaml/main.pyi

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Stubs for ruamel.yaml.main (Python 2)
2+
#
3+
# NOTE: This dynamically typed stub was automatically generated by stubgen.
4+
5+
from typing import Any, AnyStr, BinaryIO, IO, List, Tuple, Union
6+
from ruamel.yaml.loader import *
7+
8+
VersionType = Union[List[int], str, Tuple[int, int]]
9+
StreamType = Union[BinaryIO, IO[str]]
10+
11+
def load(stream: StreamType,
12+
Loader: Any =...,
13+
version: VersionType = None) -> Any: ...
14+
15+
def round_trip_load(stream: StreamType,
16+
version: VersionType = None) -> Any: ...
17+
18+
def dump(data: Any) -> Any: ...
19+
20+
def round_trip_dump(data: Any) -> Any: ...
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Stubs for ruamel.yaml.parser (Python 2)
2+
#
3+
# NOTE: This dynamically typed stub was automatically generated by stubgen.
4+
5+
from typing import Any
6+
from ruamel.yaml.error import MarkedYAMLError
7+
8+
class ParserError(MarkedYAMLError): ...

0 commit comments

Comments
 (0)