Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tooling] Initial implementation of stub checker #884

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# compare blinka's implementation vs the stubs coming from CircuitPython's implementation
circuitpython-stubs
mypy
3 changes: 3 additions & 0 deletions requirements-dev.txt.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
#
# SPDX-License-Identifier: MIT
49 changes: 49 additions & 0 deletions test/stubtest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Compare Blinka's implementation vs CircuitPython's stubs.

To do this, we use MyPy's stubtest... But we invoke it from this file, instead
of running it directly, so that we can set a specific target board and whatnot. Also
makes it easier to iterate the whole src/ folder and run the tool on each and every file.
"""

import os
import sys
from pathlib import Path

from mypy import stubtest

SRC = Path(__file__).parent.parent / "src"
sys.argv = [
"stubtest",
# run on all files
*(path.stem for path in SRC.glob("*.py")),
# shorter output (1 line instead of 5?) per error
"--concise",
# do not error about things on Blinka that arent on stubs
"--ignore-missing-stub",
]

def main() -> int:
"""Run tests and return 0 on success, 1 in error."""
for target in [
"BLINKA_OS_AGNOSTIC",
# add more things here ??
]:
msg = f"Running for: {target}"
print(msg, "=" * len(msg), sep="\n")

os.environ["BLINKA_FORCECHIP"] = target

# potentially some unittest.mock.patch or the like, to get code running

# TODO(elpekenin): pass arguments to this script? eg --failfast to control
# whether this quitting is performed or not
ret = stubtest.main()
if ret != 0:
return ret

# yay, no test failed
return 0


if __name__ == "__main__":
sys.exit(main())
Loading