Skip to content

Commit

Permalink
Remove six and Python 2 compat code (#257)
Browse files Browse the repository at this point in the history
* Remove six

* Remove character encoding

* Remove UnicodeMixin

* Include Python 3.12

* Tests against Python 3.12 in CI

* Update version

Closes gh-255
Closes gh-202
  • Loading branch information
bennylope authored Nov 23, 2023
1 parent c92c7a1 commit 571b51e
Show file tree
Hide file tree
Showing 60 changed files with 180 additions and 172 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v1
Expand Down
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
History
=======

2.3.0
-----

* Remove `six` dependency
* Start testing against Python 3.12

2.2.0
-----

Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# django-organizations documentation build configuration file, created by
# sphinx-quickstart on Wed Feb 22 12:22:14 2012.
Expand Down
5 changes: 0 additions & 5 deletions example/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [migrations.swappable_dependency(settings.AUTH_USER_MODEL)]
Expand Down Expand Up @@ -65,7 +64,6 @@ class Migration(migrations.Migration):
"ordering": ["name"],
"abstract": False,
},
bases=(organizations.base.UnicodeMixin, models.Model),
),
migrations.CreateModel(
name="AccountUser",
Expand Down Expand Up @@ -117,7 +115,6 @@ class Migration(migrations.Migration):
"abstract": False,
"unique_together": {("user", "organization")},
},
bases=(organizations.base.UnicodeMixin, models.Model),
),
migrations.CreateModel(
name="AccountOwner",
Expand Down Expand Up @@ -164,7 +161,6 @@ class Migration(migrations.Migration):
"verbose_name_plural": "organization owners",
"abstract": False,
},
bases=(organizations.base.UnicodeMixin, models.Model),
),
migrations.CreateModel(
name="AccountInvitation",
Expand Down Expand Up @@ -226,7 +222,6 @@ class Migration(migrations.Migration):
),
],
options={"abstract": False},
bases=(organizations.base.UnicodeMixin, models.Model),
),
migrations.AddField(
model_name="account",
Expand Down
5 changes: 0 additions & 5 deletions example/vendors/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand Down Expand Up @@ -78,7 +77,6 @@ class Migration(migrations.Migration):
"ordering": ["name"],
"abstract": False,
},
bases=(organizations.base.UnicodeMixin, models.Model),
),
migrations.CreateModel(
name="VendorUser",
Expand Down Expand Up @@ -134,7 +132,6 @@ class Migration(migrations.Migration):
"abstract": False,
"unique_together": {("user", "organization")},
},
bases=(organizations.base.UnicodeMixin, models.Model),
),
migrations.CreateModel(
name="VendorOwner",
Expand Down Expand Up @@ -181,7 +178,6 @@ class Migration(migrations.Migration):
"verbose_name_plural": "organization owners",
"abstract": False,
},
bases=(organizations.base.UnicodeMixin, models.Model),
),
migrations.CreateModel(
name="VendorInvitation",
Expand Down Expand Up @@ -243,7 +239,6 @@ class Migration(migrations.Migration):
),
],
options={"abstract": False},
bases=(organizations.base.UnicodeMixin, models.Model),
),
migrations.AddField(
model_name="vendor",
Expand Down
1 change: 0 additions & 1 deletion manage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Management command entry point for working with migrations
"""
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ALL_INTERPRETERS = (DEFAULT_INTERPRETER,)


DEV_INSTALL_REQUIREMENTS = ("six", "django-autoslug")
DEV_INSTALL_REQUIREMENTS = ["django-autoslug"]


def get_path(*names):
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ packages = find:
package_dir=
=src
install_requires =
six
Django>=3.2.0
django-extensions>=2.0.8
python_requires = >=3.8
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
See setup.cfg for packaging settings
"""
Expand Down
2 changes: 1 addition & 1 deletion src/organizations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = "Ben Lopatin"
__email__ = "[email protected]"
__version__ = "2.2.0"
__version__ = "2.3.0"
11 changes: 5 additions & 6 deletions src/organizations/abstract.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

import warnings

Expand All @@ -7,12 +6,12 @@
from django.urls import reverse
from django.utils.translation import gettext_lazy as _

import six

from organizations.base import AbstractBaseInvitation
from organizations.base import AbstractBaseOrganization
from organizations.base import AbstractBaseOrganizationOwner
from organizations.base import AbstractBaseOrganizationUser
from organizations.base import with_metaclass
from organizations.base import OrgMeta
from organizations.fields import AutoCreatedField
from organizations.fields import AutoLastModifiedField
Expand Down Expand Up @@ -68,7 +67,7 @@ class Meta:


class AbstractOrganization(
six.with_metaclass(OrgMeta, SharedBaseModel, AbstractBaseOrganization)
with_metaclass(OrgMeta, SharedBaseModel, AbstractBaseOrganization)
):
"""
Abstract Organization model.
Expand Down Expand Up @@ -182,7 +181,7 @@ def is_owner(self, user):


class AbstractOrganizationUser(
six.with_metaclass(OrgMeta, SharedBaseModel, AbstractBaseOrganizationUser)
with_metaclass(OrgMeta, SharedBaseModel, AbstractBaseOrganizationUser)
):
"""
Abstract OrganizationUser model
Expand Down Expand Up @@ -231,7 +230,7 @@ def get_absolute_url(self):


class AbstractOrganizationOwner(
six.with_metaclass(OrgMeta, SharedBaseModel, AbstractBaseOrganizationOwner)
with_metaclass(OrgMeta, SharedBaseModel, AbstractBaseOrganizationOwner)
):
"""
Abstract OrganizationOwner model
Expand Down Expand Up @@ -262,7 +261,7 @@ def save(self, *args, **kwargs):


class AbstractOrganizationInvitation(
six.with_metaclass(OrgMeta, SharedBaseModel, AbstractBaseInvitation)
with_metaclass(OrgMeta, SharedBaseModel, AbstractBaseInvitation)
):
"""
Abstract OrganizationInvitationBase model
Expand Down
1 change: 0 additions & 1 deletion src/organizations/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

from django.contrib import admin

Expand Down
1 change: 0 additions & 1 deletion src/organizations/app_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

from django.conf import settings
from django.contrib.auth.models import User
Expand Down
1 change: 0 additions & 1 deletion src/organizations/apps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

from django.apps import AppConfig

Expand Down
1 change: 0 additions & 1 deletion src/organizations/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

from importlib import import_module
from typing import Optional # noqa
Expand Down
1 change: 0 additions & 1 deletion src/organizations/backends/defaults.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

"""Backend classes should provide common interface"""

Expand Down
1 change: 0 additions & 1 deletion src/organizations/backends/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

from django import forms
from django.contrib.auth.forms import UserCreationForm
Expand Down
1 change: 0 additions & 1 deletion src/organizations/backends/modeled.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

"""
Invitations that use an invitation model
Expand Down
26 changes: 12 additions & 14 deletions src/organizations/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

import uuid

Expand All @@ -9,22 +8,21 @@
from django.urls import reverse
from django.utils.translation import gettext_lazy as _

import six

from organizations import signals
from organizations.managers import ActiveOrgManager
from organizations.managers import OrgManager

USER_MODEL = getattr(settings, "AUTH_USER_MODEL", "auth.User")


class UnicodeMixin:
"""
Python 2 and 3 string representation support.
# Extracted from six
def with_metaclass(meta, *bases):
class metaclass(type):
def __new__(cls, name, this_bases, d):
return meta(name, bases, d)

return type.__new__(metaclass, "temporary_class", (), {})

Legacy cruft. Removing entirely even from migrations affects the
meta class creation.
"""


class OrgMeta(ModelBase):

Check failure on line 28 in src/organizations/base.py

View workflow job for this annotation

GitHub Actions / flake8

src/organizations/base.py#L28

[E303] too many blank lines
Expand All @@ -47,7 +45,7 @@ class OrgMeta(ModelBase):

def __new__(cls, name, bases, attrs): # noqa
# Borrowed from Django-polymorphic
# Workaround compatibility issue with six.with_metaclass() and custom
# Workaround compatibility issue with with_metaclass() and custom
# Django model metaclasses:
if not attrs and name == "NewBase":
return super(OrgMeta, cls).__new__(cls, name, bases, attrs)
Expand Down Expand Up @@ -242,7 +240,7 @@ def is_member(self, user):
return True if user in self.users.all() else False


class OrganizationBase(six.with_metaclass(OrgMeta, AbstractBaseOrganization)):
class OrganizationBase(with_metaclass(OrgMeta, AbstractBaseOrganization)):
class Meta(AbstractBaseOrganization.Meta):
abstract = True

Expand Down Expand Up @@ -293,7 +291,7 @@ def name(self):
return str(self.user)


class OrganizationUserBase(six.with_metaclass(OrgMeta, AbstractBaseOrganizationUser)):
class OrganizationUserBase(with_metaclass(OrgMeta, AbstractBaseOrganizationUser)):
class Meta(AbstractBaseOrganizationUser.Meta):
abstract = True

Expand All @@ -310,7 +308,7 @@ def __str__(self):
return "{0}: {1}".format(self.organization, self.organization_user)


class OrganizationOwnerBase(six.with_metaclass(OrgMeta, AbstractBaseOrganizationOwner)):
class OrganizationOwnerBase(with_metaclass(OrgMeta, AbstractBaseOrganizationOwner)):
class Meta(AbstractBaseOrganizationOwner.Meta):
abstract = True

Expand Down Expand Up @@ -378,6 +376,6 @@ def invitation_token(self):
raise NotImplementedError


class OrganizationInvitationBase(six.with_metaclass(OrgMeta, AbstractBaseInvitation)):
class OrganizationInvitationBase(with_metaclass(OrgMeta, AbstractBaseInvitation)):
class Meta(AbstractBaseInvitation.Meta):
abstract = True
1 change: 0 additions & 1 deletion src/organizations/base_admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

from django.contrib import admin

Expand Down
1 change: 0 additions & 1 deletion src/organizations/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

class OwnershipRequired(Exception):
"""
Expand Down
1 change: 0 additions & 1 deletion src/organizations/fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Most of this code extracted and borrowed from django-model-utils
Expand Down
1 change: 0 additions & 1 deletion src/organizations/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

from django import forms
from django.contrib.auth import get_user_model
Expand Down
1 change: 0 additions & 1 deletion src/organizations/managers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

from django.db import models

Expand Down
4 changes: 0 additions & 4 deletions src/organizations/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [migrations.swappable_dependency(settings.AUTH_USER_MODEL)]
Expand Down Expand Up @@ -65,7 +64,6 @@ class Migration(migrations.Migration):
"ordering": ["name"],
"abstract": False,
},
bases=(organizations.base.UnicodeMixin, models.Model),
),
migrations.CreateModel(
name="OrganizationOwner",
Expand Down Expand Up @@ -105,7 +103,6 @@ class Migration(migrations.Migration):
"verbose_name_plural": "organization owners",
"abstract": False,
},
bases=(organizations.base.UnicodeMixin, models.Model),
),
migrations.CreateModel(
name="OrganizationUser",
Expand Down Expand Up @@ -155,7 +152,6 @@ class Migration(migrations.Migration):
"ordering": ["organization", "user"],
"abstract": False,
},
bases=(organizations.base.UnicodeMixin, models.Model),
),
migrations.AddField(
model_name="organizationowner",
Expand Down
2 changes: 0 additions & 2 deletions src/organizations/migrations/0002_model_update.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
from django.db import migrations

import organizations.fields


class Migration(migrations.Migration):

dependencies = [("organizations", "0001_initial")]

operations = [
Expand Down
2 changes: 0 additions & 2 deletions src/organizations/migrations/0003_field_fix_and_editable.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
from django.db import migrations

import organizations.fields


class Migration(migrations.Migration):

dependencies = [("organizations", "0002_model_update")]

operations = [
Expand Down
Loading

0 comments on commit 571b51e

Please sign in to comment.