diff --git a/CHANGES.rst b/CHANGES.rst index a50d32e..3f853af 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,13 @@ CHANGES 4.2.0 (Unreleased) ------------------ +General: + +* #149 django-redshift-backend depends directly on psycopg2. + If you want to use psycopg2 pre-built packages, please refer to + the following site for more information: + https://www.psycopg.org/docs/install.html + Features: * #143 Add Django-5.0 support. diff --git a/django_redshift_backend/base.py b/django_redshift_backend/base.py index ab158a0..b5e68dc 100644 --- a/django_redshift_backend/base.py +++ b/django_redshift_backend/base.py @@ -15,7 +15,7 @@ import django from django.utils import timezone from django.conf import settings -from django.core.exceptions import FieldDoesNotExist +from django.core.exceptions import FieldDoesNotExist, ImproperlyConfigured from django.db.models import Index from django.db.models.expressions import Col from django.db.utils import NotSupportedError, ProgrammingError @@ -37,9 +37,13 @@ DatabaseIntrospection as BasePGDatabaseIntrospection, ) from .meta import DistKey, SortKey -from psycopg2.extensions import Binary -from .psycopg2adapter import RedshiftBinary +try: + from psycopg2.extensions import Binary + from .psycopg2adapter import RedshiftBinary +except ImportError as e: + raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e) + logger = logging.getLogger("django.db.backends") diff --git a/pyproject.toml b/pyproject.toml index 191b0f2..6052e17 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,13 +38,11 @@ classifiers = [ ] dependencies = [ "django<5.2", + "psycopg2", "backports.zoneinfo;python_version<'3.9'", ] [project.optional-dependencies] -psycopg2 = [ - "psycopg2", -] psycopg2-binary = [ "psycopg2-binary", ] diff --git a/tox.ini b/tox.ini index 338e3db..e5f9267 100644 --- a/tox.ini +++ b/tox.ini @@ -29,7 +29,6 @@ DJANGO = [testenv] deps = coverage - psycopg2-binary>=2.7 pytest pytest-cov mock>=2.0 @@ -41,6 +40,7 @@ deps = dj50: Django>=5.0,<5.1 dj51: Django>=5.1,<5.2 djmain: https://github.com/django/django/archive/main.tar.gz + .[psycopg2-binary] setenv = DJANGO_SETTINGS_MODULE = settings PYTHONPATH = {toxinidir}