anki/pylib/tests/run_mypy.py

45 lines
1.3 KiB
Python
Raw Normal View History

2021-04-13 10:45:05 +02:00
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import os
import subprocess
import sys
import tempfile
from pathlib import Path
if __name__ == "__main__":
(module, ini, extendsitepkgs) = sys.argv[1:]
ini = os.path.abspath(ini)
extendsitepkgs = os.path.abspath(extendsitepkgs)
extra_site = os.path.abspath(os.getenv("EXTRA_SITE_PACKAGES"))
folder = os.path.join(os.path.dirname(__file__), "..")
os.chdir(folder)
args = [
sys.executable,
"-m",
"mypy",
module,
"--config-file",
ini,
"--cache-dir",
Path(tempfile.gettempdir()) / ".mypy-anki-pylib",
"--sqlite-cache",
"--python-executable",
extendsitepkgs,
]
os.environ["EXTRA_SITE_PACKAGES"] = extra_site
if sys.platform.startswith("win32"):
# bazel passes in \\?\c:\... path; mypy can't handle it, so we
# strip off prefix
for entry in sys.path:
2021-10-15 07:50:47 +02:00
if entry.endswith("__mypy"):
2021-10-02 15:51:42 +02:00
typeshed = f"{entry[4:]}\\mypy\\typeshed"
args.append("--custom-typeshed-dir")
args.append(typeshed)
sys.exit(subprocess.run(args, check=False).returncode)