From cff4d67f4b5ae4c17cfafd3b15747c783278105f Mon Sep 17 00:00:00 2001 From: Nikolai R Kristiansen Date: Sat, 11 Sep 2021 16:24:39 +0200 Subject: [PATCH] Drop EOL python 2.7,3.5 and add 3.9 Remove six --- .github/workflows/ci.yml | 19 ++++++------------- README.rst | 4 ++-- django_elasticsearch_dsl/documents.py | 9 ++++----- django_elasticsearch_dsl/fields.py | 1 - django_elasticsearch_dsl/indices.py | 2 -- .../management/commands/search_index.py | 3 --- django_elasticsearch_dsl/registries.py | 13 ++++++------- django_elasticsearch_dsl/signals.py | 3 --- docs/source/conf.py | 1 - example/test_app/migrations/0001_initial.py | 3 --- example/test_app/models.py | 7 ------- setup.py | 12 +++--------- tests/documents.py | 3 ++- tests/models.py | 8 -------- tests/test_commands.py | 3 ++- tests/test_documents.py | 13 ++++++------- tests/test_fields.py | 5 +---- tests/test_integration.py | 11 +++++------ tox.ini | 7 +++---- 19 files changed, 40 insertions(+), 87 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a699a73d..9f4e8b45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,27 +13,20 @@ jobs: fail-fast: false matrix: - python-version: ["2.7", "3.6", "3.7", "3.8"] - django-version: ["1.11", "2.0", "2.2", "2.1", "3.0"] + python-version: ["3.6", "3.7", "3.8", "3.9"] + django-version: ["2.0", "2.2", "2.1", "3.0"] es-dsl-version: ["6.4", "7.4"] es-version: ["7.13.4"] exclude: - - python-version: "2.7" - django-version: "2.0" - - python-version: "2.7" - django-version: "2.1" - - python-version: "2.7" - django-version: "2.2" - - python-version: "2.7" - django-version: "3.0" - - - python-version: "3.8" - django-version: "1.11" - python-version: "3.8" django-version: "2.0" - python-version: "3.8" django-version: "2.1" + - python-version: "3.9" + django-version: "2.0" + - python-version: "3.9" + django-version: "2.1" steps: - name: Install and Run Elasticsearch diff --git a/README.rst b/README.rst index 81c46f90..dbf6e310 100644 --- a/README.rst +++ b/README.rst @@ -30,8 +30,8 @@ Features - Index fast using `parallel` indexing. - Requirements - - Django >= 1.11 - - Python 2.7, 3.5, 3.6, 3.7, 3.8 + - Django 2.0+ + - Python 3.6+ **Elasticsearch Compatibility:** The library is compatible with all Elasticsearch versions since 5.x diff --git a/django_elasticsearch_dsl/documents.py b/django_elasticsearch_dsl/documents.py index 027568fd..1cc031fd 100644 --- a/django_elasticsearch_dsl/documents.py +++ b/django_elasticsearch_dsl/documents.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from collections import deque from functools import partial @@ -7,7 +5,6 @@ from django.db import models from elasticsearch.helpers import bulk, parallel_bulk from elasticsearch_dsl import Document as DSLDocument -from six import iteritems from .exceptions import ModelFieldNotMappedError from .fields import ( @@ -51,8 +48,10 @@ models.UUIDField: KeywordField, } + class DocType(DSLDocument): _prepared_fields = [] + def __init__(self, related_instance_to_ignore=None, **kwargs): super(DocType, self).__init__(**kwargs) self._related_instance_to_ignore = related_instance_to_ignore @@ -97,7 +96,7 @@ def init_prepare(self): """ index_fields = getattr(self, '_fields', {}) fields = [] - for name, field in iteritems(index_fields): + for name, field in index_fields.items(): if not isinstance(field, DEDField): continue @@ -201,7 +200,7 @@ def _bulk(self, *args, **kwargs): def should_index_object(self, obj): """ - Overwriting this method and returning a boolean value + Overwriting this method and returning a boolean value should determine whether the object should be indexed. """ return True diff --git a/django_elasticsearch_dsl/fields.py b/django_elasticsearch_dsl/fields.py index d28ae3c4..1445c237 100644 --- a/django_elasticsearch_dsl/fields.py +++ b/django_elasticsearch_dsl/fields.py @@ -1,4 +1,3 @@ -import collections from types import MethodType from django.core.exceptions import ObjectDoesNotExist diff --git a/django_elasticsearch_dsl/indices.py b/django_elasticsearch_dsl/indices.py index 115874d5..57d32317 100644 --- a/django_elasticsearch_dsl/indices.py +++ b/django_elasticsearch_dsl/indices.py @@ -1,13 +1,11 @@ from copy import deepcopy from elasticsearch_dsl import Index as DSLIndex -from six import python_2_unicode_compatible from .apps import DEDConfig from .registries import registry -@python_2_unicode_compatible class Index(DSLIndex): def __init__(self, *args, **kwargs): super(Index, self).__init__(*args, **kwargs) diff --git a/django_elasticsearch_dsl/management/commands/search_index.py b/django_elasticsearch_dsl/management/commands/search_index.py index 80352c07..84795160 100644 --- a/django_elasticsearch_dsl/management/commands/search_index.py +++ b/django_elasticsearch_dsl/management/commands/search_index.py @@ -1,8 +1,5 @@ -from __future__ import unicode_literals, absolute_import - from django.conf import settings from django.core.management.base import BaseCommand, CommandError -from six.moves import input from ...registries import registry diff --git a/django_elasticsearch_dsl/registries.py b/django_elasticsearch_dsl/registries.py index 569442cb..4f1ba79d 100644 --- a/django_elasticsearch_dsl/registries.py +++ b/django_elasticsearch_dsl/registries.py @@ -5,8 +5,7 @@ from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ImproperlyConfigured -from elasticsearch_dsl import Field, AttrDict -from six import itervalues, iterkeys, iteritems +from elasticsearch_dsl import AttrDict from django_elasticsearch_dsl.exceptions import RedeclaredFieldError from .apps import DEDConfig @@ -28,7 +27,7 @@ def register(self, index, doc_class): for related in doc_class.django.related_models: self._related_models[related].add(doc_class.django.model) - for idx, docs in iteritems(self._indices): + for idx, docs in self._indices.items(): if index._name == idx._name: docs.add(doc_class) return @@ -154,13 +153,13 @@ def get_documents(self, models=None): if models is not None: return set(chain.from_iterable(self._models[model] for model in models if model in self._models)) - return set(chain.from_iterable(itervalues(self._indices))) + return set(chain.from_iterable(self._indices.values())) def get_models(self): """ Get all models in the registry """ - return set(iterkeys(self._models)) + return set(self._models.keys()) def get_indices(self, models=None): """ @@ -168,11 +167,11 @@ def get_indices(self, models=None): """ if models is not None: return set( - indice for indice, docs in iteritems(self._indices) + indice for indice, docs in self._indices.items() for doc in docs if doc.django.model in models ) - return set(iterkeys(self._indices)) + return set(self._indices.keys()) registry = DocumentRegistry() diff --git a/django_elasticsearch_dsl/signals.py b/django_elasticsearch_dsl/signals.py index 35a631c4..27774f98 100644 --- a/django_elasticsearch_dsl/signals.py +++ b/django_elasticsearch_dsl/signals.py @@ -1,11 +1,8 @@ -# encoding: utf-8 """ A convenient way to attach django-elasticsearch-dsl to Django's signals and cause things to index. """ -from __future__ import absolute_import - from django.db import models from django.dispatch import Signal diff --git a/docs/source/conf.py b/docs/source/conf.py index 21e7a789..0db284dd 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- # # This file is execfile()d with the current directory set to its # containing dir. diff --git a/example/test_app/migrations/0001_initial.py b/example/test_app/migrations/0001_initial.py index ff823fcc..3d78acb9 100644 --- a/example/test_app/migrations/0001_initial.py +++ b/example/test_app/migrations/0001_initial.py @@ -1,7 +1,4 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.11.5 on 2017-11-21 18:46 -from __future__ import unicode_literals - from django.db import migrations, models import django.db.models.deletion diff --git a/example/test_app/models.py b/example/test_app/models.py index c4537100..0f64ad25 100644 --- a/example/test_app/models.py +++ b/example/test_app/models.py @@ -1,10 +1,6 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals from django.db import models -from six import python_2_unicode_compatible -@python_2_unicode_compatible class Car(models.Model): TYPE_CHOICES = ( ('se', "Sedan"), @@ -37,7 +33,6 @@ def __str__(self): } -@python_2_unicode_compatible class Manufacturer(models.Model): name = models.CharField(max_length=255) country_code = models.CharField(max_length=2) @@ -51,7 +46,6 @@ def __str__(self): return self.name -@python_2_unicode_compatible class Category(models.Model): title = models.CharField(max_length=255) slug = models.CharField(max_length=255) @@ -60,7 +54,6 @@ def __str__(self): return self.title -@python_2_unicode_compatible class Ad(models.Model): title = models.CharField(max_length=255) description = models.TextField() diff --git a/setup.py b/setup.py index 291053c0..3576d871 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- import os import sys @@ -41,30 +40,25 @@ 'django_elasticsearch_dsl', ], include_package_data=True, - install_requires=[ - 'elasticsearch-dsl>=7.2.0<8.0.0', - 'six', - ], + install_requires=['elasticsearch-dsl>=7.2.0<8.0.0'], license="Apache Software License 2.0", zip_safe=False, keywords='django elasticsearch elasticsearch-dsl', classifiers=[ 'Development Status :: 3 - Alpha', 'Framework :: Django', - 'Framework :: Django :: 1.11', 'Framework :: Django :: 2.0', 'Framework :: Django :: 2.1', 'Framework :: Django :: 2.2', 'Framework :: Django :: 3.0', + 'Framework :: Django :: 3.2', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Natural Language :: English', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', ], ) diff --git a/tests/documents.py b/tests/documents.py index 20f90f41..08ef83f1 100644 --- a/tests/documents.py +++ b/tests/documents.py @@ -1,5 +1,5 @@ from elasticsearch_dsl import analyzer -from django_elasticsearch_dsl import Document, Index, fields +from django_elasticsearch_dsl import Document, fields from django_elasticsearch_dsl.registries import registry from .models import Ad, Category, Car, Manufacturer, Article @@ -160,6 +160,7 @@ class Index: name = 'test_articles' settings = index_settings + @registry.register_document class ArticleWithSlugAsIdDocument(Document): class Django: diff --git a/tests/models.py b/tests/models.py index 16c9fd5c..7beaac43 100644 --- a/tests/models.py +++ b/tests/models.py @@ -1,11 +1,7 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals from django.db import models from django.utils.translation import ugettext_lazy as _ -from six import python_2_unicode_compatible -@python_2_unicode_compatible class Car(models.Model): TYPE_CHOICES = ( ('se', "Sedan"), @@ -41,7 +37,6 @@ def __str__(self): } -@python_2_unicode_compatible class Manufacturer(models.Model): name = models.CharField(max_length=255, default=_("Test lazy tanslation")) country_code = models.CharField(max_length=2) @@ -58,7 +53,6 @@ def __str__(self): return self.name -@python_2_unicode_compatible class Category(models.Model): title = models.CharField(max_length=255) slug = models.CharField(max_length=255) @@ -71,7 +65,6 @@ def __str__(self): return self.title -@python_2_unicode_compatible class Ad(models.Model): title = models.CharField(max_length=255) description = models.TextField() @@ -89,7 +82,6 @@ def __str__(self): return self.title -@python_2_unicode_compatible class Article(models.Model): slug = models.CharField( max_length=255, diff --git a/tests/test_commands.py b/tests/test_commands.py index 6d787380..7707e55f 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1,9 +1,10 @@ +from io import StringIO + from mock import DEFAULT, Mock, patch from unittest import TestCase from django.core.management.base import CommandError from django.core.management import call_command -from six import StringIO from django_elasticsearch_dsl import Index from django_elasticsearch_dsl.management.commands.search_index import Command diff --git a/tests/test_documents.py b/tests/test_documents.py index ac449d36..ef3d16a1 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -3,18 +3,17 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ -from elasticsearch_dsl import GeoPoint, MetaField -from mock import patch, Mock, PropertyMock +from elasticsearch_dsl import GeoPoint +from mock import patch, Mock from django_elasticsearch_dsl import fields -from django_elasticsearch_dsl.documents import DocType, Document +from django_elasticsearch_dsl.documents import DocType from django_elasticsearch_dsl.exceptions import (ModelFieldNotMappedError, RedeclaredFieldError) from django_elasticsearch_dsl.registries import registry from tests import ES_MAJOR_VERSION from .models import Article -from .documents import ArticleDocument, ArticleWithSlugAsIdDocument class Car(models.Model): @@ -353,7 +352,7 @@ def test_init_prepare_correct(self): expect = { 'color': ("", - ("", "")), # py3, py2 + ("", "")), # py3, py2 'type': ("", ("","")), 'name': ("", @@ -375,8 +374,8 @@ def test_init_prepare_results(self): car = Car() setattr(car, 'name', "Tusla") setattr(car, 'price', 340123.21) - setattr(car, 'color', "polka-dots") # Overwritten by prepare function - setattr(car, 'pk', 4701) # Ignored, not in document + setattr(car, 'color', "polka-dots") # Overwritten by prepare function + setattr(car, 'pk', 4701) # Ignored, not in document setattr(car, 'type', "imaginary") self.assertEqual(d.prepare(car), {'color': 'blue', 'type': 'imaginary', 'name': 'Tusla', 'price': 340123.21}) diff --git a/tests/test_fields.py b/tests/test_fields.py index 47c862d7..8d331448 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -3,7 +3,6 @@ from django.db.models.fields.files import FieldFile from django.utils.translation import ugettext_lazy as _ from mock import Mock, NonCallableMock -from six import string_types from django_elasticsearch_dsl.exceptions import VariableLookupError from django_elasticsearch_dsl.fields import (BooleanField, ByteField, CompletionField, DEDField, @@ -63,9 +62,7 @@ def test_get_value_from_none(self): def test_get_value_from_lazy_object(self): field = DEDField(attr='translation') instance = NonCallableMock(translation=_("foo")) - self.assertIsInstance( - field.get_value_from_instance(instance), string_types - ) + self.assertIsInstance(field.get_value_from_instance(instance), str) self.assertEqual(field.get_value_from_instance(instance), "foo") diff --git a/tests/test_integration.py b/tests/test_integration.py index ed7ec665..b5b200ed 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -1,10 +1,10 @@ from datetime import datetime import unittest +from io import StringIO from django.core.management import call_command from django.test import TestCase from django.utils.translation import ugettext_lazy as _ -from six import StringIO from elasticsearch.exceptions import NotFoundError from elasticsearch_dsl import Index as DSLIndex @@ -17,7 +17,6 @@ car_index, CarDocument, CarWithPrepareDocument, - ManufacturerDocument, ArticleDocument, ArticleWithSlugAsIdDocument, index_settings @@ -359,8 +358,8 @@ def test_default_document_id(self): slug=article_slug, ) - # saving should create two documents (in the two indices): one with the - # Django object's id as the ES doc _id, and the other with the slug + # saving should create two documents (in the two indices): one with the + # Django object's id as the ES doc _id, and the other with the slug # as the ES _id article.save() @@ -377,8 +376,8 @@ def test_custom_document_id(self): slug=article_slug, ) - # saving should create two documents (in the two indices): one with the - # Django object's id as the ES doc _id, and the other with the slug + # saving should create two documents (in the two indices): one with the + # Django object's id as the ES doc _id, and the other with the slug # as the ES _id article.save() diff --git a/tox.ini b/tox.ini index 696893c4..dbf15423 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,6 @@ [tox] envlist = - py27-django-111-es74 - {py36,py37,py38}-django-{111,20,21,22,30}-{es64,es74} + {py36,py37,py38,py39}-django-{20,21,22,30,32}-{es64,es74} [testenv] setenv = @@ -9,17 +8,17 @@ setenv = commands = coverage run --source django_elasticsearch_dsl runtests.py {posargs} deps = - django-111: Django>=1.11,<2.0 django-20: Django>=2.0,<2.1 django-21: Django>=2.1,<2.2 django-22: Django>=2.2,<2.3 django-30: Django>=3.0,<3.1 + django-32: Django>=3.1,<3.2 es64: elasticsearch-dsl>=6.4.0,<7.0.0 es74: elasticsearch-dsl>=7.4.0,<8 -r{toxinidir}/requirements_test.txt basepython = - py27: python2.7 py36: python3.6 py37: python3.7 py38: python3.8 + py39: python3.9