Skip to content

Commit 290486d

Browse files
authored
Upgrade to mypy 0.600 (#174)
* appveyor speedups * escape the CWD, normalize paths on Windows
1 parent f2c4853 commit 290486d

File tree

10 files changed

+100
-74
lines changed

10 files changed

+100
-74
lines changed

appveyor.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
version: .{build}-{branch}
22

3+
cache:
4+
- '%LOCALAPPDATA%\pip\Cache'
5+
36
environment:
47

58
matrix:
6-
- PYTHON: "C:\\Python27"
7-
PYTHON_VERSION: "2.7.x"
8-
PYTHON_ARCH: "32"
9-
109
- PYTHON: "C:\\Python27-x64"
1110
PYTHON_VERSION: "2.7.x"
1211
PYTHON_ARCH: "64"
@@ -19,18 +18,26 @@ environment:
1918
PYTHON_VERSION: "3.5.x"
2019
PYTHON_ARCH: "64"
2120

21+
- PYTHON: "C:\\Python36-x64"
22+
PYTHON_VERSION: "3.6.x"
23+
PYTHON_ARCH: "64"
24+
2225
install:
2326
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
24-
- "python --version"
25-
- "pip install --disable-pip-version-check --user --upgrade pip==9.0.3"
26-
- "pip install --disable-pip-version-check --user --upgrade setuptools"
27+
- pip install --disable-pip-version-check "setuptools>=27.3"
2728

2829
build_script:
29-
- "%CMD_IN_ENV% pip install ."
30-
30+
- |
31+
%PYTHON%\\python.exe -m pip install . wheel pytest pytest-xdist"
3132
3233
test_script:
33-
- "%CMD_IN_ENV% python setup.py test"
34+
- |
35+
%PYTHON%\\python.exe setup.py test --addopts "--verbose -p no:cacheprovider --junit-xml=tests.xml -n2"
36+
37+
on_finish:
38+
- ps: |
39+
$wc = New-Object 'System.Net.WebClient'
40+
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($Env:APPVEYOR_JOB_ID)", (Resolve-Path .\tests.xml))
3441
3542
branches:
3643
only:

mypy.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
[mypy]
2+
13
[mypy-ruamel.*]
2-
ignore_errors = True
4+
ignore_errors = True

mypy_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mypy==0.520
1+
mypy==0.600

schema_salad/codegen.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .python_codegen import PythonCodeGen
1111
from .java_codegen import JavaCodeGen
1212
from .ref_resolver import Loader
13-
from typing import List, Dict, Text, Any, Union, Text
13+
from typing import Any, Dict, List, Optional, Text, Union
1414
from ruamel.yaml.comments import CommentedSeq, CommentedMap
1515

1616
class GoCodeGen(object):
@@ -26,13 +26,14 @@ def codegen(lang, # type: str
2626

2727
j = schema.extend_and_specialize(i, loader)
2828

29-
cg = None # type: CodeGenBase
29+
cg = None # type: Optional[CodeGenBase]
3030
if lang == "python":
3131
cg = PythonCodeGen(sys.stdout)
3232
elif lang == "java":
3333
cg = JavaCodeGen(schema_metadata.get("$base", schema_metadata.get("id")))
3434
else:
3535
raise Exception("Unsupported code generation language '%s'" % lang)
36+
assert cg is not None
3637

3738
cg.prologue()
3839

@@ -52,7 +53,7 @@ def codegen(lang, # type: str
5253
if rec.get("documentRoot"):
5354
documentRoots.append(rec["name"])
5455
cg.begin_class(rec["name"], aslist(rec.get("extends", [])), rec.get("doc"),
55-
rec.get("abstract"))
56+
rec.get("abstract", False))
5657
cg.add_vocab(shortname(rec["name"]), rec["name"])
5758

5859
for f in rec.get("fields", []):
@@ -73,7 +74,7 @@ def codegen(lang, # type: str
7374
if jld.get("typeDSL"):
7475
tl = cg.typedsl_loader(tl, refScope)
7576
elif jld.get("_type") == "@id":
76-
tl = cg.uri_loader(tl, jld.get("identity"), False, refScope)
77+
tl = cg.uri_loader(tl, jld.get("identity", False), False, refScope)
7778
elif jld.get("_type") == "@vocab":
7879
tl = cg.uri_loader(tl, False, True, refScope)
7980

schema_salad/main.py

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
from .ref_resolver import Loader, file_uri
2929
_logger = logging.getLogger("salad")
3030

31-
from rdflib.plugin import register, Parser
31+
from rdflib.plugin import register
32+
from rdflib.parser import Parser
3233
register('json-ld', Parser, 'rdflib_jsonld.parser', 'JsonLDParser')
3334

3435

@@ -39,7 +40,7 @@ def printrdf(workflow, # type: str
3940
):
4041
# type: (...) -> None
4142
g = jsonld_context.makerdf(workflow, wf, ctx)
42-
print(g.serialize(format=sr, encoding='utf-8').decode('utf-8'))
43+
print(g.serialize(format=sr, encoding='utf-8').decode('utf-8')) # type: ignore
4344

4445
def regex_chunk(lines, regex):
4546
# type: (List[str], Pattern[str]) -> List[List[str]]
@@ -61,21 +62,20 @@ def chunk_messages(message): # type: (str) -> List[Tuple[int, str]]
6162
for chun in regex_chunk(message.splitlines(), file_regex):
6263
fst = chun[0]
6364
mat = file_regex.match(fst)
64-
place = mat.group(1)
65-
indent = len(mat.group(2))
66-
67-
lst = [mat.group(3)]+chun[1:]
68-
if [x for x in lst if item_regex.match(x)]:
69-
for item in regex_chunk(lst, item_regex):
70-
msg = re.sub(item_regex, '', "\n".join(item))
71-
arr.append((indent, place+' '+re.sub(r'[\n\s]+',
72-
' ',
73-
msg)))
74-
else:
75-
msg = re.sub(item_regex, '', "\n".join(lst))
76-
arr.append((indent, place+' '+re.sub(r'[\n\s]+',
77-
' ',
78-
msg)))
65+
if mat:
66+
place = mat.group(1)
67+
indent = len(mat.group(2))
68+
69+
lst = [mat.group(3)]+chun[1:]
70+
if [x for x in lst if item_regex.match(x)]:
71+
for item in regex_chunk(lst, item_regex):
72+
msg = re.sub(item_regex, '', "\n".join(item))
73+
arr.append((indent, place+' '+re.sub(
74+
r'[\n\s]+', ' ', msg)))
75+
else:
76+
msg = re.sub(item_regex, '', "\n".join(lst))
77+
arr.append((indent, place+' '+re.sub(
78+
r'[\n\s]+', ' ', msg)))
7979
return arr
8080

8181

@@ -94,7 +94,7 @@ def to_one_line_messages(message): # type: (str) -> str
9494

9595
def reformat_yaml_exception_message(message): # type: (str) -> str
9696
line_regex = re.compile(r'^\s+in "(.+)", line (\d+), column (\d+)$')
97-
fname_regex = re.compile(r'^file://'+os.getcwd()+'/')
97+
fname_regex = re.compile(r'^file://'+re.escape(os.getcwd())+'/')
9898
msgs = message.splitlines()
9999
ret = []
100100

@@ -103,17 +103,21 @@ def reformat_yaml_exception_message(message): # type: (str) -> str
103103
nblanks = 0
104104
elif len(msgs) == 4:
105105
c_msg = msgs[0]
106-
c_file, c_line, c_column = line_regex.match(msgs[1]).groups()
107-
c_file = re.sub(fname_regex, '', c_file)
108-
ret.append("%s:%s:%s: %s" % (c_file, c_line, c_column, c_msg))
106+
match = line_regex.match(msgs[1])
107+
if match:
108+
c_file, c_line, c_column = match.groups()
109+
c_file = re.sub(fname_regex, '', c_file)
110+
ret.append("%s:%s:%s: %s" % (c_file, c_line, c_column, c_msg))
109111

110112
msgs = msgs[2:]
111113
nblanks = 2
112114

113115
p_msg = msgs[0]
114-
p_file, p_line, p_column = line_regex.match(msgs[1]).groups()
115-
p_file = re.sub(fname_regex, '', p_file)
116-
ret.append("%s:%s:%s:%s %s" % (p_file, p_line, p_column, ' '*nblanks, p_msg))
116+
match = line_regex.match(msgs[1])
117+
if match:
118+
p_file, p_line, p_column = match.groups()
119+
p_file = re.sub(fname_regex, '', p_file)
120+
ret.append("%s:%s:%s:%s %s" % (p_file, p_line, p_column, ' '*nblanks, p_msg))
117121
return "\n".join(ret)
118122

119123

@@ -264,9 +268,10 @@ def main(argsl=None): # type: (List[str]) -> int
264268
return 1
265269

266270
if isinstance(avsc_names, Exception):
267-
_logger.error("Schema `%s` error:\n%s", args.schema,
268-
avsc_names, exc_info=((type(avsc_names), avsc_names,
269-
None) if args.debug else None))
271+
_logger.error("Schema `%s` error:\n%s", args.schema, # type: ignore
272+
avsc_names, exc_info=(
273+
(type(avsc_names), avsc_names, None) if args.debug
274+
else None))
270275
if args.print_avro:
271276
print(json.dumps(avsc_obj, indent=4))
272277
return 1
@@ -284,7 +289,7 @@ def main(argsl=None): # type: (List[str]) -> int
284289

285290
# Optionally print the RDFS graph from the schema
286291
if args.print_rdfs:
287-
print(rdfs.serialize(format=args.rdf_serializer).decode('utf-8'))
292+
print(rdfs.serialize(format=args.rdf_serializer).decode('utf-8')) # type: ignore
288293
return 0
289294

290295
if args.print_metadata and not args.document:

0 commit comments

Comments
 (0)