Skip to content

Commit

Permalink
Merge pull request #78 from dbenzel/upgrade-python-django-support
Browse files Browse the repository at this point in the history
Uprate python constraints to 3.7-3.10; remove six; uprate django version constraints.
  • Loading branch information
epierce78 authored Mar 15, 2022
2 parents d84a28c + 5b010c7 commit 0b5f9b7
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 47 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @hearsaycorp/platform
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
max-parallel: 1
matrix:
python-version: [2.7, 3.5, 3.6, 3.7]
python-version: [3.7, 3.8, 3.9, '3.10']
services:
postgres:
image: postgres:11
Expand Down
26 changes: 10 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
import os
import sys

from setuptools import setup, find_packages
from setuptools import find_packages
from setuptools import setup
from setuptools.command.test import test as TestCommand


tests_require = (
'pytest<5.0',
'pytest>=6.2.5,<7.2',
'pytest-django',
)


install_requires = (
'Django>=1.11,<3.1',
'Django>=2.2,<3.3',
'richenum',
'six',
)


Expand All @@ -29,9 +28,9 @@ def finalize_options(self):
self.test_suite = True

def run_tests(self):
import django
import pytest
from django.conf import settings
import django

db_host = os.environ.get('DJANGO_DB_HOST')
db_engine = os.environ.get('DJANGO_DB_ENGINE', 'sqlite')
Expand Down Expand Up @@ -65,6 +64,7 @@ def run_tests(self):
settings.configure(
DEBUG=True,
DATABASES={'default': db_settings},
SECRET_KEY=os.environ.get('SECRET_KEY'),
CACHES={
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache'
Expand All @@ -87,7 +87,7 @@ def run_tests(self):

setup(
name='django-richenum',
version='3.8.0',
version='4.0.0',
description='Django Enum library for python.',
long_description=(
open('README.rst').read() + '\n\n' +
Expand All @@ -96,16 +96,10 @@ def run_tests(self):
classifiers=[
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: MIT License',
'Framework :: Django :: 1.11',
'Framework :: Django :: 2.1',
'Framework :: Django :: 2.2',
'Programming Language :: Python',
'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',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: Implementation :: CPython',
],
keywords='python django enum richenum',
Expand Down
8 changes: 4 additions & 4 deletions src/django_richenum/admin/options.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.contrib import admin

import six

from ..models.fields import IndexEnumField, LaxIndexEnumField, CanonicalNameEnumField
from ..models.fields import CanonicalNameEnumField
from ..models.fields import IndexEnumField
from ..models.fields import LaxIndexEnumField

RICH_ENUM_FORMFIELD_FOR_DBFIELD_DEFAULTS = {
IndexEnumField: {},
Expand All @@ -16,5 +16,5 @@ def __init__(self, *args, **kwargs):
super(RichEnumModelAdmin, self).__init__(*args, **kwargs)

# Update unspecified internal formfields
for model_field_cls, formfield_override_value in six.iteritems(RICH_ENUM_FORMFIELD_FOR_DBFIELD_DEFAULTS):
for model_field_cls, formfield_override_value in RICH_ENUM_FORMFIELD_FOR_DBFIELD_DEFAULTS.items():
self.formfield_overrides.setdefault(model_field_cls, formfield_override_value)
10 changes: 4 additions & 6 deletions src/django_richenum/forms/fields.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from abc import ABCMeta
from abc import abstractmethod
import six

from django import forms
from django.core.exceptions import ValidationError

from richenum import EnumLookupError, OrderedRichEnumValue

from richenum import EnumLookupError
from richenum import OrderedRichEnumValue

try:
from django.forms.fields import RenameFieldMethods # pylint: disable=no-name-in-module
Expand Down Expand Up @@ -76,7 +74,7 @@ def coerce_value(self, name):

# In Django 1.6, value is coerced already. Below 1.6, we need to manually coerce
def valid_value(self, value):
if isinstance(value, six.string_types):
if isinstance(value, str):
value = self.coerce_value(value)
return super(_BaseCanonicalField, self).valid_value(value)

Expand All @@ -98,7 +96,7 @@ def coerce_value(self, index):
# In Django 1.6, value is coerced already. Below 1.6, we need to manually coerce
def valid_value(self, value):
# In < Dango 1.6, this comes in as a string, so we should flip it to be an int
if isinstance(value, six.string_types):
if isinstance(value, str):
try:
value = int(value)
except ValueError as e:
Expand Down
20 changes: 9 additions & 11 deletions src/django_richenum/models/fields.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import six

from django.db import models

from richenum import RichEnumValue, OrderedRichEnumValue
from richenum import OrderedRichEnumValue
from richenum import RichEnumValue


# https://github.com/django/django/blob/64200c14e0072ba0ffef86da46b2ea82fd1e019a/django/db/models/fields/subclassing.py#L31-L44
Expand Down Expand Up @@ -61,7 +59,7 @@ def get_prep_value(self, value):
return None
elif isinstance(value, OrderedRichEnumValue):
return value.index
elif isinstance(value, six.integer_types):
elif isinstance(value, int):
return value
else:
raise TypeError('Cannot convert value: %s (%s) to an int.' % (value, type(value)))
Expand All @@ -80,7 +78,7 @@ def to_python(self, value):
return None
elif isinstance(value, OrderedRichEnumValue):
return value
elif isinstance(value, six.integer_types):
elif isinstance(value, int):
return self.enum.from_index(value)
else:
raise TypeError('Cannot interpret %s (%s) as an OrderedRichEnumValue.' % (value, type(value)))
Expand Down Expand Up @@ -114,19 +112,19 @@ class LaxIndexEnumField(IndexEnumField):
Mainly used to help migrate existing code that uses strings as database values.
'''
def get_prep_value(self, value):
if isinstance(value, six.string_types):
if isinstance(value, str):
return self.enum.from_canonical(value).index
return super(LaxIndexEnumField, self).get_prep_value(value)

def from_db_value(self, value, expression, connection, *args):
# context param is deprecated in Django 2.x will be removed in Django 3.x
# having *args allows this code to run in Django 1.x and Django 2.x
if isinstance(value, six.string_types):
if isinstance(value, str):
return self.enum.from_canonical(value)
return super(LaxIndexEnumField, self).from_db_value(value, expression, connection, *args)

def to_python(self, value):
if isinstance(value, six.string_types):
if isinstance(value, str):
return self.enum.from_canonical(value)
return super(LaxIndexEnumField, self).to_python(value)

Expand Down Expand Up @@ -170,7 +168,7 @@ def get_prep_value(self, value):
return None
elif isinstance(value, RichEnumValue):
return value.canonical_name
elif isinstance(value, six.string_types):
elif isinstance(value, str):
return value
else:
raise TypeError('Cannot convert value: %s (%s) to a string.' % (value, type(value)))
Expand All @@ -189,7 +187,7 @@ def to_python(self, value):
return None
elif isinstance(value, RichEnumValue):
return value
elif isinstance(value, six.string_types):
elif isinstance(value, str):
return self.enum.from_canonical(value)
else:
raise TypeError('Cannot interpret %s (%s) as an RichEnumValue.' % (value, type(value)))
Expand Down
18 changes: 9 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
[tox]
envlist = {py27,py35}-django{111}-{sqlite,mysql,postgres},
{py35,py36,py37}-django{210,220}-{sqlite,mysql,postgres},lint
{py36,py37}-django{300}-{sqlite,mysql,postgres},lint
envlist = {py37,py38,py39,py310}-django{220}-{sqlite,mysql,postgres},lint
{py37,py38,py39,py310}-django{300,310,320}-{sqlite,mysql,postgres},lint

[gh-actions]
python =
2.7: py27
3.5: py35
3.6: py36
3.7: py37
3.8: py38
3.9: py39
3.10: py310

[testenv]
deps =
django111: Django>=1.11,<2.0
django210: Django>=2.1,<2.2
django220: Django>=2.2,<2.3
django300: Django>=2.3,<3.1
pytest
django310: Django>=3.1,<3.2
django320: Django>=3.2,<3.3
pytest>=6.2.5,<7.2
pytest-django
mysqlclient
psycopg2
Expand All @@ -31,6 +30,7 @@ setenv =
postgres: DJANGO_DB_ENGINE = postgres
postgres: DJANGO_DB_USER = travis
postgres: DJANGO_DB_PASSWORD = travis
SECRET_KEY = placeholder # required env variable for django>=3.2

commands =
python setup.py test
Expand Down

0 comments on commit 0b5f9b7

Please sign in to comment.