From fbe3d53b31b52763cc9ce88eacbe36c9b150a562 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Mon, 29 Jan 2024 12:40:35 +0200 Subject: [PATCH] Drop support for EOL Python 2.7 --- .github/workflows/ci.yml | 25 ++++--------------------- .travis.yml | 2 -- docs/intro.rst | 2 +- setup.cfg | 2 -- setup.py | 4 +--- tox.ini | 8 +------- wcwidth/wcwidth.py | 40 +++++++++++----------------------------- 7 files changed, 18 insertions(+), 65 deletions(-) delete mode 100644 setup.cfg diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b58483..43c82c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,6 @@ jobs: - "3.10" - "3.11" - "3.12" - - "pypy-2.7" - "pypy-3.7" - "pypy-3.8" - "pypy-3.9" @@ -45,9 +44,6 @@ jobs: python-version: "3.6" - os: ubuntu-20.04 python-version: "3.5" - - os: ubuntu-20.04 - container: python:2.7-buster - python-version: "2.7" runs-on: ${{ matrix.os }} container: ${{ matrix.container }} @@ -77,22 +73,13 @@ jobs: echo IS_PYPY=$IS_PYPY >>$GITHUB_ENV echo TOX_PYTHON=$V >>$GITHUB_ENV - if [[ ${{ matrix.python-version }} = *2.7 ]]; then - python -m pip install tox - else - python -Im pip install tox - fi + python -Im pip install tox - name: Prepare sdist and source-dir shell: bash run: | - if [[ ${{ matrix.python-version }} = *2.7 ]]; then - python -m pip install build - python -m build - else - python -Im pip install build - python -Im build - fi + python -Im pip install build + python -Im build mkdir source-dir tar -xzvf dist/wcwidth-*.tar.gz -C source-dir --strip-components=1 @@ -101,11 +88,7 @@ jobs: shell: bash working-directory: ./source-dir run: | - if [[ ${{ matrix.python-version }} = *2.7 ]]; then - python -m tox -e ${{ env.TOX_PYTHON }} - else - python -Im tox -e ${{ env.TOX_PYTHON }} - fi + python -Im tox -e ${{ env.TOX_PYTHON }} - name: Rename coverage data shell: bash diff --git a/.travis.yml b/.travis.yml index f0f6cd9..614dc17 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,6 @@ matrix: include: - python: 3.8 env: TOXENV=update,compile,autopep8,docformatter,isort,pylint,flake8,flake8_tests,pydocstyle,docs COVERAGE_ID=travis-ci - - python: 2.7 - env: TOXENV=py27,codecov COVERAGE_ID=travis-ci - python: 3.4 env: TOXENV=py34,codecov COVERAGE_ID=travis-ci - python: 3.5 diff --git a/docs/intro.rst b/docs/intro.rst index 65df208..b9142e9 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -107,7 +107,7 @@ Install wcwidth in editable mode:: Execute unit tests using tox_:: - tox -e py27,py35,py36,py37,py38,py39,py310,py311,py312 + tox -e py35,py36,py37,py38,py39,py310,py311,py312 Updating Unicode Version ------------------------ diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 2a9acf1..0000000 --- a/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[bdist_wheel] -universal = 1 diff --git a/setup.py b/setup.py index 87e5704..4876b1c 100755 --- a/setup.py +++ b/setup.py @@ -51,8 +51,6 @@ def main(): _get_here('README.rst'), 'rb', 'utf8').read(), author='Jeff Quast', author_email='contact@jeffquast.com', - install_requires=('backports.functools-lru-cache>=1.2.1;' - 'python_version < "3.2"'), license='MIT', packages=['wcwidth'], url='https://github.com/jquast/wcwidth', @@ -60,6 +58,7 @@ def main(): '': ['LICENSE', '*.rst'], }, zip_safe=True, + python_requires='>=3.5', classifiers=[ 'Intended Audience :: Developers', 'Natural Language :: English', @@ -67,7 +66,6 @@ def main(): 'Environment :: Console', 'License :: OSI Approved :: MIT License', 'Operating System :: POSIX', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', diff --git a/tox.ini b/tox.ini index 5ffb5ff..99c4b58 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = update, compile, autopep8, docformatter, isort, pylint, flake8, pydocstyle, docs, verify_tables, py{27, 35, 36, 37, 38, 39, 310, 311, 312}, pypy{27, 36, 37, 38, 39, 310} +envlist = update, compile, autopep8, docformatter, isort, pylint, flake8, pydocstyle, docs, verify_tables, py{35, 36, 37, 38, 39, 310, 311, 312}, pypy{36, 37, 38, 39, 310} skip_missing_interpreters = true # https://tox.wiki/en/4.11.3/faq.html#testing-end-of-life-python-versions requires = virtualenv<20.22.0 @@ -113,12 +113,6 @@ deps = -r requirements-tests36.txt [testenv:py35] deps = -r requirements-tests37.in -[testenv:py27] -deps = -r requirements-tests37.in - -[testenv:pypy27] -deps = -r requirements-tests37.in - [testenv:update] basepython = python3.12 usedevelop = true diff --git a/wcwidth/wcwidth.py b/wcwidth/wcwidth.py index e924020..89e29e2 100644 --- a/wcwidth/wcwidth.py +++ b/wcwidth/wcwidth.py @@ -64,8 +64,8 @@ # std imports import os -import sys import warnings +from functools import lru_cache # local from .table_vs16 import VS16_NARROW_TO_WIDE @@ -73,17 +73,6 @@ from .table_zero import ZERO_WIDTH from .unicode_versions import list_versions -try: - # std imports - from functools import lru_cache -except ImportError: - # lru_cache was added in Python 3.2 - # 3rd party - from backports.functools_lru_cache import lru_cache - -# global cache -_PY3 = sys.version_info[0] >= 3 - def _bisearch(ucs, table): """ @@ -250,8 +239,7 @@ def _wcmatch_version(given_version): ``UNICODE_VERSION``. If the environment variable is not set, then the latest is used. :rtype: str - :returns: unicode string, or non-unicode ``str`` type for python 2 - when given ``version`` is also type ``str``. + :returns: unicode string. """ # Design note: the choice to return the same type that is given certainly # complicates it for python 2 str-type, but allows us to define an api that @@ -261,30 +249,24 @@ def _wcmatch_version(given_version): # That, along with the string-to-numeric and comparisons of earliest, # latest, matching, or nearest, greatly complicates this function. # Performance is somewhat curbed by memoization. - _return_str = not _PY3 and isinstance(given_version, str) - - if _return_str: - # avoid list-comprehension to work around a coverage issue: - # https://github.com/nedbat/coveragepy/issues/753 - unicode_versions = list(map(lambda ucs: ucs.encode(), list_versions())) - else: - unicode_versions = list_versions() + + unicode_versions = list_versions() latest_version = unicode_versions[-1] if given_version in (u'auto', 'auto'): given_version = os.environ.get( 'UNICODE_VERSION', - 'latest' if not _return_str else latest_version.encode()) + 'latest') if given_version in (u'latest', 'latest'): # default match, when given as 'latest', use the most latest unicode # version specification level supported. - return latest_version if not _return_str else latest_version.encode() + return latest_version if given_version in unicode_versions: # exact match, downstream has specified an explicit matching version # matching any value of list_versions(). - return given_version if not _return_str else given_version.encode() + return given_version # The user's version is not supported by ours. We return the newest unicode # version level that we support below their given value. @@ -298,7 +280,7 @@ def _wcmatch_version(given_version): "supported unicode version {latest_version!r} has been " "inferred.".format(given_version=given_version, latest_version=latest_version)) - return latest_version if not _return_str else latest_version.encode() + return latest_version # given version is less than any available version, return earliest # version. @@ -314,7 +296,7 @@ def _wcmatch_version(given_version): "version level, {earliest_version!r}".format( given_version=given_version, earliest_version=earliest_version)) - return earliest_version if not _return_str else earliest_version.encode() + return earliest_version # create list of versions which are less than our equal to given version, # and return the tail value, which is the highest level we may support, @@ -328,7 +310,7 @@ def _wcmatch_version(given_version): cmp_next_version = _wcversion_value(unicode_versions[idx + 1]) except IndexError: # at end of list, return latest version - return latest_version if not _return_str else latest_version.encode() + return latest_version # Maybe our given version has less parts, as in tuple(8, 0), than the # next compare version tuple(8, 0, 0). Test for an exact match by @@ -338,7 +320,7 @@ def _wcmatch_version(given_version): # Or, if any next value is greater than our given support level # version, return the current value in index. Even though it must - # be less than the given value, its our closest possible match. That + # be less than the given value, it's our closest possible match. That # is, 4.1 is returned for given 4.9.9, where 4.1 and 5.0 are available. if cmp_next_version > cmp_given: return unicode_version