Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["pypy-2.7", "pypy-3.8", "2.7", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["pypy-3.11", "3.9", "3.10", "3.11", "3.12", "3.13"]
os: [ubuntu-latest, macos-latest, windows-latest]
include:
# Add new helper variables to existing jobs
- {python-version: "pypy-2.7", toxenv: "pypy"}
- {python-version: "pypy-3.8", toxenv: "pypy3"}
- {python-version: "2.7", toxenv: "py27"}
- {python-version: "3.7", toxenv: "py37"}
- {python-version: "3.8", toxenv: "py38"}
- {python-version: "pypy-3.11", toxenv: "pypy3"}
- {python-version: "3.9", toxenv: "py39"}
- {python-version: "3.10", toxenv: "py310"}
- {python-version: "3.11", toxenv: "py311"}
Expand Down
6 changes: 1 addition & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ If you find Colorama useful, please |donate| to the authors. Thank you!
Installation
------------

Tested on CPython 2.7, 3.7, 3.8, 3.9, 3.10, 3.11 and 3.12 and PyPy 2.7 and 3.8.
Tested on CPython 3.9, 3.10, 3.11, 3.12, 3.13 and PyPy 3.11.

No requirements other than the standard library.

Expand Down Expand Up @@ -257,10 +257,6 @@ init(wrap=True):
init(wrap=False)
stream = AnsiToWin32(sys.stderr).stream

# Python 2
print >>stream, Fore.BLUE + 'blue text on stderr'

# Python 3
print(Fore.BLUE + 'blue text on stderr', file=stream)

Recognised ANSI Sequences
Expand Down
4 changes: 2 additions & 2 deletions colorama/ansi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def clear_line(mode=2):
return CSI + str(mode) + 'K'


class AnsiCodes(object):
class AnsiCodes:
def __init__(self):
# the subclasses declare class attributes which are numbers.
# Upon instantiation we define instance attributes, which are the same
Expand All @@ -33,7 +33,7 @@ def __init__(self):
setattr(self, name, code_to_chars(value))


class AnsiCursor(object):
class AnsiCursor:
def UP(self, n=1):
return CSI + str(n) + 'A'
def DOWN(self, n=1):
Expand Down
4 changes: 2 additions & 2 deletions colorama/ansitowin32.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
winterm = WinTerm()


class StreamWrapper(object):
class StreamWrapper:
'''
Wraps a stream (such as stdout), acting as a transparent proxy for all
attribute access apart from method 'write()', which is delegated to our
Expand Down Expand Up @@ -69,7 +69,7 @@ def closed(self):
return True


class AnsiToWin32(object):
class AnsiToWin32:
'''
Implements a 'write()' method which, on Windows, will strip ANSI character
sequences from the text, and if outputting to a tty, will convert them into
Expand Down
8 changes: 2 additions & 6 deletions colorama/initialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ def _wipe_internal_state_for_tests():
global fixed_windows_console
fixed_windows_console = False

try:
# no-op if it wasn't registered
atexit.unregister(reset_all)
except AttributeError:
# python 2: no atexit.unregister. Oh well, we did our best.
pass
# no-op if it wasn't registered
atexit.unregister(reset_all)


def reset_all():
Expand Down
14 changes: 3 additions & 11 deletions colorama/tests/ansitowin32_test.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
from io import StringIO, TextIOWrapper
from unittest import TestCase, main
try:
from contextlib import ExitStack
except ImportError:
# python 2
from contextlib2 import ExitStack

try:
from unittest.mock import MagicMock, Mock, patch
except ImportError:
from mock import MagicMock, Mock, patch
from unittest.mock import MagicMock, Mock, patch
from contextlib import ExitStack

from ..ansitowin32 import AnsiToWin32, StreamWrapper
from ..win32 import ENABLE_VIRTUAL_TERMINAL_PROCESSING
Expand All @@ -35,7 +27,7 @@ def testDelegatesContext(self):
mockConverter = Mock()
s = StringIO()
with StreamWrapper(s, mockConverter) as fp:
fp.write(u'hello')
fp.write('hello')
self.assertTrue(s.closed)

def testProxyNoContextManager(self):
Expand Down
6 changes: 1 addition & 5 deletions colorama/tests/initialise_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
import sys
from unittest import TestCase, main, skipUnless

try:
from unittest.mock import patch, Mock
except ImportError:
from mock import patch, Mock
from unittest.mock import patch, Mock

from ..ansitowin32 import StreamWrapper
from ..initialise import init, just_fix_windows_console, _wipe_internal_state_for_tests
Expand Down
6 changes: 1 addition & 5 deletions colorama/tests/winterm_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
import sys
from unittest import TestCase, main, skipUnless

try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch
from unittest.mock import Mock, patch

from ..winterm import WinColor, WinStyle, WinTerm

Expand Down
8 changes: 4 additions & 4 deletions colorama/winterm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def get_osfhandle(_):
from . import win32

# from wincon.h
class WinColor(object):
class WinColor:
BLACK = 0
BLUE = 1
GREEN = 2
Expand All @@ -20,12 +20,12 @@ class WinColor(object):
GREY = 7

# from wincon.h
class WinStyle(object):
class WinStyle:
NORMAL = 0x00 # dim text, dim background
BRIGHT = 0x08 # bright text, dim background
BRIGHT_BACKGROUND = 0x80 # dim text, bright background

class WinTerm(object):
class WinTerm:

def __init__(self):
self._default = win32.GetConsoleScreenBufferInfo(win32.STDOUT).wAttributes
Expand Down Expand Up @@ -191,5 +191,5 @@ def enable_vt_processing(fd):
if mode & win32.ENABLE_VIRTUAL_TERMINAL_PROCESSING:
return True
# Can get TypeError in testsuite where 'fd' is a Mock() and IOError in python2.7
except (IOError, OSError, TypeError):
except (OSError, TypeError):
return False
1 change: 0 additions & 1 deletion demos/demo01.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# print grid of all colors and brightnesses
# uses stdout.write to write chars with no newline nor spaces between them
# This should run more-or-less identically on Windows and Unix.
from __future__ import print_function
import sys

# Add parent dir to sys path, so the following 'import colorama' always finds
Expand Down
1 change: 0 additions & 1 deletion demos/demo02.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

# Simple demo of changing foreground, background and brightness.

from __future__ import print_function
import fixpath
from colorama import just_fix_windows_console, Fore, Back, Style

Expand Down
1 change: 0 additions & 1 deletion demos/demo03.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

# Demonstrate the different behavior when autoreset is True and False.

from __future__ import print_function
import fixpath
from colorama import init, Fore, Back, Style

Expand Down
1 change: 0 additions & 1 deletion demos/demo04.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.

# check that stripped ANSI in redirected stderr does not affect stdout
from __future__ import print_function
import sys
import fixpath
from colorama import init, Fore
Expand Down
1 change: 0 additions & 1 deletion demos/demo05.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# The point of the demonstration is to show how the ANSI wrapping on Windows can be disabled.
# The unwrapped cases will be interpreted with ANSI on Unix, but not on Windows.

from __future__ import print_function
import sys
import fixpath
from colorama import AnsiToWin32, init, Fore
Expand Down
1 change: 0 additions & 1 deletion demos/demo06.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
from __future__ import print_function
import fixpath
import colorama
from colorama import Fore, Back, Style, Cursor
Expand Down
1 change: 0 additions & 1 deletion demos/demo07.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import fixpath
import colorama

Expand Down
1 change: 0 additions & 1 deletion demos/demo08.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import fixpath
from colorama import colorama_text, Fore

Expand Down
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "colorama"
description = "Cross-platform colored terminal text."
readme = "README.rst"
license = "BSD-3-Clause"
requires-python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*"
requires-python = ">=3.9"
authors = [
{ name = "Jonathan Hartley", email = "[email protected]" },
]
Expand All @@ -30,11 +30,8 @@ classifiers = [
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down
2 changes: 0 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mock>=1.0.1;python_version<"3.3"
twine>=3.1.1
contextlib2;python_version<"3"
build
-e .
5 changes: 1 addition & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[tox]
isolated_build = true
envlist = py{27, 37, 38, 39, 310, 311, 312, 313, py, py3}
envlist = py{39, 310, 311, 312, 313, py3}

[testenv]
deps =
py27,pypy: mock
py27,pypy: contextlib2
commands = python -m unittest discover -p *_test.py
Loading