Skip to content

Commit 4397859

Browse files
zaniebindygreg
authored andcommitted
Add mypy and perform type checks
1 parent 843695f commit 4397859

File tree

5 files changed

+412
-53
lines changed

5 files changed

+412
-53
lines changed

check.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def run():
4949
# Unused variable
5050
check_args = ["--select", "I,F401,F841"]
5151
format_args = []
52+
mypy_args = ["pythonbuild"]
5253

5354
if args.fix:
5455
check_args.append("--fix")
@@ -61,8 +62,13 @@ def run():
6162
format_result = subprocess.run(
6263
["ruff", "format"] + format_args, stdout=sys.stdout, stderr=sys.stderr
6364
)
65+
mypy_result = subprocess.run(
66+
["mypy"] + mypy_args, stdout=sys.stdout, stderr=sys.stderr
67+
)
6468

65-
sys.exit(check_result.returncode + format_result.returncode)
69+
sys.exit(
70+
check_result.returncode + format_result.returncode + mypy_result.returncode
71+
)
6672

6773

6874
if __name__ == "__main__":

pythonbuild/docker.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pathlib
1010
import tarfile
1111

12-
import docker
12+
import docker # type: ignore
1313
import jinja2
1414

1515
from .logging import log, log_raw
@@ -85,7 +85,7 @@ def get_image(client, source_dir: pathlib.Path, image_dir: pathlib.Path, name):
8585
return image_id
8686

8787
else:
88-
return build_docker_image(client, source_dir, image_dir, name)
88+
return build_docker_image(client, str(source_dir).encode(), image_dir, name)
8989

9090

9191
def copy_file_to_container(path, container, container_path, archive_path=None):

pythonbuild/utils.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ def write_target_settings(targets, dest_path: pathlib.Path):
202202
for key in ("host_cc", "host_cxx", "target_cc", "target_cflags"):
203203
payload[key] = settings.get(key)
204204

205-
payload = json.dumps(payload, indent=4).encode("utf-8")
205+
serialized_payload = json.dumps(payload, indent=4).encode("utf-8")
206206

207-
write_if_different(dest_path / triple, payload)
207+
write_if_different(dest_path / triple, serialized_payload)
208208

209209

210210
class IntegrityError(Exception):
@@ -298,11 +298,17 @@ def download_to_path(url: str, path: pathlib.Path, size: int, sha256: str):
298298
def download_entry(key: str, dest_path: pathlib.Path, local_name=None) -> pathlib.Path:
299299
entry = DOWNLOADS[key]
300300
url = entry["url"]
301+
size = entry["size"]
302+
sha256 = entry["sha256"]
303+
304+
assert isinstance(url, str)
305+
assert isinstance(size, int)
306+
assert isinstance(sha256, str)
301307

302308
local_name = local_name or url[url.rindex("/") + 1 :]
303309

304310
local_path = dest_path / local_name
305-
download_to_path(url, local_path, entry["size"], entry["sha256"])
311+
download_to_path(url, local_path, size, sha256)
306312

307313
return local_path
308314

requirements.dev.in

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
-r requirements.txt
2+
13
ruff
24
mypy
35
types-jsonschema
46
types-PyYAML
7+
types-jinja2

0 commit comments

Comments
 (0)