Skip to content

Commit

Permalink
Drop support for Python 2.7 up to 3.6.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Jan 11, 2023
1 parent bcebace commit bb1a586
Show file tree
Hide file tree
Showing 49 changed files with 529 additions and 349 deletions.
2 changes: 1 addition & 1 deletion .meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ with-future-python = false
with-macos = false

[tox]
use-flake8 = false
use-flake8 = true

[coverage]
fail-under = 99
Expand Down
17 changes: 9 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
##############################################################################
"""Setup for zope.index package
"""
from __future__ import print_function
import sys
import os

import sys
from distutils.command.build_ext import build_ext
from distutils.errors import CCompilerError
from distutils.errors import DistutilsExecError
from distutils.errors import DistutilsPlatformError

from setuptools import setup, find_packages, Extension
from setuptools import Extension
from setuptools import find_packages
from setuptools import setup


def read(*rnames):
Expand All @@ -46,6 +46,7 @@ class optional_build_ext(build_ext):
"""This class subclasses build_ext and allows
the building of C extensions to fail.
"""

def run(self):
try:
build_ext.run(self)
Expand Down Expand Up @@ -118,15 +119,15 @@ def _unavailable(self, e):
'persistent',
'BTrees>=4.4.1',
'setuptools',
'six',
'zope.interface'
],
tests_require=['zope.testrunner'],
ext_modules=[
Extension('zope.index.text.okascore',
[os.path.join('src', 'zope', 'index', 'text', 'okascore.c')]),
Extension(
'zope.index.text.okascore',
[os.path.join('src', 'zope', 'index', 'text', 'okascore.c')]),
],
cmdclass={'build_ext': optional_build_ext},
include_package_data=True,
zip_safe=False,
)
)
2 changes: 1 addition & 1 deletion src/zope/index/field/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from zope.index.field.index import FieldIndex
from zope.index.field.index import FieldIndex # noqa: F401 unused
6 changes: 4 additions & 2 deletions src/zope/index/field/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
from zope.index import interfaces
from zope.index.field.sorting import SortingIndexMixin


_MARKER = object()


@zope.interface.implementer(
interfaces.IInjection,
interfaces.IStatistics,
Expand Down Expand Up @@ -86,14 +88,14 @@ def unindex_doc(self, docid):
rev_index = self._rev_index
value = rev_index.get(docid, _MARKER)
if value is _MARKER:
return # not in index
return # not in index

del rev_index[docid]

try:
set = self._fwd_index[value]
set.remove(docid)
except KeyError: #pragma NO COVERAGE
except KeyError: # pragma NO COVERAGE
# This is fishy, but we don't want to raise an error.
# We should probably log something.
# but keep it from throwing a dirty exception
Expand Down
12 changes: 7 additions & 5 deletions src/zope/index/field/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@
##############################################################################
"""A sorting mixin class for FieldIndex-like indexes.
"""
import heapq
import bisect
import heapq
from itertools import islice

from zope.interface import implementer

from zope.index.interfaces import IIndexSort


@implementer(IIndexSort)
class SortingIndexMixin(object):
class SortingIndexMixin:
"""
Implementation of :class:`zope.index.interfaces.IIndexSort`.
"""

_sorting_num_docs_attr = '_num_docs' # Length object
_sorting_fwd_index_attr = '_fwd_index' # forward BTree index
_sorting_rev_index_attr = '_rev_index' # reverse BTree index
_sorting_fwd_index_attr = '_fwd_index' # forward BTree index
_sorting_rev_index_attr = '_rev_index' # reverse BTree index

def sort(self, docids, reverse=False, limit=None):
if (limit is not None) and (limit < 1):
Expand All @@ -48,7 +50,7 @@ def sort(self, docids, reverse=False, limit=None):

fwd_index = getattr(self, self._sorting_fwd_index_attr)
rev_index = getattr(self, self._sorting_rev_index_attr)
getValue = lambda x, d=-1: rev_index.get(x, d)
getValue = lambda x, d=-1: rev_index.get(x, d) # noqa: E731 use def
marker = object()

# use_lazy and use_nbest computations lifted wholesale from
Expand Down
26 changes: 18 additions & 8 deletions src/zope/index/field/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
##############################################################################
"""Test field index
"""
import unittest
import doctest
import unittest


_marker = object()


class FieldIndexTests(unittest.TestCase):

def _getTargetClass(self):
Expand All @@ -30,7 +32,7 @@ def _makeOne(self, family=_marker):
return self._getTargetClass()(family)

def _populateIndex(self, index):
index.index_doc(5, 1) # docid, obj
index.index_doc(5, 1) # docid, obj
index.index_doc(2, 2)
index.index_doc(1, 3)
index.index_doc(3, 4)
Expand All @@ -44,31 +46,37 @@ def _populateIndex(self, index):

def test_class_conforms_to_IInjection(self):
from zope.interface.verify import verifyClass

from zope.index.interfaces import IInjection
verifyClass(IInjection, self._getTargetClass())

def test_instance_conforms_to_IInjection(self):
from zope.interface.verify import verifyObject

from zope.index.interfaces import IInjection
verifyObject(IInjection, self._makeOne())

def test_class_conforms_to_IIndexSearch(self):
from zope.interface.verify import verifyClass

from zope.index.interfaces import IIndexSearch
verifyClass(IIndexSearch, self._getTargetClass())

def test_instance_conforms_to_IIndexSearch(self):
from zope.interface.verify import verifyObject

from zope.index.interfaces import IIndexSearch
verifyObject(IIndexSearch, self._makeOne())

def test_class_conforms_to_IStatistics(self):
from zope.interface.verify import verifyClass

from zope.index.interfaces import IStatistics
verifyClass(IStatistics, self._getTargetClass())

def test_instance_conforms_to_IStatistics(self):
from zope.interface.verify import verifyObject

from zope.index.interfaces import IStatistics
verifyObject(IStatistics, self._makeOne())

Expand Down Expand Up @@ -115,12 +123,12 @@ def test_index_doc_existing_new_value(self):

def test_unindex_doc_nonesuch(self):
index = self._makeOne()
index.unindex_doc(1) # doesn't raise
index.unindex_doc(1) # doesn't raise

def test_unindex_doc_no_residual_fwd_values(self):
index = self._makeOne()
index.index_doc(1, 'value')
index.unindex_doc(1) # doesn't raise
index.unindex_doc(1) # doesn't raise
self.assertEqual(index.documentCount(), 0)
self.assertEqual(index.wordCount(), 0)
self.assertFalse(1 in index._rev_index)
Expand All @@ -130,7 +138,7 @@ def test_unindex_doc_w_residual_fwd_values(self):
index = self._makeOne()
index.index_doc(1, 'value')
index.index_doc(2, 'value')
index.unindex_doc(1) # doesn't raise
index.unindex_doc(1) # doesn't raise
self.assertEqual(index.documentCount(), 1)
self.assertEqual(index.wordCount(), 1)
self.assertFalse(1 in index._rev_index)
Expand Down Expand Up @@ -226,7 +234,7 @@ def test_sort_nonlazy_missingdocid(self):
self._populateIndex(index)
c1 = IFSet([1, 2, 3, 4, 5, 99])
result = index.sort(c1)
self.assertEqual(list(result), [5, 2, 1, 3, 4]) # 99 not present
self.assertEqual(list(result), [5, 2, 1, 3, 4]) # 99 not present

def test_sort_nonlazy_withlimit(self):
from BTrees.IFBTree import IFSet
Expand Down Expand Up @@ -326,11 +334,13 @@ def test_insert_none_value_does_insert_into_forward_index(self):
self.assertEqual(len(index._fwd_index), 1)
self.assertEqual(len(index._rev_index), 1)


def test_suite():
return unittest.TestSuite((
doctest.DocFileSuite('README.rst', optionflags=doctest.ELLIPSIS),
unittest.makeSuite(FieldIndexTests),
))
unittest.defaultTestLoader.loadTestsFromTestCase(FieldIndexTests),
))


if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
3 changes: 3 additions & 0 deletions src/zope/index/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def clear():
"""Unindex all documents indexed by the index
"""


class IIndexSearch(Interface):
"""
Interface for searching indexes.
Expand Down Expand Up @@ -83,6 +84,7 @@ def apply(query):
"""


class IIndexSort(Interface):
"""
Interface for sorting documents.
Expand All @@ -99,6 +101,7 @@ def sort(docids, reverse=False, limit=None):
reversed, using the "reverse" argument.
"""


class IStatistics(Interface):
"""An index that provides statistical information about itself."""

Expand Down
3 changes: 2 additions & 1 deletion src/zope/index/keyword/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from zope.index.keyword.index import KeywordIndex, CaseInsensitiveKeywordIndex
from zope.index.keyword.index import CaseInsensitiveKeywordIndex # noqa: F401
from zope.index.keyword.index import KeywordIndex # noqa: F401 unused
14 changes: 7 additions & 7 deletions src/zope/index/keyword/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
##############################################################################
"""Keyword index
"""
import six
import BTrees
from BTrees.Length import Length
from persistent import Persistent
from zope.interface import implementer


from zope.index.interfaces import IInjection, IStatistics, IIndexSearch
from zope.index.interfaces import IIndexSearch
from zope.index.interfaces import IInjection
from zope.index.interfaces import IStatistics
from zope.index.keyword.interfaces import IKeywordQuerying
from zope.interface import implementer


@implementer(IInjection, IStatistics, IIndexSearch, IKeywordQuerying)
Expand Down Expand Up @@ -79,7 +79,7 @@ def normalize(self, seq):
return seq

def index_doc(self, docid, seq):
if isinstance(seq, six.string_types):
if isinstance(seq, str):
raise TypeError('seq argument must be a list/tuple of strings')

old_kw = self._rev_index.get(docid, None)
Expand Down Expand Up @@ -127,7 +127,7 @@ def unindex_doc(self, docid):

try:
del self._rev_index[docid]
except KeyError: # pragma: no cover
except KeyError: # pragma: no cover
# 'WAAA! Inconsistent'
pass

Expand Down Expand Up @@ -159,7 +159,7 @@ def _insert_reverse(self, docid, words):

def search(self, query, operator='and'):
"""Execute a search given by 'query'."""
if isinstance(query, six.string_types):
if isinstance(query, str):
query = [query]

query = self.normalize(query)
Expand Down
1 change: 1 addition & 0 deletions src/zope/index/keyword/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
from zope.interface import Interface


class IKeywordQuerying(Interface):
"""Query over a set of keywords, seperated by white space."""

Expand Down
Loading

0 comments on commit bb1a586

Please sign in to comment.