(color: bool)
| 3021 | |
| 3022 | @contextlib.contextmanager |
| 3023 | def force_color(color: bool): |
| 3024 | import _colorize |
| 3025 | from .os_helper import EnvironmentVarGuard |
| 3026 | |
| 3027 | if color: |
| 3028 | try: |
| 3029 | import _pyrepl # noqa: F401 |
| 3030 | except ModuleNotFoundError: |
| 3031 | # Can't force enable color without _pyrepl, so just skip. |
| 3032 | raise unittest.SkipTest("_pyrepl is missing") |
| 3033 | |
| 3034 | with ( |
| 3035 | swap_attr(_colorize, "can_colorize", lambda *, file=None: color), |
| 3036 | EnvironmentVarGuard() as env, |
| 3037 | ): |
| 3038 | env.unset("FORCE_COLOR", "NO_COLOR", "PYTHON_COLORS") |
| 3039 | env.set("FORCE_COLOR" if color else "NO_COLOR", "1") |
| 3040 | yield |
| 3041 | |
| 3042 | |
| 3043 | def force_colorized(func): |
searching dependent graphs…