Skip to content

Commit 21a0fa3

Browse files
Added MyPy to CI configuration (addresses #165) (#170)
* added mypy to .travis.yml * added missing imports flag * fixed return type in TestSuiteCoverage.restricted_to_files * add mypy files to gitignore * added missing -> None for __init__ methods * fixed Bug.to_dict -- mypy is awesome * added missing type annotations * increased Python version to 3.6 * fixed undefined var in FileLineSet.intersection * fixed issues in fileline that were detected by mypy * fixed inconsistent types in CLI module * bug fix: added missing 'self.' in method call * added missing restricted_to_files method to FileLineSet * fixed bad type declaration * fixed bad type declaration * added missing __contains__ to TestCoverage * bug fix: unref var * fixed bad type declaration * fixed type declarations * tweaked test data structures * tweaked Language properties * suppress type warnings in compiler module * ignore type warnings in soon-to-be-deprecated compiler module * fixed bad type declaration
1 parent ed7f199 commit 21a0fa3

File tree

20 files changed

+140
-104
lines changed

20 files changed

+140
-104
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.mypy_cache
12
*.pyc
23

34
.eggs

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ sudo: required
33
services:
44
- docker
55
python:
6-
- '3.5'
6+
- '3.6'
77
install:
8-
- pip install sphinx
8+
- pip install sphinx mypy
99
- pip install .
1010
script:
1111
- bugzoo -h
@@ -17,6 +17,7 @@ script:
1717
- bugzoo source list
1818
- bugzoo bug list
1919
- python3 test/test_manybugs.py
20+
- mypy bugzoo --ignore-missing-imports
2021
before_deploy:
2122
- "(cd docs && make html && cd _build/html && touch .nojekyll)"
2223
notifications:

bugzoo/cli/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,12 @@ def launch(bz: 'BugZoo',
247247
bug_name: str,
248248
interactive: bool,
249249
network: Optional[str] = None,
250-
tools: Optional[List[str]] = None,
251-
volumes: Optional[List[str]] = None,
250+
tool_names: Optional[List[str]] = None,
251+
volume_args: Optional[List[str]] = None,
252252
command: Optional[str] = None,
253253
) -> None:
254-
volumes = __prepare_volumes(volumes)
255-
tools = __prepare_tools(bz, tools)
254+
volumes = __prepare_volumes(volume_args)
255+
tools = __prepare_tools(bz, tool_names)
256256
bug = bz.bugs[bug_name]
257257

258258
if network is None:

bugzoo/compiler/__init__.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ def from_dict(d: dict) -> 'Compiler':
4747
except KeyError:
4848
raise Exception("unsupported compiler type: {}".format(typ))
4949

50-
return cls.from_dict(d)
50+
return cls.from_dict(d) # type: ignore
5151

5252
def clean(self,
5353
manager_container,
54-
container: 'Container',
54+
container: 'Container', # type: ignore
5555
verbose: bool = False
5656
) -> None:
5757
raise NotImplementedError
5858

5959
def compile(self,
60-
container: 'Container',
60+
container: 'Container', # type: ignore
6161
verbose: bool = False,
6262
) -> CompilationOutcome:
6363
"""
@@ -67,7 +67,7 @@ def compile(self,
6767
raise NotImplementedError
6868

6969
def compile_with_coverage_instrumentation(self,
70-
container: 'Container',
70+
container: 'Container', # type: ignore
7171
verbose: bool = False
7272
) -> CompilationOutcome:
7373
"""
@@ -122,7 +122,7 @@ def __init__(self,
122122

123123
def __compile(self,
124124
manager_container,
125-
container: 'Container',
125+
container: 'Container', # type: ignore
126126
command: str,
127127
verbose: bool
128128
) -> CompilationOutcome:
@@ -136,7 +136,7 @@ def __compile(self,
136136

137137
def clean(self,
138138
manager_container,
139-
container: 'Container',
139+
container: 'Container', # type: ignore
140140
verbose: bool = False
141141
) -> None:
142142
# if a context isn't given, use the source directory of the bug
@@ -147,19 +147,20 @@ def clean(self,
147147
stderr=True)
148148

149149
# TODO decouple!
150-
def compile(self,
150+
def compile(self, # type: ignore
151151
manager_container,
152-
container: 'Container',
152+
container: 'Container', # type: ignore
153153
verbose: bool = False
154154
) -> CompilationOutcome:
155155
"""
156156
See `Compiler.compile`
157157
"""
158158
return self.__compile(manager_container, container, self.__command, verbose)
159159

160-
def compile_with_coverage_instrumentation(self,
160+
def compile_with_coverage_instrumentation(self, # type: ignore
161161
manager_container,
162-
container: 'Container',
162+
container: 'Container', # type: ignore
163+
163164
verbose: bool = False
164165
) -> CompilationOutcome:
165166
"""

bugzoo/core/bug.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ def to_dict(self) -> dict:
6363
serialised in a JSON or YAML format.
6464
"""
6565
jsn = {
66-
'uid': self.uid,
66+
'name': self.name,
67+
'image': self.image,
6768
'program': self.program,
68-
'dataset': self.dataset.name if self.dataset else None,
69+
'dataset': self.dataset,
6970
'languages': [l.name for l in self.__languages]
7071
}
7172
return jsn

bugzoo/core/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def __init__(self,
2222
filename: str,
2323
arguments: Dict[str, str],
2424
depends_on: Optional[str],
25-
source: Optional[str]):
25+
source: Optional[str]
26+
) -> None:
2627
self.__root = root
2728
self.__tag = tag
2829
self.__context = context

bugzoo/core/container.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class Container(object):
2020
def __init__(self,
2121
uid: str,
2222
bug: Bug,
23-
tools: List[str]):
23+
tools: List[str]
24+
) -> None:
2425
"""
2526
Constructs a container for a given bug.
2627

bugzoo/core/coverage.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def from_dict(d: dict) -> 'TestCoverage':
4040
def __init__(self,
4141
test: str,
4242
outcome: TestOutcome,
43-
coverage: FileLineSet):
43+
coverage: FileLineSet
44+
) -> None:
4445
self.__test = test
4546
self.__outcome = outcome
4647
self.__coverage = coverage
@@ -52,6 +53,9 @@ def __repr__(self) -> str:
5253
s = "[{}: {}]\n{}".format(self.__test, status, coverage)
5354
return s
5455

56+
def __contains__(self, fileline: FileLine) -> bool:
57+
return fileline in self.__coverage
58+
5559
@property
5660
def test(self) -> str:
5761
"""
@@ -80,14 +84,14 @@ def restricted_to_files(self, filenames: List[str]) -> 'TestCoverage':
8084
Returns a variant of this coverage that is restricted to a given list
8185
of files.
8286
"""
83-
return TestCoverage(test,
84-
outcome,
87+
return TestCoverage(self.__test,
88+
self.__outcome,
8589
self.__coverage.restricted_to_files(filenames))
8690

8791
def to_dict(self) -> dict:
88-
return {'test': self.test,
89-
'outcome': self.outcome.to_dict(),
90-
'coverage': self.coverage.to_dict()}
92+
return {'test': self.__test,
93+
'outcome': self.__outcome.to_dict(),
94+
'coverage': self.__coverage.to_dict()}
9195

9296

9397
class TestSuiteCoverage(object):
@@ -109,7 +113,7 @@ def from_file(fn: str) -> 'TestSuiteCoverage':
109113
d = yaml.load(f)
110114
return TestSuiteCoverage.from_dict(d)
111115

112-
def __init__(self, test_coverage: Dict[str, TestCoverage]):
116+
def __init__(self, test_coverage: Dict[str, TestCoverage]) -> None:
113117
self.__test_coverage = test_coverage
114118

115119
def __repr__(self) -> str:
@@ -156,7 +160,7 @@ def to_dict(self) -> dict:
156160

157161
def restricted_to_files(self,
158162
filenames: List[str]
159-
) -> 'ProjectCoverageMap':
163+
) -> 'TestSuiteCoverage':
160164
"""
161165
Returns a variant of this coverage that is restricted to a given list
162166
of files.
@@ -182,9 +186,9 @@ def passing(self) -> 'TestSuiteCoverage':
182186
Returns a variant of this coverage report that only contains coverage
183187
for failing test executions.
184188
"""
185-
return ProjectCoverageMap({t: cov \
186-
for (t, cov) in self.__test_coverage.items() \
187-
if cov.outcome.passed})
189+
return TestSuiteCoverage({t: cov \
190+
for (t, cov) in self.__test_coverage.items() \
191+
if cov.outcome.passed})
188192

189193
def __len__(self) -> int:
190194
"""

bugzoo/core/errors.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ class BadManifestFile(BaseException):
66
"""
77
Thrown when the server fails to parse a manifest file.
88
"""
9-
def __init__(self, reason: str):
9+
def __init__(self, reason: str) -> None:
1010
msg = "bad manifest file: {}".format(reason)
1111
super().__init__(msg)
1212

13+
1314
class UnexpectedStatusCode(BaseException):
1415
"""
1516
Indicates that the API request produced an unexpected status code.
1617
"""
17-
def __init__(self, code: int):
18+
def __init__(self, code: int) -> None:
1819
self.__code = code
1920
super().__init__("API request produced unexpected status code: {}".format(code))
2021

@@ -30,7 +31,7 @@ class BugAlreadyBuilt(BaseException):
3031
"""
3132
Indicates that the given bug has already been installed on the server.
3233
"""
33-
def __init__(self, name: str):
34+
def __init__(self, name: str) -> None:
3435
self.__name = name
3536
super().__init__("bug already built: {}".format(name))
3637

@@ -46,7 +47,7 @@ class BugNotFound(BaseException):
4647
"""
4748
Indicates that no bug was found that matches the provided identifier.
4849
"""
49-
def __init__(self, name: str):
50+
def __init__(self, name: str) -> None:
5051
self.__name = name
5152
super().__init__("no bug found with name: {}".format(name))
5253

@@ -62,7 +63,7 @@ class SourceNotFoundWithURL(BaseException):
6263
"""
6364
Indicates that no source has been found that matches a provided URL.
6465
"""
65-
def __init__(self, url: str):
66+
def __init__(self, url: str) -> None:
6667
self.__url = url
6768
super().__init__("no source registered with URL: {}".format(url))
6869

@@ -75,7 +76,7 @@ class SourceNotFoundWithName(BaseException):
7576
"""
7677
Indicates that there exists no source registered with a given name.
7778
"""
78-
def __init__(self, name: str):
79+
def __init__(self, name: str) -> None:
7980
self.__name = name
8081
super().__init__("no source registered with name: {}".format(name))
8182

@@ -89,7 +90,7 @@ class SourceAlreadyRegisteredWithURL(BaseException):
8990
Indicates that there exists a source that is already registered with a
9091
given URL.
9192
"""
92-
def __init__(self, url: str):
93+
def __init__(self, url: str) -> None:
9394
self.__url = url
9495
super().__init__("source already registered with URL: {}".format(url))
9596

@@ -102,7 +103,7 @@ class NameInUseError(BaseException):
102103
"""
103104
Indicates that a given name is already in use by another resource.
104105
"""
105-
def __init__(self, name: str):
106+
def __init__(self, name: str) -> None:
106107
self.__name = name
107108
super().__init__("name already in use: {}".format(name))
108109

@@ -115,9 +116,9 @@ class BugNotInstalledError(BaseException):
115116
"""
116117
Indicates that a given bug hasn't been installed.
117118
"""
118-
def __init__(self, name: str):
119+
def __init__(self, name: str) -> None:
119120
self.__name = name
120-
super().__init__("bug not installed: {}".format(bug))
121+
super().__init__("bug not installed: {}".format(name))
121122

122123
@property
123124
def name(self) -> str:
@@ -133,7 +134,8 @@ class ImageBuildFailed(BaseException):
133134
"""
134135
def __init__(self,
135136
image_name: str,
136-
log: List[Dict[str, str]]):
137+
log: List[Dict[str, str]]
138+
) -> None:
137139
self.__image_name = image_name
138140
self.__log = copy(log)
139141
msg = "failed to build image: {}".format(image_name)

0 commit comments

Comments
 (0)