Skip to content

Commit

Permalink
Drop support for EOL Python 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Jan 29, 2024
1 parent b0e4c88 commit fbe3d53
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 65 deletions.
25 changes: 4 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
- "3.10"
- "3.11"
- "3.12"
- "pypy-2.7"
- "pypy-3.7"
- "pypy-3.8"
- "pypy-3.9"
Expand All @@ -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 }}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------
Expand Down
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,21 @@ def main():
_get_here('README.rst'), 'rb', 'utf8').read(),
author='Jeff Quast',
author_email='[email protected]',
install_requires=('backports.functools-lru-cache>=1.2.1;'
'python_version < "3.2"'),
license='MIT',
packages=['wcwidth'],
url='https://github.com/jquast/wcwidth',
package_data={
'': ['LICENSE', '*.rst'],
},
zip_safe=True,
python_requires='>=3.5',
classifiers=[
'Intended Audience :: Developers',
'Natural Language :: English',
'Development Status :: 5 - Production/Stable',
'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',
Expand Down
8 changes: 1 addition & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
40 changes: 11 additions & 29 deletions wcwidth/wcwidth.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,15 @@

# std imports
import os
import sys
import warnings
from functools import lru_cache

# local
from .table_vs16 import VS16_NARROW_TO_WIDE
from .table_wide import WIDE_EASTASIAN
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):
"""
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit fbe3d53

Please sign in to comment.