From 6c7ad08cc508d3f65362fa5147f6806c508593b3 Mon Sep 17 00:00:00 2001 From: Hugo Rodger-Brown Date: Fri, 11 May 2018 14:32:26 +0100 Subject: [PATCH] Drop support for Python2, Django<1.11 --- .travis.yml | 1 - README.rst | 2 ++ elasticsearch_django/__init__.py | 1 - elasticsearch_django/admin.py | 2 -- elasticsearch_django/apps.py | 1 - elasticsearch_django/compat.py | 5 ---- elasticsearch_django/index.py | 2 -- .../management/commands/__init__.py | 5 +--- .../commands/create_search_index.py | 1 - .../commands/delete_search_index.py | 1 - .../management/commands/prune_search_index.py | 1 - .../commands/rebuild_search_index.py | 1 - .../commands/update_search_index.py | 1 - .../migrations/0005_convert_JSONFields.py | 4 +-- .../0007_update_json_field_encoders.py | 25 +++++++++++++++++++ elasticsearch_django/models.py | 7 ++---- elasticsearch_django/settings.py | 1 - elasticsearch_django/tests/__init__.py | 1 - elasticsearch_django/tests/test_apps.py | 4 +-- elasticsearch_django/tests/test_commands.py | 5 ++-- .../tests/test_index_functions.py | 4 +-- elasticsearch_django/tests/test_migrations.py | 2 -- elasticsearch_django/tests/test_models.py | 4 +-- elasticsearch_django/tests/test_settings.py | 4 +-- elasticsearch_django/tests/test_utils.py | 1 - elasticsearch_django/utils.py | 1 - setup.py | 9 +++---- tox.ini | 10 +++----- urls.py | 10 +++++--- 29 files changed, 52 insertions(+), 64 deletions(-) delete mode 100644 elasticsearch_django/compat.py create mode 100644 elasticsearch_django/migrations/0007_update_json_field_encoders.py diff --git a/.travis.yml b/.travis.yml index 4348f9c..bfa9ace 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ dist: language: python python: - - "2.7" - "3.6" install: pip install tox-travis diff --git a/README.rst b/README.rst index 07efb38..e3c18dc 100644 --- a/README.rst +++ b/README.rst @@ -4,6 +4,8 @@ .. image:: https://badge.fury.io/py/elasticsearch_django.svg :target: https://badge.fury.io/py/elasticsearch_django +**This project now requires Python3 and Django1.11 or above. For previous versions please refer to the Python2 branch.** + Elasticsearch for Django ======================== diff --git a/elasticsearch_django/__init__.py b/elasticsearch_django/__init__.py index 4da8e16..f866495 100644 --- a/elasticsearch_django/__init__.py +++ b/elasticsearch_django/__init__.py @@ -1,2 +1 @@ -# -*- coding: utf-8 -*- default_app_config = 'elasticsearch_django.apps.ElasticAppConfig' diff --git a/elasticsearch_django/admin.py b/elasticsearch_django/admin.py index 0d18023..7758687 100644 --- a/elasticsearch_django/admin.py +++ b/elasticsearch_django/admin.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -"""elasticsearch_django model admin.""" import simplejson as json # simplejson supports Decimal serialization import logging diff --git a/elasticsearch_django/apps.py b/elasticsearch_django/apps.py index 90ccd69..1baf1b5 100644 --- a/elasticsearch_django/apps.py +++ b/elasticsearch_django/apps.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import logging from django.apps import AppConfig diff --git a/elasticsearch_django/compat.py b/elasticsearch_django/compat.py deleted file mode 100644 index 05b7fed..0000000 --- a/elasticsearch_django/compat.py +++ /dev/null @@ -1,5 +0,0 @@ -# -*- coding: utf-8 -*- -try: - from unittest import mock -except ImportError: - import mock # noqa diff --git a/elasticsearch_django/index.py b/elasticsearch_django/index.py index 781a464..b0c6ec7 100644 --- a/elasticsearch_django/index.py +++ b/elasticsearch_django/index.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -"""Search3 index-related functions.""" import logging from elasticsearch import helpers diff --git a/elasticsearch_django/management/commands/__init__.py b/elasticsearch_django/management/commands/__init__.py index 5c82338..5cda625 100644 --- a/elasticsearch_django/management/commands/__init__.py +++ b/elasticsearch_django/management/commands/__init__.py @@ -1,11 +1,8 @@ -# -*- coding: utf-8 -*- """Base command for search-related management commands.""" -import logging - import builtins +import logging from django.core.management.base import BaseCommand - from elasticsearch.exceptions import TransportError logger = logging.getLogger(__name__) diff --git a/elasticsearch_django/management/commands/create_search_index.py b/elasticsearch_django/management/commands/create_search_index.py index f5cb99c..08d5c25 100644 --- a/elasticsearch_django/management/commands/create_search_index.py +++ b/elasticsearch_django/management/commands/create_search_index.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Create a search index.""" from . import BaseSearchCommand from ...index import create_index diff --git a/elasticsearch_django/management/commands/delete_search_index.py b/elasticsearch_django/management/commands/delete_search_index.py index 76a0160..77e2b21 100644 --- a/elasticsearch_django/management/commands/delete_search_index.py +++ b/elasticsearch_django/management/commands/delete_search_index.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Delete a search index (and all documents therein).""" import logging diff --git a/elasticsearch_django/management/commands/prune_search_index.py b/elasticsearch_django/management/commands/prune_search_index.py index fecda7f..f2a5919 100644 --- a/elasticsearch_django/management/commands/prune_search_index.py +++ b/elasticsearch_django/management/commands/prune_search_index.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Remove all documents in a search index that no longer exist in source queryset.""" from . import BaseSearchCommand from ...index import prune_index diff --git a/elasticsearch_django/management/commands/rebuild_search_index.py b/elasticsearch_django/management/commands/rebuild_search_index.py index ad808aa..73b7313 100644 --- a/elasticsearch_django/management/commands/rebuild_search_index.py +++ b/elasticsearch_django/management/commands/rebuild_search_index.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Create a search index.""" import logging diff --git a/elasticsearch_django/management/commands/update_search_index.py b/elasticsearch_django/management/commands/update_search_index.py index 4b7ee7b..a46cb1f 100644 --- a/elasticsearch_django/management/commands/update_search_index.py +++ b/elasticsearch_django/management/commands/update_search_index.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Update all documents in a search index.""" from . import BaseSearchCommand from ...index import update_index diff --git a/elasticsearch_django/migrations/0005_convert_JSONFields.py b/elasticsearch_django/migrations/0005_convert_JSONFields.py index a73aef5..f2df27b 100644 --- a/elasticsearch_django/migrations/0005_convert_JSONFields.py +++ b/elasticsearch_django/migrations/0005_convert_JSONFields.py @@ -1,11 +1,9 @@ # -*- coding: utf-8 -*- # Generated by Django 1.10 on 2017-01-03 16:11 -from __future__ import unicode_literals +from django.contrib.postgres.fields import JSONField from django.db import migrations -from ..db.fields import JSONField - class Migration(migrations.Migration): diff --git a/elasticsearch_django/migrations/0007_update_json_field_encoders.py b/elasticsearch_django/migrations/0007_update_json_field_encoders.py new file mode 100644 index 0000000..d87c94c --- /dev/null +++ b/elasticsearch_django/migrations/0007_update_json_field_encoders.py @@ -0,0 +1,25 @@ +# Generated by Django 2.0.5 on 2018-05-11 13:30 + +import django.contrib.postgres.fields.jsonb +import django.core.serializers.json +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('elasticsearch_django', '0006_add_encoder_JSONField_kwarg'), + ] + + operations = [ + migrations.AlterField( + model_name='searchquery', + name='hits', + field=django.contrib.postgres.fields.jsonb.JSONField(encoder=django.core.serializers.json.DjangoJSONEncoder, help_text='The list of meta info for each of the query matches returned.'), + ), + migrations.AlterField( + model_name='searchquery', + name='query', + field=django.contrib.postgres.fields.jsonb.JSONField(encoder=django.core.serializers.json.DjangoJSONEncoder, help_text='The raw ElasticSearch DSL query.'), + ), + ] diff --git a/elasticsearch_django/models.py b/elasticsearch_django/models.py index f8c2d07..cd75821 100644 --- a/elasticsearch_django/models.py +++ b/elasticsearch_django/models.py @@ -1,18 +1,15 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - import logging import time from django.conf import settings +from django.contrib.postgres.fields import JSONField from django.core.cache import cache -from django.db.models.fields import CharField from django.core.serializers.json import DjangoJSONEncoder from django.db import models from django.db.models.expressions import RawSQL +from django.db.models.fields import CharField from django.utils.timezone import now as tz_now -from .db.fields import JSONField from .settings import ( get_client, get_model_indexes, diff --git a/elasticsearch_django/settings.py b/elasticsearch_django/settings.py index 9a59d1f..2448106 100644 --- a/elasticsearch_django/settings.py +++ b/elasticsearch_django/settings.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Access to SEARCH_SETTINGS Django conf. The SEARCH_SETTINGS dict in the Django conf contains three diff --git a/elasticsearch_django/tests/__init__.py b/elasticsearch_django/tests/__init__.py index 08d5e5e..50ab37f 100644 --- a/elasticsearch_django/tests/__init__.py +++ b/elasticsearch_django/tests/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # search.tests package identifier from django.db import models diff --git a/elasticsearch_django/tests/test_apps.py b/elasticsearch_django/tests/test_apps.py index 4eb30b1..9ed05c0 100644 --- a/elasticsearch_django/tests/test_apps.py +++ b/elasticsearch_django/tests/test_apps.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +from unittest import mock + from django.core.exceptions import ImproperlyConfigured from django.test import TestCase @@ -13,7 +14,6 @@ _update_search_index, ) from .. import tests -from ..compat import mock from ..models import SearchDocumentMixin from ..tests import TestModel diff --git a/elasticsearch_django/tests/test_commands.py b/elasticsearch_django/tests/test_commands.py index 4afc6b2..1314367 100644 --- a/elasticsearch_django/tests/test_commands.py +++ b/elasticsearch_django/tests/test_commands.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- -from django.test import TestCase +from unittest import mock +from django.test import TestCase from elasticsearch.exceptions import TransportError -from ..compat import mock from ..management.commands import ( BaseSearchCommand, create_search_index, diff --git a/elasticsearch_django/tests/test_index_functions.py b/elasticsearch_django/tests/test_index_functions.py index 31416d4..314f310 100644 --- a/elasticsearch_django/tests/test_index_functions.py +++ b/elasticsearch_django/tests/test_index_functions.py @@ -1,7 +1,7 @@ -# -*- coding: utf-8 -*- +from unittest import mock + from django.test import TestCase -from ..compat import mock from ..index import ( create_index, update_index, diff --git a/elasticsearch_django/tests/test_migrations.py b/elasticsearch_django/tests/test_migrations.py index 2733beb..1ce253f 100644 --- a/elasticsearch_django/tests/test_migrations.py +++ b/elasticsearch_django/tests/test_migrations.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from django.apps import apps from django.db import connection from django.db.migrations.autodetector import MigrationAutodetector diff --git a/elasticsearch_django/tests/test_models.py b/elasticsearch_django/tests/test_models.py index 00a38b9..0a8d80f 100644 --- a/elasticsearch_django/tests/test_models.py +++ b/elasticsearch_django/tests/test_models.py @@ -1,14 +1,12 @@ -# -*- coding: utf-8 -*- import datetime import decimal +from unittest import mock from django.db.models import Model from django.test import TestCase from django.utils.timezone import now as tz_now - from elasticsearch_dsl.search import Search -from ..compat import mock from ..models import ( SearchDocumentMixin, SearchDocumentManagerMixin, diff --git a/elasticsearch_django/tests/test_settings.py b/elasticsearch_django/tests/test_settings.py index 82f6217..26f87e7 100644 --- a/elasticsearch_django/tests/test_settings.py +++ b/elasticsearch_django/tests/test_settings.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals +from unittest import mock from django.test import TestCase from django.test.utils import override_settings -from ..compat import mock from ..settings import ( get_client, get_setting, diff --git a/elasticsearch_django/tests/test_utils.py b/elasticsearch_django/tests/test_utils.py index 862097f..1c68fd5 100644 --- a/elasticsearch_django/tests/test_utils.py +++ b/elasticsearch_django/tests/test_utils.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from django.test import TestCase from ..settings import get_setting diff --git a/elasticsearch_django/utils.py b/elasticsearch_django/utils.py index 3d3d2d2..024f17a 100644 --- a/elasticsearch_django/utils.py +++ b/elasticsearch_django/utils.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from contextlib import contextmanager from .settings import get_settings diff --git a/setup.py b/setup.py index 7dd4393..20a87e9 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from os import path, chdir, pardir from setuptools import setup, find_packages @@ -9,10 +8,10 @@ setup( name="elasticsearch-django", - version="5.0.6", + version="5.1", packages=find_packages(), install_requires=[ - 'Django>=1.9', + 'Django>=1.11', 'elasticsearch>=5', 'elasticsearch-dsl>=5', 'psycopg2>=2.6', @@ -34,11 +33,9 @@ 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Framework :: Django', - 'Framework :: Django :: 1.9', - 'Framework :: Django :: 1.10', 'Framework :: Django :: 1.11', + 'Framework :: Django :: 2.0', 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.6', 'Topic :: Internet :: WWW/HTTP', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', diff --git a/tox.ini b/tox.ini index cf39341..9741169 100644 --- a/tox.ini +++ b/tox.ini @@ -1,14 +1,12 @@ [tox] -envlist = py{27,36}-django{19,110,111} +envlist = py{36}-django{111,20} [testenv] deps = - coverage==4.2 - dj-database-url==0.4 - py27: mock==2.0 - django19: Django==1.9 - django110: Django==1.10 + coverage + dj-database-url django111: Django==1.11 + django20: Django==2.0 commands = python --version diff --git a/urls.py b/urls.py index 5d43f33..fa00f12 100644 --- a/urls.py +++ b/urls.py @@ -1,9 +1,11 @@ -# urls for the development project -from django.conf.urls import include, url - from django.contrib import admin +try: + from django.urls import re_path, include +except ImportError: + from django.conf.urls import url as re_path, include + admin.autodiscover() urlpatterns = [ - url(r'^admin/', include(admin.site.urls,)), + re_path(r'^admin/', admin.site.urls), ]