Revert "Add colour to the output of mypy_test" (#7874)

Revert "Add colour to the output of `mypy_test` (#7872)"

This reverts commit 753eb053ac.
This commit is contained in:
Alex Waygood
2022-05-19 01:13:06 +01:00
committed by GitHub
parent 753eb053ac
commit a348dac6e7
4 changed files with 33 additions and 79 deletions

View File

@@ -19,8 +19,6 @@ import subprocess
import sys
import tempfile
from collections.abc import Iterable
from contextlib import redirect_stdout
from io import StringIO
from pathlib import Path
from typing import TYPE_CHECKING, NamedTuple
@@ -30,7 +28,6 @@ if TYPE_CHECKING:
from typing_extensions import TypeAlias
import tomli
from colors import colored, print_error, print_success_msg
parser = argparse.ArgumentParser(description="Test runner for typeshed. Patterns are unanchored regexps on the full path.")
parser.add_argument("-v", "--verbose", action="count", default=0, help="More output")
@@ -168,7 +165,7 @@ def run_mypy(
try:
from mypy.api import run as mypy_run
except ImportError:
print_error("Cannot import mypy. Did you install it?")
print("Cannot import mypy. Did you install it?")
sys.exit(1)
with tempfile.NamedTemporaryFile("w+") as temp:
@@ -186,14 +183,9 @@ def run_mypy(
if args.dry_run:
exit_code = 0
else:
stdout_file = StringIO()
with redirect_stdout(stdout_file):
stdout, stderr, exit_code = mypy_run(mypy_args)
if exit_code:
if stderr:
print_error(stderr)
if stdout:
print_error(stdout_file.getvalue(), end="")
stdout, stderr, exit_code = mypy_run(mypy_args)
print(stdout, end="")
print(stderr, end="")
return exit_code
@@ -202,11 +194,8 @@ ReturnCode: TypeAlias = int
def run_mypy_as_subprocess(directory: StrPath, flags: Iterable[str]) -> ReturnCode:
result = subprocess.run([sys.executable, "-m", "mypy", directory, *flags], capture_output=True)
stdout, stderr = result.stdout, result.stderr
if stderr:
print_error(stderr.decode())
if stdout:
print_error(stdout.decode())
print(result.stdout.decode())
print(result.stderr.decode())
return result.returncode
@@ -245,7 +234,6 @@ def get_mypy_flags(
if strict:
flags.append("--strict")
if test_suite_run:
flags.append("--namespace-packages")
if sys.platform == "win32" or args.platform == "win32":
flags.extend(["--exclude", "tests/pytype_test.py"])
else:
@@ -303,17 +291,13 @@ def test_third_party_distribution(distribution: str, major: int, minor: int, arg
seen_dists: set[str] = set()
add_third_party_files(distribution, major, files, args, configurations, seen_dists)
print(f"testing {distribution} ({len(files)} files)... ", end="")
print(f"testing {distribution} ({len(files)} files)...")
if not files:
print_error("no files found")
print("--- no files found ---")
sys.exit(1)
code = run_mypy(args, configurations, major, minor, files)
if not code:
print_success_msg()
return code, len(files)
@@ -354,9 +338,6 @@ def test_stdlib(code: int, major: int, minor: int, args: argparse.Namespace) ->
this_code = run_mypy(args, [], major, minor, files, custom_typeshed=True)
code = max(code, this_code)
if not code:
print_success_msg()
return TestResults(code, len(files))
@@ -394,8 +375,6 @@ def test_the_test_scripts(code: int, major: int, minor: int, args: argparse.Name
else:
this_code = run_mypy_as_subprocess("tests", flags)
code = max(code, this_code)
if not code:
print_success_msg()
return TestResults(code, num_test_files_to_test)
@@ -414,8 +393,6 @@ def test_the_test_cases(code: int, major: int, minor: int, args: argparse.Namesp
shutil.copytree(Path("test_cases"), Path(td) / "test_cases")
this_code = run_mypy_as_subprocess(td, flags)
code = max(code, this_code)
if not code:
print_success_msg()
return TestResults(code, num_test_case_files)
@@ -456,7 +433,7 @@ def main() -> None:
if args.python_version:
versions = [v for v in versions if any(("%d.%d" % v).startswith(av) for av in args.python_version)]
if not versions:
print_error("--- no versions selected ---")
print("--- no versions selected ---")
sys.exit(1)
code = 0
@@ -465,17 +442,13 @@ def main() -> None:
code, files_checked_this_version = test_typeshed(code, major, minor, args)
total_files_checked += files_checked_this_version
if code:
print_error(f"--- exit status {code}, {total_files_checked} files checked ---")
print(f"--- exit status {code}, {total_files_checked} files checked ---")
sys.exit(code)
if not total_files_checked:
print_error("--- nothing to do; exit 1 ---")
print("--- nothing to do; exit 1 ---")
sys.exit(1)
print(colored(f"--- success, {total_files_checked} files checked ---", "green"))
print(f"--- success, {total_files_checked} files checked ---")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print_error("\n\n!!!\nTest aborted due to KeyboardInterrupt\n!!!")
sys.exit(1)
main()