Skip to content

Commit

Permalink
Drop hard dependency on psycopg2 - require it anyway - closes sqlalch…
Browse files Browse the repository at this point in the history
…emy-redshift#165 (sqlalchemy-redshift#172)

* Drop hard dependency on psycopg2 - require it anyway - closes sqlalchemy-redshift#165

    * Try to import psycopg2 raising ImportError with more descriptive message
    * add documentation warning about psycopg2
  • Loading branch information
fizyk authored and jklukas committed Jul 18, 2019
1 parent fd36098 commit 8e0c485
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ docs/_build/

# PyBuilder
target/

# IDE
.idea/
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
0.7.4 (unreleased)
------------------

- Drop hard dependency on psycopg2 but require package to be present on runtime
(`Issue #165 <https://github.com/sqlalchemy-redshift/sqlalchemy-redshift/pull/165>`_)
- Switch from info to keyword arguments on columns for ``SQLAlchemy >= 1.3.0``
(`Issue #161 <https://github.com/sqlalchemy-redshift/sqlalchemy-redshift/pull/161>`_)
- Add support for column info on redshift late binding views
Expand Down
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ The package is available on PyPI::

pip install sqlalchemy-redshift

.. warning::

This dialect requires psycopg2 library to work properly. It does not provide
it as required, but relies on you to select the psycopg2 distribution you need:

* psycopg2 - standard distribution of psycopg2, requires compilation so few system dependencies are required for it
* psycopg2-binary - already compiled distribution (no system dependencies are required)
* psycopg2cffi - pypy compatible version

See `Psycopg2's binary install docs <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>`_
for more context on choosing a distribution.
Usage
-----
The DSN format is similar to that of regular Postgres::
Expand Down
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
package_data={'sqlalchemy_redshift': ['redshift-ca-bundle.crt']},
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
install_requires=[
'psycopg2>=2.5',
# requires sqlalchemy.sql.base.DialectKWArgs.dialect_options, new in
# version 0.9.2
'SQLAlchemy>=0.9.2,<2.0.0',
],
extras_require={
Expand Down
15 changes: 14 additions & 1 deletion sqlalchemy_redshift/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
from pkg_resources import get_distribution
from pkg_resources import get_distribution, parse_version

try:
import psycopg2 # noqa: F401
if get_distribution('psycopg2').parsed_version < parse_version('2.5'):
raise ImportError('Minimum required version for psycopg2 is 2.5')
# requires sqlalchemy.sql.base.DialectKWArgs.dialect_options, new in
# version 0.9.2
except ImportError:
raise ImportError(
'No module named psycopg2. Please install either '
'psycopg2 or psycopg2-binary package for CPython '
'or psycopg2cffi for Pypy.'
)

__version__ = get_distribution('sqlalchemy-redshift').version

Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ deps =
[testenv:lint]
deps =
flake8==2.4.0
psycopg2
commands=flake8 sqlalchemy_redshift tests

[testenv:docs]
Expand Down

0 comments on commit 8e0c485

Please sign in to comment.