Dropped Python 2 support

This commit is contained in:
Claude Paroz 2021-08-09 17:41:03 +02:00
parent 6224ba3b08
commit 0f9d94fb23
10 changed files with 17 additions and 48 deletions

View File

@ -35,12 +35,6 @@ matrix:
env: DJANGO_VERSION=">=2.0,<2.1" XAPIAN_VERSION=1.3.6
- python: 3.4
env: DJANGO_VERSION=">=1.11,<2.0" XAPIAN_VERSION=1.3.6
- python: 2.7
env: DJANGO_VERSION=">=1.11,<2.0" XAPIAN_VERSION=1.4.9
- python: 2.7
env: DJANGO_VERSION=">=1.11,<2.0" XAPIAN_VERSION=1.3.6
- python: 2.7
env: DJANGO_VERSION=">=1.11,<2.0" XAPIAN_VERSION=1.2.25
addons:
apt:

View File

@ -35,17 +35,17 @@ The `endswith` search operation is not supported by Xapian-Haystack.
Requirements
------------
- Python 2.7 or 3+
- Django 1.8+
- Python 3+
- Django 1.11+
- Django-Haystack 2.5.1
- Xapian 1.2.19+
- Xapian 1.3.3+
In particular, we build-test this backend in `Travis`_ using:
- Python 2.7 and 3.4
- Django 1.8, 1.9 and 1.10
- Python 3.4
- Django 1.11, 2.0, 2.1, 2.2
- Django-Haystack (master)
- Xapian 1.2.19 (Python 2 only), 1.3.3 (both), and 1.4.1 (both)
- Xapian 1.3.6 and 1.4.1
Installation
@ -57,7 +57,7 @@ First, install Xapian in your machine e.g. with the script provided,
source <path>/bin/activate
./install_xapian.sh <version>
`<version>` must be >=1.3.0 for Python 3 envs. This takes around 10 minutes.
`<version>` must be >=1.3.0. This takes around 10 minutes.
Finally, install Xapian-Haystack by running::
@ -117,7 +117,7 @@ Credits
Xapian-Haystack is maintained by `Jorge C. Leitão <http://jorgecarleitao.net>`__;
`David Sauve <mailto:david.sauve@bag-of-holding.com>`__ was the main contributor of Xapian-Haystack and
Xapian-Haystack was originally funded by `Trapeze <http://www.trapeze.com>`__.
`Claudep <http://www.2xlibre.net>`__ is a frequent contributor.
`Claude Paroz <http://www.2xlibre.net>`__ is a frequent contributor.
`ANtlord <https://github.com/ANtlord>`__ implemented support for EdgeNgram and Ngram.

View File

@ -29,13 +29,7 @@ echo "Installing Xapian-core..."
cd $VIRTUAL_ENV/packages/${CORE}
./configure --prefix=$VIRTUAL_ENV && make && make install
PYV=`python -c "import sys;t='{v[0]}'.format(v=list(sys.version_info[:1]));sys.stdout.write(t)";`
if [ $PYV = "2" ]; then
PYTHON_FLAG=--with-python
else
PYTHON_FLAG=--with-python3
fi
PYTHON_FLAG=--with-python3
if [ $VERSION = "1.3.3" ]; then
XAPIAN_CONFIG=$VIRTUAL_ENV/bin/xapian-config-1.3

View File

@ -1,2 +1,2 @@
Django>=1.8
Django-Haystack>=2.5.1
Django>=1.11
Django-Haystack>=3.0

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
from distutils.core import setup
@ -27,7 +24,7 @@ setup(
license='GPL2',
py_modules=['xapian_backend'],
install_requires=[
'django>=1.8',
'django>=1.11',
'django-haystack>=2.5.1',
]
)

View File

@ -1,5 +1,3 @@
from __future__ import unicode_literals
from haystack import indexes
from . import models

View File

@ -1,5 +1,3 @@
from __future__ import unicode_literals
from decimal import Decimal
import datetime
import sys
@ -56,7 +54,7 @@ def pks(results):
return [result.pk for result in results]
class HaystackBackendTestCase(object):
class HaystackBackendTestCase:
"""
Abstract TestCase that implements an hack to ensure `connections`
has the right index

View File

@ -1,5 +1,3 @@
from __future__ import unicode_literals
import datetime
from django.db.models import Q

View File

@ -1,5 +1,3 @@
from __future__ import unicode_literals
import datetime
from django.conf import settings

View File

@ -1,5 +1,3 @@
from __future__ import unicode_literals
import datetime
import pickle
import os
@ -7,7 +5,6 @@ import re
import shutil
import sys
from django.utils import six
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.encoding import force_text
@ -29,11 +26,6 @@ except ImportError:
raise MissingDependency("The 'xapian' backend requires the installation of 'Xapian'. "
"Please refer to the documentation.")
if sys.version_info[0] == 2:
DirectoryExistsException = OSError
elif sys.version_info[0] == 3:
DirectoryExistsException = FileExistsError
class NotSupportedError(Exception):
"""
@ -201,7 +193,7 @@ class XapianSearchBackend(BaseSearchBackend):
if self.path != MEMORY_DB_NAME:
try:
os.makedirs(self.path)
except DirectoryExistsException:
except FileExistsError:
pass
self.flags = connection_options.get('FLAGS', DEFAULT_XAPIAN_FLAGS)
@ -354,7 +346,7 @@ class XapianSearchBackend(BaseSearchBackend):
def _get_ngram_lengths(value):
values = value.split()
for item in values:
for ngram_length in six.moves.range(NGRAM_MIN_LENGTH, NGRAM_MAX_LENGTH + 1):
for ngram_length in range(NGRAM_MIN_LENGTH, NGRAM_MAX_LENGTH + 1):
yield item, ngram_length
for obj in iterable:
@ -364,8 +356,8 @@ class XapianSearchBackend(BaseSearchBackend):
def ngram_terms(value):
for item, length in _get_ngram_lengths(value):
item_length = len(item)
for start in six.moves.range(0, item_length - length + 1):
for size in six.moves.range(length, length + 1):
for start in range(0, item_length - length + 1):
for size in range(length, length + 1):
end = start + size
if end > item_length:
continue