From 49ec0e263b630cb97b16a1d9da55e70fef75c5d0 Mon Sep 17 00:00:00 2001 From: Dave Hunt Date: Fri, 8 Jun 2018 16:04:36 +0100 Subject: Use six to support Python 2 and 3 without using 2to3 --- blessings/__init__.py | 16 +++++++++------- blessings/tests.py | 11 ++++++----- setup.py | 6 +----- tox.ini | 6 +++--- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/blessings/__init__.py b/blessings/__init__.py index 9e10ebc..0212ae9 100644 --- a/blessings/__init__.py +++ b/blessings/__init__.py @@ -1,10 +1,12 @@ """A thin, practical wrapper around terminal coloring, styling, and positioning""" +from __future__ import absolute_import from contextlib import contextmanager import curses from curses import setupterm, tigetnum, tigetstr, tparm from fcntl import ioctl +import six try: from io import UnsupportedOperation as IOUnsupportedOperation @@ -420,7 +422,7 @@ COMPOUNDABLES = (COLORS | 'shadow', 'standout', 'subscript', 'superscript'])) -class ParametrizingString(unicode): +class ParametrizingString(six.text_type): """A Unicode string which can be called to parametrize it as a terminal capability""" @@ -432,7 +434,7 @@ class ParametrizingString(unicode): "normal" capability. """ - new = unicode.__new__(cls, formatting) + new = six.text_type.__new__(cls, formatting) new._normal = normal return new @@ -461,7 +463,7 @@ class ParametrizingString(unicode): except TypeError: # If the first non-int (i.e. incorrect) arg was a string, suggest # something intelligent: - if len(args) == 1 and isinstance(args[0], basestring): + if len(args) == 1 and isinstance(args[0], six.string_types): raise TypeError( 'A native or nonexistent capability template received ' '%r when it was expecting ints. You probably misspelled a ' @@ -472,12 +474,12 @@ class ParametrizingString(unicode): raise -class FormattingString(unicode): +class FormattingString(six.text_type): """A Unicode string which can be called upon a piece of text to wrap it in formatting""" def __new__(cls, formatting, normal): - new = unicode.__new__(cls, formatting) + new = six.text_type.__new__(cls, formatting) new._normal = normal return new @@ -492,7 +494,7 @@ class FormattingString(unicode): return self + text + self._normal -class NullCallableString(unicode): +class NullCallableString(six.text_type): """A dummy callable Unicode to stand in for ``FormattingString`` and ``ParametrizingString`` @@ -500,7 +502,7 @@ class NullCallableString(unicode): """ def __new__(cls): - new = unicode.__new__(cls, u'') + new = six.text_type.__new__(cls, u'') return new def __call__(self, *args): diff --git a/blessings/tests.py b/blessings/tests.py index aff3a2f..c51b36c 100644 --- a/blessings/tests.py +++ b/blessings/tests.py @@ -10,13 +10,14 @@ xterm-256color exists. """ from __future__ import with_statement # Make 2.5-compatible +from __future__ import absolute_import from curses import tigetstr, tparm from functools import partial -from StringIO import StringIO import sys from nose import SkipTest from nose.tools import eq_ +from six import StringIO # This tests that __all__ is correct, since we use below everything that should # be imported: @@ -229,22 +230,22 @@ def test_nice_formatting_errors(): t = TestTerminal() try: t.bold_misspelled('hey') - except TypeError, e: + except TypeError as e: assert 'probably misspelled' in e.args[0] try: t.bold_misspelled(u'hey') # unicode - except TypeError, e: + except TypeError as e: assert 'probably misspelled' in e.args[0] try: t.bold_misspelled(None) # an arbitrary non-string - except TypeError, e: + except TypeError as e: assert 'probably misspelled' not in e.args[0] try: t.bold_misspelled('a', 'b') # >1 string arg - except TypeError, e: + except TypeError as e: assert 'probably misspelled' not in e.args[0] diff --git a/setup.py b/setup.py index 8584935..adf5060 100644 --- a/setup.py +++ b/setup.py @@ -10,10 +10,6 @@ except ImportError: from setuptools import setup, find_packages -extra_setup = {} -if sys.version_info >= (3,): - extra_setup['use_2to3'] = True - setup( name='blessings', version='1.6.1', @@ -23,6 +19,7 @@ setup( author_email='erikrose@grinchcentral.com', license='MIT', packages=find_packages(exclude=['ez_setup']), + install_requires=['six'], tests_require=['nose'], test_suite='nose.collector', url='https://github.com/erikrose/blessings', @@ -49,5 +46,4 @@ setup( 'Topic :: Terminals' ], keywords=['terminal', 'tty', 'curses', 'ncurses', 'formatting', 'style', 'color', 'console'], - **extra_setup ) diff --git a/tox.ini b/tox.ini index cf09e35..b7dcfb6 100644 --- a/tox.ini +++ b/tox.ini @@ -3,6 +3,6 @@ envlist = py27, py34, py36 [testenv] commands = nosetests blessings -deps = nose -# So Python 3 runs don't pick up incompatible, un-2to3'd source from the cwd: -changedir = .tox \ No newline at end of file +deps = + nose + six -- cgit v1.2.1 From 37784c170a423faa8a7970ece416c99b93692f79 Mon Sep 17 00:00:00 2001 From: Dave Hunt Date: Mon, 18 Jun 2018 15:54:34 +0100 Subject: Import constants from six instead of importing the six module --- blessings/__init__.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/blessings/__init__.py b/blessings/__init__.py index 0212ae9..ebace02 100644 --- a/blessings/__init__.py +++ b/blessings/__init__.py @@ -6,7 +6,7 @@ from contextlib import contextmanager import curses from curses import setupterm, tigetnum, tigetstr, tparm from fcntl import ioctl -import six +from six import text_type, string_types try: from io import UnsupportedOperation as IOUnsupportedOperation @@ -422,7 +422,7 @@ COMPOUNDABLES = (COLORS | 'shadow', 'standout', 'subscript', 'superscript'])) -class ParametrizingString(six.text_type): +class ParametrizingString(text_type): """A Unicode string which can be called to parametrize it as a terminal capability""" @@ -434,7 +434,7 @@ class ParametrizingString(six.text_type): "normal" capability. """ - new = six.text_type.__new__(cls, formatting) + new = text_type.__new__(cls, formatting) new._normal = normal return new @@ -463,7 +463,7 @@ class ParametrizingString(six.text_type): except TypeError: # If the first non-int (i.e. incorrect) arg was a string, suggest # something intelligent: - if len(args) == 1 and isinstance(args[0], six.string_types): + if len(args) == 1 and isinstance(args[0], string_types): raise TypeError( 'A native or nonexistent capability template received ' '%r when it was expecting ints. You probably misspelled a ' @@ -474,12 +474,12 @@ class ParametrizingString(six.text_type): raise -class FormattingString(six.text_type): +class FormattingString(text_type): """A Unicode string which can be called upon a piece of text to wrap it in formatting""" def __new__(cls, formatting, normal): - new = six.text_type.__new__(cls, formatting) + new = text_type.__new__(cls, formatting) new._normal = normal return new @@ -494,7 +494,7 @@ class FormattingString(six.text_type): return self + text + self._normal -class NullCallableString(six.text_type): +class NullCallableString(text_type): """A dummy callable Unicode to stand in for ``FormattingString`` and ``ParametrizingString`` @@ -502,7 +502,7 @@ class NullCallableString(six.text_type): """ def __new__(cls): - new = six.text_type.__new__(cls, u'') + new = text_type.__new__(cls, u'') return new def __call__(self, *args): -- cgit v1.2.1 From 21cb2b0c4ea79e72e4550cdbb4597dd56a45082d Mon Sep 17 00:00:00 2001 From: Dave Hunt Date: Mon, 18 Jun 2018 16:30:37 +0100 Subject: Remove imports from __future__ --- blessings/__init__.py | 1 - blessings/tests.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/blessings/__init__.py b/blessings/__init__.py index ebace02..388cece 100644 --- a/blessings/__init__.py +++ b/blessings/__init__.py @@ -1,7 +1,6 @@ """A thin, practical wrapper around terminal coloring, styling, and positioning""" -from __future__ import absolute_import from contextlib import contextmanager import curses from curses import setupterm, tigetnum, tigetstr, tparm diff --git a/blessings/tests.py b/blessings/tests.py index c51b36c..a03eb8d 100644 --- a/blessings/tests.py +++ b/blessings/tests.py @@ -9,8 +9,6 @@ All we require from the host machine is that a standard terminfo definition of xterm-256color exists. """ -from __future__ import with_statement # Make 2.5-compatible -from __future__ import absolute_import from curses import tigetstr, tparm from functools import partial import sys -- cgit v1.2.1 From 739c4cb70bb41b503f26a28a572937827b7c6237 Mon Sep 17 00:00:00 2001 From: Dave Hunt Date: Mon, 18 Jun 2018 16:31:03 +0100 Subject: Add test coverage for Python 3.5 --- .travis.yml | 1 + tox.ini | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d6fa6a5..9132c4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: python python: - 2.7 - 3.4 + - 3.5 - 3.6 - pypy diff --git a/tox.ini b/tox.ini index b7dcfb6..ebd78ef 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27, py34, py36 +envlist = py27, py34, py35, py36 [testenv] commands = nosetests blessings -- cgit v1.2.1 From 86765e22fa730cb23d756fa62f6a06f949a9b5ed Mon Sep 17 00:00:00 2001 From: Dave Hunt Date: Mon, 18 Jun 2018 16:36:24 +0100 Subject: Add pypy to tox environments --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index ebd78ef..558601e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27, py34, py35, py36 +envlist = py{27,34,35,36,py} [testenv] commands = nosetests blessings -- cgit v1.2.1