diff --git a/.travis.yml b/.travis.yml index 41d3b3a..2b49312 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,12 @@ script: - if [[ "$TOXENV" == "py37" ]]; then black --check cli_helpers tests ; else echo "Skipping black for $TOXENV"; fi matrix: include: + - os: linux + python: 2.7 + env: TOXENV=py27 + - os: linux + python: 3.5 + env: TOXENV=py35 - os: linux python: 3.6 env: TOXENV=py36 diff --git a/.travis/install.sh b/.travis/install.sh index 3d827ef..83fdfc9 100755 --- a/.travis/install.sh +++ b/.travis/install.sh @@ -11,6 +11,10 @@ if [[ "$(uname -s)" == 'Darwin' ]]; then eval "$(pyenv init -)" case "${TOXENV}" in + py27) + curl -O https://bootstrap.pypa.io/get-pip.py + python get-pip.py --user + ;; py36) pyenv install 3.6.1 pyenv global 3.6.1 diff --git a/AUTHORS b/AUTHORS index 5bcb9cc..d1701a1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -23,6 +23,7 @@ This project receives help from these awesome contributors: - Michał Górny - Waldir Pimenta + Thanks ------ diff --git a/CHANGELOG b/CHANGELOG index f3d0c71..9d0a4ae 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -20,7 +20,6 @@ Version 2.0.1 (released on 2020-05-27) * Fix newline escaping in plain-text formatters (ascii, double, github) -* Use built-in unittest.mock instead of mock. Version 2.0.0 ------------- diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index a7e9d2a..c69eeba 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -66,7 +66,7 @@ hasn't broken any existing functionality. To run the tests, just type in:: $ pytest -CLI Helpers supports Python 3.6+. You can test against multiple versions of +CLI Helpers supports Python 2.7 and 3.4+. You can test against multiple versions of Python by running:: $ tox diff --git a/appveyor.yml b/appveyor.yml index 68eded1..3c568c8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,7 @@ environment: matrix: + - PYTHON: "C:\\Python27" + - PYTHON: "C:\\Python35" - PYTHON: "C:\\Python36" - PYTHON: "C:\\Python37" diff --git a/cli_helpers/tabular_output/tabulate_adapter.py b/cli_helpers/tabular_output/tabulate_adapter.py index 565b5a9..2054d36 100644 --- a/cli_helpers/tabular_output/tabulate_adapter.py +++ b/cli_helpers/tabular_output/tabulate_adapter.py @@ -20,23 +20,23 @@ tabulate.MIN_PADDING = 0 tabulate._table_formats["psql_unicode"] = tabulate.TableFormat( - lineabove=tabulate.Line("┌", "─", "┬", "┐"), - linebelowheader=tabulate.Line("├", "─", "┼", "┤"), + lineabove=tabulate.Line(u"┌", u"─", u"┬", u"┐"), + linebelowheader=tabulate.Line(u"├", u"─", u"┼", u"┤"), linebetweenrows=None, - linebelow=tabulate.Line("└", "─", "┴", "┘"), - headerrow=tabulate.DataRow("│", "│", "│"), - datarow=tabulate.DataRow("│", "│", "│"), + linebelow=tabulate.Line(u"└", u"─", u"┴", u"┘"), + headerrow=tabulate.DataRow(u"│", u"│", u"│"), + datarow=tabulate.DataRow(u"│", u"│", u"│"), padding=1, with_header_hide=None, ) tabulate._table_formats["double"] = tabulate.TableFormat( - lineabove=tabulate.Line("╔", "═", "╦", "╗"), - linebelowheader=tabulate.Line("╠", "═", "╬", "╣"), + lineabove=tabulate.Line(u"╔", u"═", u"╦", u"╗"), + linebelowheader=tabulate.Line(u"╠", u"═", u"╬", u"╣"), linebetweenrows=None, - linebelow=tabulate.Line("╚", "═", "╩", "╝"), - headerrow=tabulate.DataRow("║", "║", "║"), - datarow=tabulate.DataRow("║", "║", "║"), + linebelow=tabulate.Line(u"╚", u"═", u"╩", u"╝"), + headerrow=tabulate.DataRow(u"║", u"║", u"║"), + datarow=tabulate.DataRow(u"║", u"║", u"║"), padding=1, with_header_hide=None, ) diff --git a/cli_helpers/utils.py b/cli_helpers/utils.py index cd91556..ac0cfbe 100644 --- a/cli_helpers/utils.py +++ b/cli_helpers/utils.py @@ -3,15 +3,13 @@ import binascii import re -from functools import lru_cache -from typing import Dict -from typing import TYPE_CHECKING +from cli_helpers.compat import binary_type, text_type, Terminal256Formatter, StringIO, PY2 -if TYPE_CHECKING: - from pygments.style import StyleMeta - -from cli_helpers.compat import binary_type, text_type, Terminal256Formatter, StringIO +if PY2: + from repoze.lru import lru_cache +else: + from functools import lru_cache def bytes_to_string(b): @@ -82,7 +80,7 @@ def replace(s, replace): @lru_cache() -def _get_formatter(style) -> Terminal256Formatter: +def _get_formatter(style): return Terminal256Formatter(style=style) @@ -94,7 +92,7 @@ def style_field(token, field, style): return s.getvalue() -def filter_style_table(style: "StyleMeta", *relevant_styles: str) -> Dict: +def filter_style_table(style, *relevant_styles): """ get a dictionary of styles for given tokens. Typical usage: diff --git a/requirements-dev.txt b/requirements-dev.txt index 7846a4d..aff8e25 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,6 +2,8 @@ autopep8==1.3.3 codecov==2.0.9 coverage==4.3.4 black>=20.8b1 +mock==2.0.0 +pep8radius Pygments>=2.4.0 pytest==3.0.7 pytest-cov==2.4.0 diff --git a/setup.py b/setup.py index 6c1dd38..2ccd07d 100755 --- a/setup.py +++ b/setup.py @@ -24,6 +24,14 @@ def open_file(filename): readme = open_file("README.rst") +if sys.version_info[0] == 2: + py2_reqs = [ + 'backports.csv >= 1.0.0', + 'repoze.lru', + ] +else: + py2_reqs = [] + setup( name="cli_helpers", author="dbcli", @@ -38,20 +46,22 @@ def open_file(filename): install_requires=[ "configobj >= 5.0.5", "tabulate[widechars] >= 0.8.2", - ], + ] + py2_reqs, extras_require={ "styles": ["Pygments >= 1.6"], }, classifiers=[ - "Intended Audience :: Developers", - "License :: OSI Approved :: BSD License", - "Operating System :: Unix", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Topic :: Software Development", - "Topic :: Software Development :: Libraries :: Python Modules", - "Topic :: Terminals :: Terminal Emulators/X Terminals", - ], + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Operating System :: Unix', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Topic :: Software Development', + 'Topic :: Software Development :: Libraries :: Python Modules', + 'Topic :: Terminals :: Terminal Emulators/X Terminals', + ] ) diff --git a/tests/test_config.py b/tests/test_config.py index 27e76c7..e460bc4 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import os -from unittest.mock import MagicMock +from mock import MagicMock import pytest from cli_helpers.compat import MAC, text_type, WIN diff --git a/tox.ini b/tox.ini index d0d97f8..4c29d57 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = cov-init, py36, py37, noextras, docs, packaging, cov-report +envlist = cov-init, py27, py35, py36, py37, noextras, docs, packaging, cov-report [testenv] passenv = CI TRAVIS TRAVIS_* CODECOV