deps(colorama): bump colorama dependency

This commit is contained in:
Xuehai Pan 2025-04-25 21:56:59 +08:00
parent 87bbb625fc
commit 319e88f16b
8 changed files with 43 additions and 31 deletions

View file

@ -39,6 +39,7 @@ from nvitop.version import __version__
__all__ = [*api.__all__, 'select_devices']
# Add submodules to the top-level namespace
submodule = api
for submodule in (
caching,
collector,
@ -57,4 +58,4 @@ for submodule in (
# Required for `python -m nvitop.select` to work properly
sys.modules.pop(f'{__name__}.select', None)
del sys
del sys, submodule

View file

@ -104,13 +104,12 @@ if TYPE_CHECKING:
__all__ = ['colored', 'cprint']
if os.name == 'nt': # Windows
try:
from colorama import init
except ImportError:
pass
else:
init()
try:
from colorama import just_fix_windows_console
except ImportError:
pass
else:
just_fix_windows_console()
ATTRIBUTES: dict[Attribute, int] = {
@ -122,7 +121,6 @@ ATTRIBUTES: dict[Attribute, int] = {
'concealed': 8,
'strike': 9,
}
HIGHLIGHTS: dict[Highlight, int] = {
'on_black': 40,
'on_grey': 40, # Actually black but kept for backwards compatibility
@ -142,7 +140,6 @@ HIGHLIGHTS: dict[Highlight, int] = {
'on_light_cyan': 106,
'on_white': 107,
}
COLORS: dict[Color, int] = {
'black': 30,
'grey': 30, # Actually black but kept for backwards compatibility
@ -162,8 +159,6 @@ COLORS: dict[Color, int] = {
'light_cyan': 96,
'white': 97,
}
RESET = '\033[0m'
@ -239,19 +234,15 @@ def colored(
if not _can_do_color(no_color=no_color, force_color=force_color):
return result
fmt_str = '\033[%dm%s'
sequence = []
if color is not None:
result = fmt_str % (COLORS[color], result)
sequence.append(COLORS[color])
if on_color is not None:
result = fmt_str % (HIGHLIGHTS[on_color], result)
sequence.append(HIGHLIGHTS[on_color])
if attrs is not None:
for attr in attrs:
result = fmt_str % (ATTRIBUTES[attr], result)
result += RESET
sequence.extend(ATTRIBUTES[attr] for attr in attrs)
if sequence:
return f'\033[{";".join(map(str, sequence))}m{result}{RESET}'
return result

View file

@ -590,9 +590,11 @@ class CursesWindow: # pylint: disable=too-many-public-methods
import ctypes # pylint: disable=import-outside-toplevel
try:
self.encoding = f'cp{ctypes.windll.kernel32.GetConsoleOutputCP()}' # type: ignore[attr-defined]
code_page = ctypes.windll.kernel32.GetConsoleOutputCP() # type: ignore[attr-defined,unused-ignore]
except (AttributeError, OSError):
self.encoding = 'utf-8'
else:
self.encoding = f'cp{code_page}'
@overload
def addch(self, ch: ChType, attr: int = ...) -> None: ...

View file

@ -132,9 +132,14 @@ class Selection: # pylint: disable=too-many-instance-attributes
self.foreach(lambda process: process.send_signal(sig))
def interrupt(self) -> None:
try:
sig = (
signal.SIGINT
if not IS_WINDOWS
# pylint: disable-next=no-member
self.send_signal(signal.SIGINT if not IS_WINDOWS else signal.CTRL_C_EVENT) # type: ignore[attr-defined]
else signal.CTRL_C_EVENT # type: ignore[attr-defined,unused-ignore]
)
try:
self.send_signal(sig)
except SystemError:
pass

View file

@ -57,12 +57,12 @@ with contextlib.suppress(AttributeError, OSError):
if IS_WINDOWS:
import ctypes
IS_SUPERUSER = bool(ctypes.windll.shell32.IsUserAnAdmin()) # type: ignore[attr-defined]
IS_SUPERUSER = bool(ctypes.windll.shell32.IsUserAnAdmin()) # type: ignore[attr-defined,unused-ignore]
else:
try:
IS_SUPERUSER = os.geteuid() == 0
IS_SUPERUSER = os.geteuid() == 0 # type: ignore[attr-defined,unused-ignore]
except AttributeError:
IS_SUPERUSER = os.getuid() == 0
IS_SUPERUSER = os.getuid() == 0 # type: ignore[attr-defined,unused-ignore]
HOSTNAME: str = hostname()
IS_WINDOWS_SUBSYSTEM_FOR_LINUX = IS_WSL = bool(WINDOWS_SUBSYSTEM_FOR_LINUX)

View file

@ -63,7 +63,7 @@ if not __release__:
# The package `nvidia-ml-py` is not backward compatible over releases. This may
# cause problems with Old versions of NVIDIA drivers.
# cause problems with old versions of NVIDIA drivers.
# The ideal solution is to let the user install the best-fit version of `nvidia-ml-py`.
PYNVML_VERSION_CANDIDATES = (
# Sync with pyproject.toml and requirements.txt
@ -124,3 +124,16 @@ Note:
which are incompatible with some old NVIDIA drivers. ``nvitop`` may not display the processes
correctly due to this incompatibility.
"""
# Check that PYNVML_VERSION_CANDIDATES is sorted.
if not __release__:
try:
from packaging.version import Version as _Version
except ImportError:
pass
else:
assert (
tuple(sorted(PYNVML_VERSION_CANDIDATES, key=_Version)) == PYNVML_VERSION_CANDIDATES
), 'PYNVML_VERSION_CANDIDATES is not sorted.'
del _Version

View file

@ -49,7 +49,7 @@ dependencies = [
# Sync with nvitop/version.py and requirements.txt
"nvidia-ml-py >= 11.450.51, < 13.591.0a0",
"psutil >= 5.6.6",
"colorama >= 0.4.0; platform_system == 'Windows'",
"colorama >= 0.4.6; platform_system == 'Windows'",
]
dynamic = ["version", "optional-dependencies"]

View file

@ -1,4 +1,4 @@
# Sync with pyproject.toml and nvitop/version.py
nvidia-ml-py >= 11.450.51, < 13.591.0a0
psutil >= 5.6.6
colorama >= 0.4.0; platform_system == 'Windows'
colorama >= 0.4.6; platform_system == 'Windows'