From 9e9959b39c0d016bd120c17bc5acb9661e25638e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Fri, 23 Dec 2016 20:54:35 +0100 Subject: [PATCH] python 3 --- .gitignore | 1 + .travis.yml | 4 ++++ README.md | 2 -- Vagrantfile | 7 ++++++- coolamqp/backends/base.py | 1 + coolamqp/backends/pyamqp.py | 4 +++- setup.py | 22 +++++++++++++--------- tests/test_basics.py | 5 ++--- 8 files changed, 30 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index f42c2b3..5c528f9 100644 --- a/.gitignore +++ b/.gitignore @@ -91,3 +91,4 @@ ENV/ .vagrant/ .idea/ +MANIFEST diff --git a/.travis.yml b/.travis.yml index 8c29529..4a4d901 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,10 @@ language: python python: - "2.7" + - "3.2" + - "3.3" + - "3.4" + - "3.5 - "pypy" cache: pip sudo: required diff --git a/README.md b/README.md index b874c49..714c1c3 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,6 @@ CoolAMQP []() []() -**Support for Python 3 is suspended until I fix pending issues** - When you're tired of fucking with AMQP reconnects. When a connection made by CoolAMQP to your broker fails, it will pick another diff --git a/Vagrantfile b/Vagrantfile index 25d3c70..d395929 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -13,8 +13,11 @@ Vagrant.configure("2") do |config| config.vm.provision "shell", inline: <<-SHELL apt-get update - apt-get install -y htop curl python python-setuptools python-pip python-dev build-essential rabbitmq-server + + # Python + apt-get install -y htop curl python python-setuptools python-pip python-dev build-essential rabbitmq-server python3 python3-pip python3-setuptools pip install --upgrade pip setuptools + pip3 install --upgrade pip setuptools /usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management sudo service rabbitmq-server restart @@ -25,6 +28,8 @@ Vagrant.configure("2") do |config| # Install deps pip install -r /vagrant/requirements.txt pip install nose coverage + pip3 install -r /vagrant/requirements.txt + pip3 install nose coverage # HTTP server for viewing coverage reports apt-get -y install nginx diff --git a/coolamqp/backends/base.py b/coolamqp/backends/base.py index 401b897..4959e36 100644 --- a/coolamqp/backends/base.py +++ b/coolamqp/backends/base.py @@ -9,6 +9,7 @@ class ConnectionFailedError(AMQPError): class Cancelled(Exception): """Cancel ordered by user""" + class RemoteAMQPError(AMQPError): """ Remote AMQP broker responded with an error code diff --git a/coolamqp/backends/pyamqp.py b/coolamqp/backends/pyamqp.py index 90bbbe3..12ae1a0 100644 --- a/coolamqp/backends/pyamqp.py +++ b/coolamqp/backends/pyamqp.py @@ -3,6 +3,7 @@ from __future__ import division import amqp import socket +import six import functools import logging from .base import AMQPBackend, RemoteAMQPError, ConnectionFailedError @@ -21,7 +22,8 @@ def translate_exceptions(fun): except amqp.RecoverableChannelError as e: raise RemoteAMQPError(e.reply_code, e.reply_text) except (IOError, amqp.ConnectionForced, amqp.IrrecoverableChannelError) as e: - raise ConnectionFailedError(e.message) + msg = e.message if six.PY2 else e.args[0] + raise ConnectionFailedError(msg) return q diff --git a/setup.py b/setup.py index 554ba11..b3f06c7 100644 --- a/setup.py +++ b/setup.py @@ -2,10 +2,16 @@ # coding=UTF-8 from setuptools import setup + +def reqs(): + with open('requirements.txt', 'r') as fin: + return [q.strip() for q in fin.readlines() if len(q.strip()) > 0] + + setup(name='CoolAMQP', version='0.7', - description=u'AMQP client with sane reconnects', - author=u'DMS Serwis s.c.', + description='AMQP client with sane reconnects', + author='DMS Serwis s.c.', author_email='piotrm@smok.co', url='https://github.com/smok-serwis/coolamqp', download_url='https://github.com/smok-serwis/coolamqp/archive/v0.7.zip', @@ -13,18 +19,16 @@ setup(name='CoolAMQP', packages=['coolamqp', 'coolamqp.backends'], license='MIT License', long_description=u'The AMQP client that handles reconnection madness for you', - requires=[ - "amqp", - "six", - "monotonic" - ], + requires=reqs(), tests_require=["nose"], test_suite='nose.collector', classifiers=[ 'Programming Language :: Python', 'Programming Language :: Python :: 2.7', -# 'Programming Language :: Python :: 3.4', -# 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.2', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Operating System :: OS Independent' diff --git a/tests/test_basics.py b/tests/test_basics.py index ed1e4e2..e633f6c 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -3,8 +3,7 @@ from __future__ import absolute_import, division, print_function import unittest import six -from coolamqp import Cluster, ClusterNode, Queue, MessageReceived, ConnectionUp, \ - ConnectionDown, ConsumerCancelled, Message, Exchange +from coolamqp import Cluster, ClusterNode, Queue, MessageReceived, ConnectionUp, ConsumerCancelled, Message, Exchange def getamqp(): @@ -55,7 +54,7 @@ class TestBasics(unittest.TestCase): p = self.amqp.drain(wait=4) self.assertIsInstance(p, MessageReceived) - self.assertEquals(six.binary_type(p.message.body), 'what the fuck') + self.assertEquals(six.text_type(p.message.body), 'what the fuck') def test_bug_hangs(self): p = Queue('lol', exclusive=True) -- GitLab