Skip to content

Commit

Permalink
Drop support for Python 2.7, 3.5, 3.6, 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
taleinat committed Jun 24, 2024
1 parent 1760745 commit 58b8dee
Show file tree
Hide file tree
Showing 22 changed files with 76 additions and 163 deletions.
3 changes: 2 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ History
?.?.? (????-??-??)
++++++++++++++++++

* Added support for Python 3.9, 3.10 and 3.11.
* Dropped support for Python 2.7, 3.5, 3.6 and 3.7.
* Added support for Python 3.9 and 3.10.

0.7.3 (2020-06-27)
++++++++++++++++++
Expand Down
3 changes: 1 addition & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ For more info, see the `documentation <http://fuzzysearch.rtfd.org>`_.
Installation
------------

``fuzzysearch`` supports Python versions 2.7 and 3.5+, as well as PyPy 2.7 and
3.6.
``fuzzysearch`` supports Python versions 3.8+, as well as PyPy 3.9 and 3.10.

.. code::
Expand Down
21 changes: 3 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import with_statement

import os
import sys

from setuptools import setup, Extension
if sys.version_info < (3, 8):
from distutils.command.build_ext import build_ext
from distutils.errors import (
CCompilerError,
DistutilsExecError as ExecError,
DistutilsPlatformError as PlatformError,
)
else:
from setuptools.command.build_ext import build_ext
from setuptools.errors import CCompilerError, ExecError, PlatformError
from setuptools.command.build_ext import build_ext
from setuptools.errors import CCompilerError, ExecError, PlatformError

# --noexts: don't try building the C extensions
if '--noexts' in sys.argv[1:]:
Expand All @@ -34,7 +24,7 @@ def readfile(file_path):
history = readfile('HISTORY.rst').replace('.. :changelog:', '')


# Fail safe compilation based on markupsafe's, which in turn was shamelessly
# Fail-safe compilation based on markupsafe's, which in turn was shamelessly
# stolen from the simplejson setup.py file. Original author: Bob Ippolito

is_jython = 'java' in sys.platform
Expand Down Expand Up @@ -135,12 +125,7 @@ def run_setup(with_binary=True):
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
Expand Down
8 changes: 3 additions & 5 deletions src/fuzzysearch/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from functools import wraps

from fuzzysearch.compat import int_types

from attr import attrs, attrib


Expand All @@ -22,11 +20,11 @@ class Match(object):

if __debug__:
def __attrs_post_init__(self):
if not (isinstance(self.start, int_types) and self.start >= 0):
if not (isinstance(self.start, int) and self.start >= 0):
raise ValueError('start must be a non-negative integer')
if not (isinstance(self.end, int_types) and self.end >= self.start):
if not (isinstance(self.end, int) and self.end >= self.start):
raise ValueError('end must be an integer no smaller than start')
if not (isinstance(self.dist, int_types) and self.dist >= 0):
if not (isinstance(self.dist, int) and self.dist >= 0):
print(self.dist)
raise ValueError('dist must be a non-negative integer')
if self.matched is None:
Expand Down
25 changes: 0 additions & 25 deletions src/fuzzysearch/compat.py

This file was deleted.

5 changes: 2 additions & 3 deletions src/fuzzysearch/generic_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from fuzzysearch.common import FuzzySearchBase, Match, \
consolidate_overlapping_matches
from fuzzysearch.compat import xrange
from fuzzysearch.search_exact import search_exact


Expand Down Expand Up @@ -139,7 +138,7 @@ def make_match(start, end, dist):
yield make_match(cand.start, index + 1, cand.l_dist + 1)

# try skipping subsequence chars
for n_skipped in xrange(1, min(max_deletions - cand.n_dels, max_l_dist - cand.l_dist) + 1):
for n_skipped in range(1, min(max_deletions - cand.n_dels, max_l_dist - cand.l_dist) + 1):
# if skipping n_dels sub-sequence chars reaches the end
# of the sub-sequence, yield a match
if cand.subseq_index + n_skipped == subseq_len:
Expand Down Expand Up @@ -220,7 +219,7 @@ def find_near_matches_generic_ngrams(subsequence, sequence, search_params):
if ngram_len == 0:
raise ValueError('the subsequence length must be greater than max_l_dist')

for ngram_start in xrange(0, subseq_len - ngram_len + 1, ngram_len):
for ngram_start in range(0, subseq_len - ngram_len + 1, ngram_len):
ngram_end = ngram_start + ngram_len
start_index = max(0, ngram_start - max_l_dist)
end_index = min(seq_len, seq_len - subseq_len + ngram_end + max_l_dist)
Expand Down
5 changes: 2 additions & 3 deletions src/fuzzysearch/levenshtein.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from fuzzysearch.common import FuzzySearchBase, Match, \
consolidate_overlapping_matches
from fuzzysearch.compat import xrange
from fuzzysearch.levenshtein_ngram import find_near_matches_levenshtein_ngrams
from fuzzysearch.search_exact import search_exact

Expand Down Expand Up @@ -61,7 +60,7 @@ def make_match(start, end, dist):
return Match(start, end, dist, matched=sequence[start:end])

if max_l_dist >= subseq_len:
for index in xrange(len(sequence) + 1):
for index in range(len(sequence) + 1):
yield make_match(index, index, subseq_len)
return

Expand Down Expand Up @@ -112,7 +111,7 @@ def make_match(start, end, dist):
))

# try skipping subsequence chars
for n_skipped in xrange(1, max_l_dist - cand.dist + 1):
for n_skipped in range(1, max_l_dist - cand.dist + 1):
# if skipping n_skipped sub-sequence chars reaches the end
# of the sub-sequence, yield a match
if cand.subseq_index + n_skipped == subseq_len:
Expand Down
3 changes: 1 addition & 2 deletions src/fuzzysearch/levenshtein_ngram.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from fuzzysearch.common import Match
from fuzzysearch.compat import xrange
from fuzzysearch.search_exact import search_exact


Expand Down Expand Up @@ -168,7 +167,7 @@ def find_near_matches_levenshtein_ngrams(subsequence, sequence, max_l_dist):
def make_match(start, end, dist):
return Match(start, end, dist, matched=sequence[start:end])

for ngram_start in xrange(0, subseq_len - ngram_len + 1, ngram_len):
for ngram_start in range(0, subseq_len - ngram_len + 1, ngram_len):
ngram_end = ngram_start + ngram_len
subseq_before_reversed = subsequence[:ngram_start][::-1]
subseq_after = subsequence[ngram_end:]
Expand Down
5 changes: 2 additions & 3 deletions src/fuzzysearch/search_exact.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from functools import wraps

from fuzzysearch.common import FuzzySearchBase, Match
from fuzzysearch.compat import text_type, xrange


__all__ = [
Expand All @@ -11,7 +10,7 @@


CLASSES_WITH_INDEX = (list, tuple)
CLASSES_WITH_FIND = (bytes, bytearray, text_type)
CLASSES_WITH_FIND = (bytes, bytearray, str)

try:
from Bio.Seq import Seq
Expand Down Expand Up @@ -41,7 +40,7 @@ def find_in_index_range(start_index):
start_index = first_index + 1
except ValueError:
return -1
for subseq_index in xrange(1, len(subsequence)):
for subseq_index in range(1, len(subsequence)):
if sequence[first_index + subseq_index] != subsequence[subseq_index]:
break
else:
Expand Down
36 changes: 2 additions & 34 deletions tests/compat.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,8 @@
"""Compatibility support of testing tools for different Python versions"""
# The required modules are installed as necessary for different Python
# versions by `tox`. See `tox.ini` for details.
import sys

__all__ = [
'b',
'mock',
'u',
'unittest',
]

# The `unittest2` module is a backport of the new unittest features introduced
# in Python versions 3.2 and 2.7. Use it in older versions of Python.
# It is also used here in versions 2.7, 3.2 and 3.3 to make features added
# in version 3.4 available (specifically, TestCase.subTest).
if sys.version_info < (3, 4):
import unittest2 as unittest
else:
import unittest

# The `mock` module was added to the stdlib as `unittest.mock` in Python
# version 3.3.
if sys.version_info < (3, 3):
import mock
else:
import unittest.mock as mock

if sys.version_info < (3,):
def b(x):
return x

def u(x):
return unicode(x.replace(r'\\', r'\\\\'), 'unicode_escape')
else:
def b(x):
return x.encode('latin-1')

def u(x):
return x
def b(x):
return x.encode('latin-1')
4 changes: 3 additions & 1 deletion tests/test_common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import unittest

from fuzzysearch.common import Match, group_matches, GroupOfMatches, \
count_differences_with_maximum
from tests.compat import b, unittest
from tests.compat import b


class TestGroupOfMatches(unittest.TestCase):
Expand Down
14 changes: 8 additions & 6 deletions tests/test_find_near_matches.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from tests.compat import unittest, mock
import unittest
import unittest.mock

from tests.test_search_exact import TestSearchExactBase
from tests.test_substitutions_only import TestSubstitionsOnlyBase
from tests.test_levenshtein import TestFindNearMatchesLevenshteinBase
Expand Down Expand Up @@ -35,7 +37,7 @@ def patch_concrete_search_classes(self):
self.mock_find_near_matches_generic = \
MockSearchClassFailsUnlessDefined()

patcher = mock.patch.multiple(
patcher = unittest.mock.patch.multiple(
'fuzzysearch',
ExactSearch=self.mock_search_exact,
LevenshteinSearch=
Expand Down Expand Up @@ -130,23 +132,23 @@ def test_levenshtein(self):
# find_near_matches_levenshtein
self.patch_concrete_search_classes()
self.mock_find_near_matches_levenshtein.return_value = \
[mock.sentinel.SENTINEL]
[unittest.mock.sentinel.SENTINEL]

self.assertEqual(
find_near_matches('a', 'a', 1, 1, 1, 1),
[mock.sentinel.SENTINEL],
[unittest.mock.sentinel.SENTINEL],
)
self.assertEqual(self.mock_find_near_matches_levenshtein.call_count, 1)

self.assertEqual(
find_near_matches('a', 'a', 2, 2, 2, 2),
[mock.sentinel.SENTINEL],
[unittest.mock.sentinel.SENTINEL],
)
self.assertEqual(self.mock_find_near_matches_levenshtein.call_count, 2)

self.assertEqual(
find_near_matches('a', 'a', 5, 3, 7, 2),
[mock.sentinel.SENTINEL],
[unittest.mock.sentinel.SENTINEL],
)
self.assertEqual(self.mock_find_near_matches_levenshtein.call_count, 3)

Expand Down
Loading

0 comments on commit 58b8dee

Please sign in to comment.