Skip to content

Commit

Permalink
Merge pull request #105 from jazzband/83-bump-django-python-versions
Browse files Browse the repository at this point in the history
Drop Python-3.6 and Django-2.2 support on 2022-04 #83
  • Loading branch information
shimizukawa committed Oct 16, 2022
2 parents 57b3d4a + 4d96efe commit 3173766
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-examples-proj1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
max-parallel: 5
matrix:
python-version: ['3.10']
django-version: ['2.2', '3.2', '4.0']
django-version: ['3.2', '4.0']
include:
- django-version: 'main'
python-version: '3.10'
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ jobs:
fail-fast: false
max-parallel: 5
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
django-version: ['2.2', '3.2', '4.0']
python-version: ['3.7', '3.8', '3.9', '3.10']
django-version: ['3.2', '4.0']
exclude:
- django-version: '4.0'
python-version: '3.6'
- django-version: '4.0'
python-version: '3.7'
include:
Expand Down
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CHANGES
=======

x.y.z (Unreleased)
4.0.0 (Unreleased)
------------------

General:
Expand All @@ -10,6 +10,9 @@ Incompatible Changes:

Features:

* #83 Drop Python-3.6 support.
* #83 Drop Django-2.2 support.

Bug Fixes:

3.0.0 (2022/02/27)
Expand Down
2 changes: 1 addition & 1 deletion django_redshift_backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
except PackageNotFoundError:
# package is not installed
pass
except ImportError: # py36, py37
except ImportError: # py37
from pkg_resources import get_distribution, DistributionNotFound
try:
__version__ = get_distribution(__name__).version
Expand Down
25 changes: 7 additions & 18 deletions django_redshift_backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ class DatabaseSchemaEditor(BasePGDatabaseSchemaEditor):
sql_create_table = "CREATE TABLE %(table)s (%(definition)s) %(options)s"
sql_delete_fk = "ALTER TABLE %(table)s DROP CONSTRAINT %(name)s"

if django.VERSION < (3,):
# to remove "USING %(column)s::%(type)s"
sql_alter_column_type = "ALTER COLUMN %(column)s TYPE %(type)s"

@property
def multiply_varchar_length(self):
return int(getattr(settings, "REDSHIFT_VARCHAR_LENGTH_MULTIPLIER", 1))
Expand Down Expand Up @@ -741,7 +737,7 @@ def _get_max_length(field):
# 0. Find the unique constraint for this field

unique_constraint = pk_constraint = fk_constraint = None
if old_field.unique and new_field.unique and not(old_field.primary_key or new_field.primary_key):
if old_field.unique and new_field.unique and not (old_field.primary_key or new_field.primary_key):
unique_constraint = self._get_constraint(model, old_field, unique=True, primary_key=False)
elif old_field.primary_key and new_field.primary_key:
pk_constraint = self._get_constraint(model, old_field, primary_key=True)
Expand Down Expand Up @@ -878,7 +874,7 @@ def _create_unique_sql(
self, model, fields, name=None, condition=None, deferrable=None,
include=None, opclasses=None, expressions=None,
):
if django.VERSION >= (4,):
if django.VERSION >= (4,): # dj40 support
return super()._create_unique_sql(
model, fields, name=name, condition=condition, deferrable=deferrable,
include=include, opclasses=opclasses, expressions=expressions
Expand All @@ -892,13 +888,8 @@ def _create_unique_sql(
model, columns, name=name, condition=condition, deferrable=deferrable,
include=include, opclasses=opclasses,
)
else: # dj32, dj22 support
columns = [
field.column if hasattr(field, 'column') else field
for field in fields
]
return super()._create_unique_sql(
model, columns, name=name, condition=condition)
else: # dj22 or earlier are not supported
raise NotImplementedError


redshift_data_types = {
Expand Down Expand Up @@ -947,15 +938,13 @@ def get_table_description(self, cursor, table_name):
# field_map = {line[0]: line[1:] for line in cursor.fetchall()}
field_map = {}
for column_name, is_nullable, column_default in cursor.fetchall():
_field_map = {
field_map[column_name] = {
'null_ok': is_nullable,
'default': column_default,
}
if django.VERSION >= (3, 2):
# Redshift doesn't support user-defined collation
# https://docs.aws.amazon.com/redshift/latest/dg/c_collation_sequences.html
_field_map['collation'] = None
field_map[column_name] = _field_map
'collation': None,
}
cursor.execute(
"SELECT * FROM %s LIMIT 1" % self.connection.ops.quote_name(table_name)
)
Expand Down
4 changes: 2 additions & 2 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ Support versions

This product is tested with:

* Python-3.6, 3.7, 3.8, 3.9, 3.10
* Django-2.2, 3.2, 4.0
* Python-3.7, 3.8, 3.9, 3.10
* Django-3.2, 4.0

License
=======
Expand Down
4 changes: 1 addition & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ classifiers =
License :: OSI Approved :: Apache Software License
Programming Language :: Python
Programming Language :: Python :: 3
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
Framework :: Django
Framework :: Django :: 2.2
Framework :: Django :: 3.2
Framework :: Django :: 4.0
Intended Audience :: Developers
Expand All @@ -33,7 +31,7 @@ project_urls =
Tracker = https://github.com/jazzband/django-redshift-backend/issues

[options]
python_requires = >=3.6, <4
python_requires = >=3.7, <4
packages = find:
include_package_data = false
zip_safe = false
Expand Down
14 changes: 3 additions & 11 deletions tests/test_redshift_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import unittest

import django
from django.db import connections
from django.db.utils import NotSupportedError
from django.core.management.color import no_style
Expand Down Expand Up @@ -158,16 +157,9 @@ def test_create_table_meta_keys(self):
reason='to run, TEST_WITH_POSTGRES=1 tox')
def test_sqlmigrate(self):
from django.db import connection

if django.VERSION < (3, 0): # for dj22
from django.db.migrations.executor import MigrationExecutor
executor = MigrationExecutor(connection)
loader = executor.loader
collect_sql = executor.collect_sql
else:
from django.db.migrations.loader import MigrationLoader
loader = MigrationLoader(connection)
collect_sql = loader.collect_sql
from django.db.migrations.loader import MigrationLoader
loader = MigrationLoader(connection)
collect_sql = loader.collect_sql

app_label, migration_name = 'testapp', '0001'
migration = loader.get_migration_by_prefix(app_label, migration_name)
Expand Down
7 changes: 2 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
[tox]
envlist =
py{36,37}-dj{22,32}
py{38,39,310}-dj{22,32,40,main}
py37-dj32
py{38,39,310}-dj{32,40,main}
flake8
check
skipsdist = True

[gh-actions]
python =
3.6: py36
3.7: py37
3.8: py38
3.9: py39
3.10: py310, flake8, check

[gh-actions:env]
DJANGO =
2.2: dj22
3.2: dj32
4.0: dj40
main: djmain
Expand All @@ -28,7 +26,6 @@ deps =
pytest
pytest-cov
mock>=2.0
dj22: Django>=2.2,<2.3
dj32: Django>=3.2,<3.3
dj40: Django>=4.0,<4.1
djmain: https://github.com/django/django/archive/main.tar.gz
Expand Down

0 comments on commit 3173766

Please sign in to comment.