From 0f9d94fb23ebf8cf194a3a88948a86f6dc69e786 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Mon, 9 Aug 2021 17:41:03 +0200 Subject: [PATCH] Dropped Python 2 support --- .travis.yml | 6 ------ README.rst | 16 ++++++++-------- install_xapian.sh | 8 +------- requirements.txt | 4 ++-- setup.py | 5 +---- tests/xapian_tests/search_indexes.py | 2 -- tests/xapian_tests/tests/test_backend.py | 4 +--- tests/xapian_tests/tests/test_interface.py | 2 -- tests/xapian_tests/tests/test_query.py | 2 -- xapian_backend.py | 16 ++++------------ 10 files changed, 17 insertions(+), 48 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4662480..cd441d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/README.rst b/README.rst index 3e82fb5..887f2fa 100644 --- a/README.rst +++ b/README.rst @@ -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 /bin/activate ./install_xapian.sh -`` must be >=1.3.0 for Python 3 envs. This takes around 10 minutes. +`` 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 `__; `David Sauve `__ was the main contributor of Xapian-Haystack and Xapian-Haystack was originally funded by `Trapeze `__. -`Claudep `__ is a frequent contributor. +`Claude Paroz `__ is a frequent contributor. `ANtlord `__ implemented support for EdgeNgram and Ngram. diff --git a/install_xapian.sh b/install_xapian.sh index 548935a..4351371 100755 --- a/install_xapian.sh +++ b/install_xapian.sh @@ -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 diff --git a/requirements.txt b/requirements.txt index f14b48e..192fac0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -Django>=1.8 -Django-Haystack>=2.5.1 +Django>=1.11 +Django-Haystack>=3.0 diff --git a/setup.py b/setup.py index 517b445..d273b78 100644 --- a/setup.py +++ b/setup.py @@ -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', ] ) diff --git a/tests/xapian_tests/search_indexes.py b/tests/xapian_tests/search_indexes.py index a588290..7a80c81 100644 --- a/tests/xapian_tests/search_indexes.py +++ b/tests/xapian_tests/search_indexes.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from haystack import indexes from . import models diff --git a/tests/xapian_tests/tests/test_backend.py b/tests/xapian_tests/tests/test_backend.py index 8e108ff..a53eaac 100644 --- a/tests/xapian_tests/tests/test_backend.py +++ b/tests/xapian_tests/tests/test_backend.py @@ -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 diff --git a/tests/xapian_tests/tests/test_interface.py b/tests/xapian_tests/tests/test_interface.py index 159e044..7ef7efe 100644 --- a/tests/xapian_tests/tests/test_interface.py +++ b/tests/xapian_tests/tests/test_interface.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - import datetime from django.db.models import Q diff --git a/tests/xapian_tests/tests/test_query.py b/tests/xapian_tests/tests/test_query.py index 24d3e1e..ad71a4e 100644 --- a/tests/xapian_tests/tests/test_query.py +++ b/tests/xapian_tests/tests/test_query.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - import datetime from django.conf import settings diff --git a/xapian_backend.py b/xapian_backend.py index a448b22..9f60f1c 100755 --- a/xapian_backend.py +++ b/xapian_backend.py @@ -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