diff options
author | Ask Solem <ask@celeryproject.org> | 2014-06-02 17:17:20 +0100 |
---|---|---|
committer | Ask Solem <ask@celeryproject.org> | 2014-06-02 17:17:20 +0100 |
commit | 241c4c0c0d8845f83356d7aa4caf40952faf4ea2 (patch) | |
tree | 75bfc51cc208853174c9a06e91c911825201bfee | |
parent | 96ed178cda629217a8ae81703d1866676f8cc916 (diff) | |
download | kombu-241c4c0c0d8845f83356d7aa4caf40952faf4ea2.tar.gz |
amqplib can now be imported without amqplib dependency. Closes #316
-rw-r--r-- | kombu/transport/amqplib.py | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/kombu/transport/amqplib.py b/kombu/transport/amqplib.py index fff82a1f..2a8e103a 100644 --- a/kombu/transport/amqplib.py +++ b/kombu/transport/amqplib.py @@ -17,11 +17,26 @@ except ImportError: pass from struct import unpack -from amqplib import client_0_8 as amqp -from amqplib.client_0_8 import transport -from amqplib.client_0_8.channel import Channel as _Channel -from amqplib.client_0_8.exceptions import AMQPConnectionException -from amqplib.client_0_8.exceptions import AMQPChannelException +try: + from amqplib import client_0_8 as amqp + from amqplib.client_0_8 import transport + from amqplib.client_0_8.channel import Channel as _Channel + from amqplib.client_0_8.exceptions import AMQPConnectionException + from amqplib.client_0_8.exceptions import AMQPChannelException +except ImportError: # pragma: no cover + + class NA(object): + pass + + class NAx(object): + pass + amqp = NA + amqp.Connection = NA + transport = _Channel = NA # noqa + # Sphinx crashes if this is NA, must be different class + transport.TCPTransport = transport.SSLTransport = NAx + AMQPConnectionException = AMQPChannelException = NA # noqa + from kombu.five import items from kombu.utils.encoding import str_to_bytes @@ -321,6 +336,9 @@ class Transport(base.Transport): self.client = client self.default_port = kwargs.get('default_port') or self.default_port + if amqp is NA: + raise ImportError('Missing amqplib library (pip install amqplib)') + def create_channel(self, connection): return connection.channel() |