Skip to content

Commit 47a5352

Browse files
committed
Drop support for Python 2 and old versions of Django. Add support for Django 3.
1 parent 7773b7f commit 47a5352

File tree

121 files changed

+138
-672
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+138
-672
lines changed

.travis.yml

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ python:
55
- 3.5
66
- 3.6
77
- 3.7
8+
- 3.8
89
- pypy3
910
services:
1011
- docker
@@ -29,10 +30,10 @@ addons:
2930
before_install:
3031
- mkdir -p $HOME/download-cache
3132
- >
32-
if [[ $VERSION_ES == '>=2.0.0,<3.0.0' ]];
33+
if [[ $VERSION_ES == '>=2,<3' ]];
3334
then
3435
docker run -d -p 9200:9200 elasticsearch:2.4.6-alpine
35-
elif [[ $VERSION_ES == '>=5.0.0,<6.0.0' ]];
36+
elif [[ $VERSION_ES == '>=5,<6' ]];
3637
then
3738
docker run -d -p 9200:9200 elasticsearch:5.6.10-alpine
3839
else
@@ -59,31 +60,34 @@ env:
5960
global:
6061
- JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
6162
jobs:
62-
- DJANGO_VERSION=">=1.11,<2.0" VERSION_ES=">=1.0.0,<2.0.0"
63-
- DJANGO_VERSION=">=2.0,<2.1" VERSION_ES=">=1.0.0,<2.0.0"
64-
- DJANGO_VERSION=">=2.1,<2.2" VERSION_ES=">=1.0.0,<2.0.0"
65-
- DJANGO_VERSION=">=1.11,<2.0" VERSION_ES=">=2.0.0,<3.0.0"
66-
- DJANGO_VERSION=">=2.0,<2.1" VERSION_ES=">=2.0.0,<3.0.0"
67-
- DJANGO_VERSION=">=2.1,<2.2" VERSION_ES=">=2.0.0,<3.0.0"
68-
- DJANGO_VERSION=">=1.11,<2.0" VERSION_ES=">=5.0.0,<6.0.0"
69-
- DJANGO_VERSION=">=2.0,<2.1" VERSION_ES=">=5.0.0,<6.0.0"
70-
- DJANGO_VERSION=">=2.1,<2.2" VERSION_ES=">=5.0.0,<6.0.0"
63+
- DJANGO_VERSION=">=2.2,<3.0" VERSION_ES=">=1,<2"
64+
- DJANGO_VERSION=">=3.0,<3.1" VERSION_ES=">=1,<2"
65+
- DJANGO_VERSION=">=2.2,<3.0" VERSION_ES=">=2,<3"
66+
- DJANGO_VERSION=">=3.0,<3.1" VERSION_ES=">=2,<3"
67+
- DJANGO_VERSION=">=2.2,<3.0" VERSION_ES=">=5,<6"
68+
- DJANGO_VERSION=">=3.0,<3.1" VERSION_ES=">=5,<6"
7169
jobs:
7270
allow_failures:
7371
- python: 'pypy3'
7472
exclude:
7573
- python: pypy3
76-
env: DJANGO_VERSION=">=2.0,<2.1" VERSION_ES=">=5.0.0,<6.0.0"
74+
env: DJANGO_VERSION=">=2.2,<3.0" VERSION_ES=">=5,<6"
7775
- python: pypy3
78-
env: DJANGO_VERSION=">=2.0,<2.1" VERSION_ES=">=2.0.0,<3.0.0"
76+
env: DJANGO_VERSION=">=2.2,<3.0" VERSION_ES=">=2,<3"
7977
- python: pypy3
80-
env: DJANGO_VERSION=">=2.0,<2.1" VERSION_ES=">=1.0.0,<2.0.0"
78+
env: DJANGO_VERSION=">=2.2,<3.0" VERSION_ES=">=1,<2"
8179
- python: pypy3
82-
env: DJANGO_VERSION=">=2.1,<2.2" VERSION_ES=">=5.0.0,<6.0.0"
80+
env: DJANGO_VERSION=">=3.0,<3.1" VERSION_ES=">=5,<6"
8381
- python: pypy3
84-
env: DJANGO_VERSION=">=2.1,<2.2" VERSION_ES=">=2.0.0,<3.0.0"
82+
env: DJANGO_VERSION=">=3.0,<3.1" VERSION_ES=">=2,<3"
8583
- python: pypy3
86-
env: DJANGO_VERSION=">=2.1,<2.2" VERSION_ES=">=1.0.0,<2.0.0"
84+
env: DJANGO_VERSION=">=3.0,<3.1" VERSION_ES=">=1,<2"
85+
- python: 3.5
86+
env: DJANGO_VERSION=">=3.0,<3.1" VERSION_ES=">=1,<2"
87+
- python: 3.5
88+
env: DJANGO_VERSION=">=3.0,<3.1" VERSION_ES=">=2,<3"
89+
- python: 3.5
90+
env: DJANGO_VERSION=">=3.0,<3.1" VERSION_ES=">=5,<6"
8791

8892
notifications:
8993
irc: 'irc.freenode.org#haystack'

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Requirements
5050

5151
Haystack has a relatively easily-met set of requirements.
5252

53-
* Python 2.7+ or Python 3.3+
53+
* Python 3.5+
5454
* A supported version of Django: https://www.djangoproject.com/download/#supported-versions
5555

5656
Additionally, each backend has its own requirements. You should refer to

docs/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
# All configuration values have a default; values that are commented out
1212
# serve to show the default.
1313

14-
from __future__ import absolute_import, division, print_function, unicode_literals
15-
1614
import os
1715
import sys
1816

docs/searchindex_api.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ object and write its ``prepare`` method to populate/alter the data any way you
332332
choose. For instance, a (naive) user-created ``GeoPointField`` might look
333333
something like::
334334

335-
from django.utils import six
336335
from haystack import indexes
337336

338337
class GeoPointField(indexes.CharField):
@@ -341,7 +340,7 @@ something like::
341340
super(GeoPointField, self).__init__(**kwargs)
342341

343342
def prepare(self, obj):
344-
return six.text_type("%s-%s" % (obj.latitude, obj.longitude))
343+
return "%s-%s" % (obj.latitude, obj.longitude)
345344

346345
The ``prepare`` method simply returns the value to be used for that field. It's
347346
entirely possible to include data that's not directly referenced to the object
@@ -615,4 +614,3 @@ For the impatient::
615614
def index_queryset(self, using=None):
616615
"Used when the entire index for model is updated."
617616
return Note.objects.filter(pub_date__lte=datetime.datetime.now())
618-

example_project/bare_bones_app/models.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# encoding: utf-8
2-
3-
from __future__ import absolute_import, division, print_function, unicode_literals
4-
52
import datetime
63

74
from django.db import models
@@ -14,7 +11,7 @@ class Cat(models.Model):
1411
created = models.DateTimeField(default=datetime.datetime.now)
1512
updated = models.DateTimeField(default=datetime.datetime.now)
1613

17-
def __unicode__(self):
14+
def __str__(self):
1815
return self.name
1916

2017
@models.permalink

example_project/bare_bones_app/search_indexes.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# encoding: utf-8
2-
3-
from __future__ import absolute_import, division, print_function, unicode_literals
4-
52
from bare_bones_app.models import Cat
63

74
from haystack import indexes

example_project/regular_app/models.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# encoding: utf-8
2-
3-
from __future__ import absolute_import, division, print_function, unicode_literals
4-
52
import datetime
63

74
from django.db import models
@@ -25,7 +22,7 @@ class Dog(models.Model):
2522
created = models.DateTimeField(default=datetime.datetime.now)
2623
updated = models.DateTimeField(default=datetime.datetime.now)
2724

28-
def __unicode__(self):
25+
def __str__(self):
2926
return self.full_name()
3027

3128
@models.permalink
@@ -43,5 +40,5 @@ class Toy(models.Model):
4340
dog = models.ForeignKey(Dog, related_name="toys")
4441
name = models.CharField(max_length=60)
4542

46-
def __unicode__(self):
43+
def __str__(self):
4744
return "%s's %s" % (self.dog.name, self.name)

example_project/regular_app/search_indexes.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# encoding: utf-8
2-
3-
from __future__ import absolute_import, division, print_function, unicode_literals
4-
52
from regular_app.models import Dog
63

74
from haystack import indexes

example_project/settings.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# encoding: utf-8
2-
3-
from __future__ import absolute_import, division, print_function, unicode_literals
4-
52
import os
63

74
from django.conf import settings

haystack/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# encoding: utf-8
2-
3-
from __future__ import absolute_import, division, print_function, unicode_literals
4-
52
from django.conf import settings
63
from django.core.exceptions import ImproperlyConfigured
74
from pkg_resources import DistributionNotFound, get_distribution, parse_version

haystack/admin.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
# encoding: utf-8
2-
3-
from __future__ import absolute_import, division, print_function, unicode_literals
4-
52
from django.contrib.admin.options import ModelAdmin, csrf_protect_m
63
from django.contrib.admin.views.main import SEARCH_VAR, ChangeList
74
from django.core.exceptions import PermissionDenied
85
from django.core.paginator import InvalidPage, Paginator
96
from django.shortcuts import render
10-
from django.utils.encoding import force_text
7+
from django.utils.encoding import force_str
118
from django.utils.translation import ungettext
129

1310
from haystack import connections
@@ -135,7 +132,7 @@ def changelist_view(self, request, extra_context=None):
135132
)
136133

137134
context = {
138-
"module_name": force_text(self.model._meta.verbose_name_plural),
135+
"module_name": force_str(self.model._meta.verbose_name_plural),
139136
"selection_note": selection_note % {"count": len(changelist.result_list)},
140137
"selection_note_all": selection_note_all
141138
% {"total_count": changelist.result_count},

haystack/apps.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import unicode_literals
2-
31
import logging
42

53
from django.apps import AppConfig

haystack/backends/__init__.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
3-
42
import copy
53
from copy import deepcopy
64
from time import time
75

8-
import six
9-
106
from django.conf import settings
117
from django.db.models import Q
128
from django.db.models.base import ModelBase
139
from django.utils import tree
14-
from django.utils.encoding import force_text
10+
from django.utils.encoding import force_str
1511

1612
from haystack.constants import VALID_FILTERS, FILTER_SEPARATOR, DEFAULT_ALIAS
1713
from haystack.exceptions import MoreLikeThisError, FacetingError
@@ -163,7 +159,7 @@ def prep_value(self, value):
163159
Hook to give the backend a chance to prep an attribute value before
164160
sending it to the search engine. By default, just force it to unicode.
165161
"""
166-
return force_text(value)
162+
return force_str(value)
167163

168164
def more_like_this(
169165
self, model_instance, additional_query_string=None, result_class=None
@@ -315,9 +311,6 @@ def __bool__(self):
315311
"""
316312
return bool(self.children)
317313

318-
def __nonzero__(self): # Python 2 compatibility
319-
return type(self).__bool__(self)
320-
321314
def __contains__(self, other):
322315
"""
323316
Returns True is 'other' is a direct child of this instance.
@@ -407,12 +400,7 @@ def __repr__(self):
407400
)
408401

409402
def _repr_query_fragment_callback(self, field, filter_type, value):
410-
if six.PY3:
411-
value = force_text(value)
412-
else:
413-
value = force_text(value).encode("utf8")
414-
415-
return "%s%s%s=%s" % (field, FILTER_SEPARATOR, filter_type, value)
403+
return "%s%s%s=%s" % (field, FILTER_SEPARATOR, filter_type, force_str(value))
416404

417405
def as_query_string(self, query_fragment_callback):
418406
"""
@@ -785,7 +773,7 @@ def clean(self, query_fragment):
785773
786774
A basic (override-able) implementation is provided.
787775
"""
788-
if not isinstance(query_fragment, six.string_types):
776+
if not isinstance(query_fragment, str):
789777
return query_fragment
790778

791779
words = query_fragment.split()

haystack/backends/elasticsearch2_backend.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import, division, print_function, unicode_literals
3-
42
import datetime
53

64
from django.conf import settings

haystack/backends/elasticsearch5_backend.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import, division, print_function, unicode_literals
3-
42
import datetime
53
import warnings
64

haystack/backends/elasticsearch_backend.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
# encoding: utf-8
2-
3-
from __future__ import absolute_import, division, print_function, unicode_literals
4-
52
import re
63
import warnings
74
from datetime import datetime, timedelta
85

9-
import six
106
from django.conf import settings
117
from django.core.exceptions import ImproperlyConfigured
128

@@ -813,9 +809,9 @@ def _from_python(self, value):
813809
iso = self._iso_datetime(value)
814810
if iso:
815811
return iso
816-
elif isinstance(value, six.binary_type):
812+
elif isinstance(value, bytes):
817813
# TODO: Be stricter.
818-
return six.text_type(value, errors="replace")
814+
return str(value, errors="replace")
819815
elif isinstance(value, set):
820816
return list(value)
821817
return value
@@ -825,7 +821,7 @@ def _to_python(self, value):
825821
if isinstance(value, (int, float, complex, list, tuple, bool)):
826822
return value
827823

828-
if isinstance(value, six.string_types):
824+
if isinstance(value, str):
829825
possible_datetime = DATETIME_REGEX.search(value)
830826

831827
if possible_datetime:
@@ -894,7 +890,7 @@ def build_query_fragment(self, field, filter_type, value):
894890
if hasattr(value, "values_list"):
895891
value = list(value)
896892

897-
if isinstance(value, six.string_types):
893+
if isinstance(value, str):
898894
# It's not an ``InputType``. Assume ``Clean``.
899895
value = Clean(value)
900896
else:
@@ -945,7 +941,7 @@ def build_query_fragment(self, field, filter_type, value):
945941
# Iterate over terms & incorportate the converted form of each into the query.
946942
terms = []
947943

948-
if isinstance(prepared_value, six.string_types):
944+
if isinstance(prepared_value, str):
949945
for possible_value in prepared_value.split(" "):
950946
terms.append(
951947
filter_types[filter_type]
@@ -1002,7 +998,7 @@ def build_alt_parser_query(self, parser_name, query_string="", **kwargs):
1002998
kwarg_bits = []
1003999

10041000
for key in sorted(kwargs.keys()):
1005-
if isinstance(kwargs[key], six.string_types) and " " in kwargs[key]:
1001+
if isinstance(kwargs[key], str) and " " in kwargs[key]:
10061002
kwarg_bits.append("%s='%s'" % (key, kwargs[key]))
10071003
else:
10081004
kwarg_bits.append("%s=%s" % (key, kwargs[key]))

haystack/backends/simple_backend.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
"""
33
A very basic, ORM-based backend for simple search during tests.
44
"""
5-
6-
from __future__ import absolute_import, division, print_function, unicode_literals
7-
5+
from functools import reduce
86
from warnings import warn
97

10-
import six
118
from django.db.models import Q
129

1310
from haystack import connections
@@ -71,7 +68,7 @@ def search(self, query_string, **kwargs):
7168

7269
if queries:
7370
qs = model.objects.filter(
74-
six.moves.reduce(lambda x, y: x | y, queries)
71+
reduce(lambda x, y: x | y, queries)
7572
)
7673
else:
7774
qs = []
@@ -128,7 +125,7 @@ def _build_sub_query(self, search_node):
128125

129126
term_list.append(value.prepare(self))
130127

131-
return (" ").join(map(six.text_type, term_list))
128+
return (" ").join(map(str, term_list))
132129

133130

134131
class SimpleEngine(BaseEngine):

0 commit comments

Comments
 (0)