Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop Python 2 support #801

Merged
merged 1 commit into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ env:
matrix:
fast_finish: true
include:
- { python: "2.7", env: DJANGO="==1.11.*" }

- { python: "3.7", env: DJANGO="==2.0.*", sudo: true }
- { python: "3.7", env: DJANGO="==2.1.*", sudo: true }
- { python: "3.7", env: DJANGO="==2.2.*", sudo: true }
Expand All @@ -32,7 +30,7 @@ services:
- mysql
install:
# mysqlclient 1.4 is not compatible with Django 1.11
- pip install flake8 coverage mock sphinx django$DJANGO psycopg2 mysqlclient==1.3.14 -e .
- pip install flake8 coverage sphinx django$DJANGO psycopg2 mysqlclient==1.3.14 -e .
before_script:
- mysql -e 'create database test_project'
- psql -c 'create database test_project;' -U postgres;
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version control for model instances.
Requirements
============

- Python 2.7 or later
- Python 3.5 or later
- Django 1.11 or later

Features
Expand Down
2 changes: 1 addition & 1 deletion docs/admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ A subclass of ``django.contrib.ModelAdmin`` providing rollback and recovery.

def reversion_register(self, model, **options):
options["exclude"] = ("some_field",)
super(YourModelAdmin, self).reversion_register(model, **options)
super().reversion_register(model, **options)

``model``
The model that will be registered with django-reversion.
Expand Down
17 changes: 8 additions & 9 deletions reversion/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
import json
from contextlib import contextmanager
from django.db import models, transaction, connection
Expand Down Expand Up @@ -74,15 +73,15 @@ def log_addition(self, request, object, change_message=None):
set_comment(json.dumps(change_message))
else:
set_comment(change_message)
super(VersionAdmin, self).log_addition(request, object, change_message)
super().log_addition(request, object, change_message)

def log_change(self, request, object, message):
if is_active():
if isinstance(message, list):
set_comment(json.dumps(message))
else:
set_comment(message)
super(VersionAdmin, self).log_change(request, object, message)
super().log_change(request, object, message)

# Auto-registration.

Expand Down Expand Up @@ -128,7 +127,7 @@ def _reversion_introspect_inline_admin(self, inline):
return inline_model, follow_field

def __init__(self, *args, **kwargs):
super(VersionAdmin, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
# Automatically register models if required.
if not is_registered(self.model):
inline_fields = ()
Expand All @@ -141,7 +140,7 @@ def __init__(self, *args, **kwargs):
self._reversion_autoregister(self.model, inline_fields)

def get_urls(self):
urls = super(VersionAdmin, self).get_urls()
urls = super().get_urls()
admin_site = self.admin_site
opts = self.model._meta
info = opts.app_label, opts.model_name,
Expand All @@ -156,11 +155,11 @@ def get_urls(self):

def add_view(self, request, form_url='', extra_context=None):
with self.create_revision(request):
return super(VersionAdmin, self).add_view(request, form_url, extra_context)
return super().add_view(request, form_url, extra_context)

def change_view(self, request, object_id, form_url='', extra_context=None):
with self.create_revision(request):
return super(VersionAdmin, self).change_view(request, object_id, form_url, extra_context)
return super().change_view(request, object_id, form_url, extra_context)

def _reversion_revisionform_view(self, request, version, template_name, extra_context=None):
# Check that database transactions are supported.
Expand Down Expand Up @@ -233,7 +232,7 @@ def changelist_view(self, request, extra_context=None):
"has_change_permission": self.has_change_permission(request),
}
context.update(extra_context or {})
return super(VersionAdmin, self).changelist_view(request, context)
return super().changelist_view(request, context)

def recoverlist_view(self, request, extra_context=None):
"""Displays a deleted model to allow recovery."""
Expand Down Expand Up @@ -289,4 +288,4 @@ def history_view(self, request, object_id, extra_context=None):
# Compile the context.
context = {"action_list": action_list}
context.update(extra_context or {})
return super(VersionAdmin, self).history_view(request, object_id, context)
return super().history_view(request, object_id, context)
3 changes: 1 addition & 2 deletions reversion/management/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
from django.apps import apps
from django.conf import settings
from django.contrib import admin
Expand All @@ -9,7 +8,7 @@
class BaseRevisionCommand(BaseCommand):

def add_arguments(self, parser):
super(BaseRevisionCommand, self).add_arguments(parser)
super().add_arguments(parser)
parser.add_argument(
"app_label",
metavar="app_label",
Expand Down
4 changes: 1 addition & 3 deletions reversion/management/commands/createinitialrevisions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import json

from django.apps import apps
Expand All @@ -15,7 +13,7 @@ class Command(BaseRevisionCommand):
help = "Creates initial revisions for a given app [and model]."

def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
super().add_arguments(parser)
parser.add_argument(
"--comment",
action="store",
Expand Down
3 changes: 1 addition & 2 deletions reversion/management/commands/deleterevisions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
from datetime import timedelta
from django.db import transaction, models, router
from django.utils import timezone
Expand All @@ -11,7 +10,7 @@ class Command(BaseRevisionCommand):
help = "Deletes revisions for a given app [and model]."

def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
super().add_arguments(parser)
parser.add_argument(
"--days",
default=0,
Expand Down
2 changes: 1 addition & 1 deletion reversion/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RevisionMiddleware(object):
atomic = True

def __init__(self, get_response=None):
super(RevisionMiddleware, self).__init__()
super().__init__()
# Support Django 1.10 middleware.
if get_response is not None:
self.get_response = create_revision(
Expand Down
3 changes: 0 additions & 3 deletions reversion/migrations/0001_squashed_0004_auto_20160611_1202.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-06-06 13:22
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
Expand Down
10 changes: 3 additions & 7 deletions reversion/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from collections import defaultdict
from itertools import chain, groupby

Expand All @@ -13,7 +11,7 @@
from django.db import IntegrityError, connections, models, router, transaction
from django.db.models.deletion import Collector
from django.db.models.functions import Cast
from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.encoding import force_text
from django.utils.functional import cached_property
from django.utils.translation import ugettext
from django.utils.translation import ugettext_lazy as _
Expand All @@ -39,7 +37,6 @@ def _safe_revert(versions):
_safe_revert(unreverted_versions)


@python_2_unicode_compatible
class Revision(models.Model):

"""A group of related serialized versions."""
Expand Down Expand Up @@ -171,7 +168,6 @@ def get_unique(self):
last_key = key


@python_2_unicode_compatible
class Version(models.Model):

"""A saved version of a database model."""
Expand Down Expand Up @@ -309,11 +305,11 @@ class _Str(models.Func):
template = "%(function)s(%(expressions)s as %(db_type)s)"

def __init__(self, expression):
super(_Str, self).__init__(expression, output_field=models.TextField())
super().__init__(expression, output_field=models.TextField())

def as_sql(self, compiler, connection):
self.extra["db_type"] = self.output_field.db_type(connection)
return super(_Str, self).as_sql(compiler, connection)
return super().as_sql(compiler, connection)


def _safe_subquery(method, left_query, left_field_name, right_subquery, right_field_name):
Expand Down
5 changes: 2 additions & 3 deletions reversion/revisions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
from collections import namedtuple, defaultdict
from contextlib import contextmanager
from functools import wraps
Expand All @@ -10,7 +9,7 @@
from django.db.models.query import QuerySet
from django.db.models.signals import post_save, m2m_changed
from django.utils.encoding import force_text
from django.utils import timezone, six
from django.utils import timezone
from reversion.errors import RevisionManagementError, RegistrationError
from reversion.signals import pre_revision_commit, post_revision_commit

Expand Down Expand Up @@ -355,7 +354,7 @@ def _get_senders_and_signals(model):
opts = model._meta.concrete_model._meta
for field in opts.local_many_to_many:
m2m_model = field.remote_field.through
if isinstance(m2m_model, six.string_types):
if isinstance(m2m_model, str):
if "." not in m2m_model:
m2m_model = "{app_label}.{m2m_model}".format(
app_label=opts.app_label,
Expand Down
2 changes: 1 addition & 1 deletion reversion/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class RevisionMixin(object):
revision_atomic = True

def __init__(self, *args, **kwargs):
super(RevisionMixin, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.dispatch = create_revision(
manage_manually=self.revision_manage_manually,
using=self.revision_using,
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
Expand Down
19 changes: 6 additions & 13 deletions tests/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django # noqa
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
3 changes: 0 additions & 3 deletions tests/test_app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-06-14 10:27
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion

Expand Down
24 changes: 11 additions & 13 deletions tests/test_app/tests/base.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
from datetime import timedelta
from importlib import import_module, reload
from io import StringIO

from django.conf import settings
from django.contrib.auth.models import User
from django.core.management import call_command
from django.urls import clear_url_caches
from django.test import TestCase, TransactionTestCase
from django.test.utils import override_settings
from django.utils import timezone
from django.utils.six import StringIO, assertRegex

import reversion
from reversion.models import Revision, Version
from test_app.models import TestModel, TestModelParent
from importlib import import_module
try:
from importlib import reload
except ImportError: # Python 2.7
pass


# Test helpers.
Expand All @@ -28,12 +26,12 @@ def reloadUrls(self):
clear_url_caches()

def setUp(self):
super(TestBaseMixin, self).setUp()
super().setUp()
for model in list(reversion.get_registered_models()):
reversion.unregister(model)

def tearDown(self):
super(TestBaseMixin, self).tearDown()
super().tearDown()
for model in list(reversion.get_registered_models()):
reversion.unregister(model)

Expand All @@ -48,7 +46,7 @@ def assertSingleRevision(self, objects, user=None, comment="", meta_names=(), da
revision = Version.objects.using(using).get_for_object(objects[0], model_db=model_db).get().revision
self.assertEqual(revision.user, user)
if hasattr(comment, 'pattern'):
assertRegex(self, revision.get_comment(), comment)
self.assertRegex(revision.get_comment(), comment)
elif comment is not None: # Allow a wildcard comment.
self.assertEqual(revision.get_comment(), comment)
self.assertAlmostEqual(revision.date_created, date_created or timezone.now(), delta=timedelta(seconds=1))
Expand Down Expand Up @@ -81,22 +79,22 @@ class TestBaseTransaction(TestBaseMixin, TransactionTestCase):
class TestModelMixin(object):

def setUp(self):
super(TestModelMixin, self).setUp()
super().setUp()
reversion.register(TestModel)


class TestModelParentMixin(TestModelMixin):

def setUp(self):
super(TestModelParentMixin, self).setUp()
super().setUp()
reversion.register(TestModelParent, follow=("testmodel_ptr",))


@override_settings(PASSWORD_HASHERS=["django.contrib.auth.hashers.MD5PasswordHasher"])
class UserMixin(TestBase):

def setUp(self):
super(UserMixin, self).setUp()
super().setUp()
self.user = User(username="test", is_staff=True, is_superuser=True)
self.user.set_password("password")
self.user.save()
Expand All @@ -105,5 +103,5 @@ def setUp(self):
class LoginMixin(UserMixin):

def setUp(self):
super(LoginMixin, self).setUp()
super().setUp()
self.client.login(username="test", password="password")
Loading