Ensure nothing initializes colorama when it isn't needed (#5063)

This commit is contained in:
jack1142 2021-05-20 10:31:27 +02:00 committed by GitHub
parent a6c438e486
commit b89c43eb0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 2 deletions

View File

@ -191,6 +191,29 @@ def _update_event_loop_policy():
_asyncio.set_event_loop_policy(_uvloop.EventLoopPolicy()) _asyncio.set_event_loop_policy(_uvloop.EventLoopPolicy())
def _ensure_no_colorama():
# a hacky way to ensure that nothing initialises colorama
# if we're not running with legacy Windows command line mode
from rich.console import detect_legacy_windows
if not detect_legacy_windows():
import colorama
import colorama.initialise
colorama.deinit()
def _colorama_wrap_stream(stream, *args, **kwargs):
return stream
colorama.wrap_stream = _colorama_wrap_stream
colorama.initialise.wrap_stream = _colorama_wrap_stream
def _early_init():
_update_event_loop_policy()
_ensure_no_colorama()
__version__ = "3.4.10.dev1" __version__ = "3.4.10.dev1"
version_info = VersionInfo.from_str(__version__) version_info = VersionInfo.from_str(__version__)

View File

@ -22,9 +22,9 @@ import discord
# Set the event loop policies here so any subsequent `new_event_loop()` # Set the event loop policies here so any subsequent `new_event_loop()`
# calls, in particular those as a result of the following imports, # calls, in particular those as a result of the following imports,
# return the correct loop object. # return the correct loop object.
from redbot import _update_event_loop_policy, __version__ from redbot import _early_init, __version__
_update_event_loop_policy() _early_init()
import redbot.logging import redbot.logging
from redbot.core.bot import Red, ExitCodes from redbot.core.bot import Red, ExitCodes

View File

@ -9,6 +9,10 @@ from copy import deepcopy
from pathlib import Path from pathlib import Path
from typing import Dict, Any, Optional, Union from typing import Dict, Any, Optional, Union
from redbot import _early_init
_early_init()
import appdirs import appdirs
import click import click