Skip to content

Commit 0b5f9b7

Browse files
authored
Merge pull request #78 from dbenzel/upgrade-python-django-support
Uprate python constraints to 3.7-3.10; remove six; uprate django version constraints.
2 parents d84a28c + 5b010c7 commit 0b5f9b7

File tree

7 files changed

+38
-47
lines changed

7 files changed

+38
-47
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @hearsaycorp/platform

.github/workflows/tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
max-parallel: 1
1717
matrix:
18-
python-version: [2.7, 3.5, 3.6, 3.7]
18+
python-version: [3.7, 3.8, 3.9, '3.10']
1919
services:
2020
postgres:
2121
image: postgres:11

setup.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@
22
import os
33
import sys
44

5-
from setuptools import setup, find_packages
5+
from setuptools import find_packages
6+
from setuptools import setup
67
from setuptools.command.test import test as TestCommand
78

8-
99
tests_require = (
10-
'pytest<5.0',
10+
'pytest>=6.2.5,<7.2',
1111
'pytest-django',
1212
)
1313

1414

1515
install_requires = (
16-
'Django>=1.11,<3.1',
16+
'Django>=2.2,<3.3',
1717
'richenum',
18-
'six',
1918
)
2019

2120

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

3130
def run_tests(self):
31+
import django
3232
import pytest
3333
from django.conf import settings
34-
import django
3534

3635
db_host = os.environ.get('DJANGO_DB_HOST')
3736
db_engine = os.environ.get('DJANGO_DB_ENGINE', 'sqlite')
@@ -65,6 +64,7 @@ def run_tests(self):
6564
settings.configure(
6665
DEBUG=True,
6766
DATABASES={'default': db_settings},
67+
SECRET_KEY=os.environ.get('SECRET_KEY'),
6868
CACHES={
6969
'default': {
7070
'BACKEND': 'django.core.cache.backends.dummy.DummyCache'
@@ -87,7 +87,7 @@ def run_tests(self):
8787

8888
setup(
8989
name='django-richenum',
90-
version='3.8.0',
90+
version='4.0.0',
9191
description='Django Enum library for python.',
9292
long_description=(
9393
open('README.rst').read() + '\n\n' +
@@ -96,16 +96,10 @@ def run_tests(self):
9696
classifiers=[
9797
'Development Status :: 5 - Production/Stable',
9898
'License :: OSI Approved :: MIT License',
99-
'Framework :: Django :: 1.11',
100-
'Framework :: Django :: 2.1',
101-
'Framework :: Django :: 2.2',
102-
'Programming Language :: Python',
103-
'Programming Language :: Python :: 2',
104-
'Programming Language :: Python :: 2.7',
105-
'Programming Language :: Python :: 3',
106-
'Programming Language :: Python :: 3.5',
107-
'Programming Language :: Python :: 3.6',
10899
'Programming Language :: Python :: 3.7',
100+
'Programming Language :: Python :: 3.8',
101+
'Programming Language :: Python :: 3.9',
102+
'Programming Language :: Python :: 3.10',
109103
'Programming Language :: Python :: Implementation :: CPython',
110104
],
111105
keywords='python django enum richenum',

src/django_richenum/admin/options.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from django.contrib import admin
22

3-
import six
4-
5-
from ..models.fields import IndexEnumField, LaxIndexEnumField, CanonicalNameEnumField
3+
from ..models.fields import CanonicalNameEnumField
4+
from ..models.fields import IndexEnumField
5+
from ..models.fields import LaxIndexEnumField
66

77
RICH_ENUM_FORMFIELD_FOR_DBFIELD_DEFAULTS = {
88
IndexEnumField: {},
@@ -16,5 +16,5 @@ def __init__(self, *args, **kwargs):
1616
super(RichEnumModelAdmin, self).__init__(*args, **kwargs)
1717

1818
# Update unspecified internal formfields
19-
for model_field_cls, formfield_override_value in six.iteritems(RICH_ENUM_FORMFIELD_FOR_DBFIELD_DEFAULTS):
19+
for model_field_cls, formfield_override_value in RICH_ENUM_FORMFIELD_FOR_DBFIELD_DEFAULTS.items():
2020
self.formfield_overrides.setdefault(model_field_cls, formfield_override_value)

src/django_richenum/forms/fields.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
from abc import ABCMeta
22
from abc import abstractmethod
3-
import six
43

54
from django import forms
65
from django.core.exceptions import ValidationError
7-
8-
from richenum import EnumLookupError, OrderedRichEnumValue
9-
6+
from richenum import EnumLookupError
7+
from richenum import OrderedRichEnumValue
108

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

7775
# In Django 1.6, value is coerced already. Below 1.6, we need to manually coerce
7876
def valid_value(self, value):
79-
if isinstance(value, six.string_types):
77+
if isinstance(value, str):
8078
value = self.coerce_value(value)
8179
return super(_BaseCanonicalField, self).valid_value(value)
8280

@@ -98,7 +96,7 @@ def coerce_value(self, index):
9896
# In Django 1.6, value is coerced already. Below 1.6, we need to manually coerce
9997
def valid_value(self, value):
10098
# In < Dango 1.6, this comes in as a string, so we should flip it to be an int
101-
if isinstance(value, six.string_types):
99+
if isinstance(value, str):
102100
try:
103101
value = int(value)
104102
except ValueError as e:

src/django_richenum/models/fields.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import six
2-
31
from django.db import models
4-
5-
from richenum import RichEnumValue, OrderedRichEnumValue
2+
from richenum import OrderedRichEnumValue
3+
from richenum import RichEnumValue
64

75

86
# https://github.com/django/django/blob/64200c14e0072ba0ffef86da46b2ea82fd1e019a/django/db/models/fields/subclassing.py#L31-L44
@@ -61,7 +59,7 @@ def get_prep_value(self, value):
6159
return None
6260
elif isinstance(value, OrderedRichEnumValue):
6361
return value.index
64-
elif isinstance(value, six.integer_types):
62+
elif isinstance(value, int):
6563
return value
6664
else:
6765
raise TypeError('Cannot convert value: %s (%s) to an int.' % (value, type(value)))
@@ -80,7 +78,7 @@ def to_python(self, value):
8078
return None
8179
elif isinstance(value, OrderedRichEnumValue):
8280
return value
83-
elif isinstance(value, six.integer_types):
81+
elif isinstance(value, int):
8482
return self.enum.from_index(value)
8583
else:
8684
raise TypeError('Cannot interpret %s (%s) as an OrderedRichEnumValue.' % (value, type(value)))
@@ -114,19 +112,19 @@ class LaxIndexEnumField(IndexEnumField):
114112
Mainly used to help migrate existing code that uses strings as database values.
115113
'''
116114
def get_prep_value(self, value):
117-
if isinstance(value, six.string_types):
115+
if isinstance(value, str):
118116
return self.enum.from_canonical(value).index
119117
return super(LaxIndexEnumField, self).get_prep_value(value)
120118

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

128126
def to_python(self, value):
129-
if isinstance(value, six.string_types):
127+
if isinstance(value, str):
130128
return self.enum.from_canonical(value)
131129
return super(LaxIndexEnumField, self).to_python(value)
132130

@@ -170,7 +168,7 @@ def get_prep_value(self, value):
170168
return None
171169
elif isinstance(value, RichEnumValue):
172170
return value.canonical_name
173-
elif isinstance(value, six.string_types):
171+
elif isinstance(value, str):
174172
return value
175173
else:
176174
raise TypeError('Cannot convert value: %s (%s) to a string.' % (value, type(value)))
@@ -189,7 +187,7 @@ def to_python(self, value):
189187
return None
190188
elif isinstance(value, RichEnumValue):
191189
return value
192-
elif isinstance(value, six.string_types):
190+
elif isinstance(value, str):
193191
return self.enum.from_canonical(value)
194192
else:
195193
raise TypeError('Cannot interpret %s (%s) as an RichEnumValue.' % (value, type(value)))

tox.ini

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
[tox]
2-
envlist = {py27,py35}-django{111}-{sqlite,mysql,postgres},
3-
{py35,py36,py37}-django{210,220}-{sqlite,mysql,postgres},lint
4-
{py36,py37}-django{300}-{sqlite,mysql,postgres},lint
2+
envlist = {py37,py38,py39,py310}-django{220}-{sqlite,mysql,postgres},lint
3+
{py37,py38,py39,py310}-django{300,310,320}-{sqlite,mysql,postgres},lint
54

65
[gh-actions]
76
python =
8-
2.7: py27
9-
3.5: py35
10-
3.6: py36
117
3.7: py37
8+
3.8: py38
9+
3.9: py39
10+
3.10: py310
1211

1312
[testenv]
1413
deps =
15-
django111: Django>=1.11,<2.0
16-
django210: Django>=2.1,<2.2
1714
django220: Django>=2.2,<2.3
1815
django300: Django>=2.3,<3.1
19-
pytest
16+
django310: Django>=3.1,<3.2
17+
django320: Django>=3.2,<3.3
18+
pytest>=6.2.5,<7.2
2019
pytest-django
2120
mysqlclient
2221
psycopg2
@@ -31,6 +30,7 @@ setenv =
3130
postgres: DJANGO_DB_ENGINE = postgres
3231
postgres: DJANGO_DB_USER = travis
3332
postgres: DJANGO_DB_PASSWORD = travis
33+
SECRET_KEY = placeholder # required env variable for django>=3.2
3434

3535
commands =
3636
python setup.py test

0 commit comments

Comments
 (0)