From 2740627bbad86f9305644fd5b9ac9957f5484aaf Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 31 Dec 2022 15:31:26 -0500 Subject: [PATCH 1/2] Accurate, deduplicated, colored shim --- scripts/runtests.py | 10 +++------- tests/utils.py | 18 +++++++++--------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/scripts/runtests.py b/scripts/runtests.py index 4f930e3d4319..808b11825f7c 100644 --- a/scripts/runtests.py +++ b/scripts/runtests.py @@ -3,18 +3,14 @@ import json import os +import pathlib import re import subprocess import sys from pathlib import Path -try: - from termcolor import colored -except ImportError: - - def colored(text: str, color: str = "") -> str: # type: ignore[misc] - return text - +sys.path.append(str(pathlib.Path(__file__).parent.parent / "tests")) +from utils import colored # type: ignore[import] # noqa: E402 _STRICTER_CONFIG_FILE = "pyrightconfig.stricter.json" _SUCCESS = colored("Success", "green") diff --git a/tests/utils.py b/tests/utils.py index cdfba98000b9..208bab902108 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -10,13 +10,21 @@ from collections.abc import Mapping from functools import cache from pathlib import Path -from typing import NamedTuple +from typing import Iterable, NamedTuple from typing_extensions import Annotated import pathspec # type: ignore[import] import tomli from packaging.requirements import Requirement +try: + from termcolor import colored as colored +except ImportError: + + def colored(text: str, color: str | None = None, on_color: str | None = None, attrs: Iterable[str] | None = None) -> str: + return text + + # Used to install system-wide packages for different OS types: METADATA_MAPPING = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"} @@ -25,14 +33,6 @@ def strip_comments(text: str) -> str: return text.split("#")[0].strip() -try: - from termcolor import colored as colored -except ImportError: - - def colored(s: str, _: str) -> str: # type: ignore[misc] - return s - - def print_error(error: str, end: str = "\n", fix_path: tuple[str, str] = ("", "")) -> None: error_split = error.split("\n") old, new = fix_path From 475bc2bdc7a036572ff8d056e87b5fd0131ce99d Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 31 Dec 2022 17:28:48 -0500 Subject: [PATCH 2/2] Don't touch sys.path --- scripts/runtests.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/runtests.py b/scripts/runtests.py index 808b11825f7c..b2e2010d0ea6 100644 --- a/scripts/runtests.py +++ b/scripts/runtests.py @@ -3,14 +3,19 @@ import json import os -import pathlib import re import subprocess import sys from pathlib import Path +from typing import Iterable + +try: + from termcolor import colored +except ImportError: + + def colored(text: str, color: str | None = None, on_color: str | None = None, attrs: Iterable[str] | None = None) -> str: + return text -sys.path.append(str(pathlib.Path(__file__).parent.parent / "tests")) -from utils import colored # type: ignore[import] # noqa: E402 _STRICTER_CONFIG_FILE = "pyrightconfig.stricter.json" _SUCCESS = colored("Success", "green")