From 48b060cfa0e1b8b869f6cd6ac030d9d4a3a6de59 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 26 Apr 2021 12:51:28 +0200 Subject: [PATCH] mypy self check: Use mypy version from requirements file (#5245) --- requirements-tests-py3.txt | 2 ++ tests/mypy_self_check.py | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/requirements-tests-py3.txt b/requirements-tests-py3.txt index 9753eac9e..6038e56f9 100644 --- a/requirements-tests-py3.txt +++ b/requirements-tests-py3.txt @@ -1,3 +1,5 @@ +# Use the current mypy version until a version that supports modular +# typeshed is released on PyPI. git+https://github.com/python/mypy.git@master typed-ast>=1.0.4 black==20.8b1 diff --git a/tests/mypy_self_check.py b/tests/mypy_self_check.py index 963279491..a0b23b1e0 100755 --- a/tests/mypy_self_check.py +++ b/tests/mypy_self_check.py @@ -2,17 +2,29 @@ """Script to run mypy against its own code base.""" import os +import re import subprocess import sys import tempfile from pathlib import Path -# Use the current mypy version until a version that supports modular -# typeshed is released on PyPI. -MYPY_VERSION = "git+git://github.com/python/mypy" +REQUIREMENTS_FILE = "requirements-tests-py3.txt" +MYPY_REQUIREMENTS_REGEXPS = [r"^mypy[ =>]", r"^git\+.*/mypy.git\W"] + + +def determine_mypy_version() -> str: + with open(REQUIREMENTS_FILE) as f: + for line in f: + for regexp in MYPY_REQUIREMENTS_REGEXPS: + m = re.match(regexp, line) + if m: + return line.strip() + raise RuntimeError(f"no mypy version found in {REQUIREMENTS_FILE}") if __name__ == "__main__": + mypy_version = determine_mypy_version() + with tempfile.TemporaryDirectory() as tempdir: dirpath = Path(tempdir) subprocess.run( @@ -21,7 +33,7 @@ if __name__ == "__main__": ) os.environ["MYPYPATH"] = str(dirpath) try: - subprocess.run([sys.executable, "-m", "pip", "install", "-U", MYPY_VERSION], check=True) + subprocess.run([sys.executable, "-m", "pip", "install", "-U", mypy_version], check=True) subprocess.run([sys.executable, "-m", "pip", "install", "-r", dirpath / "test-requirements.txt"], check=True) subprocess.run( [