Merge lp:~james-w/python-oops-amqp/bson-compat into lp:python-oops-amqp

Proposed by James Westby
Status: Merged
Approved by: Ian Booth
Approved revision: 12
Merged at revision: 11
Proposed branch: lp:~james-w/python-oops-amqp/bson-compat
Merge into: lp:python-oops-amqp
Diff against target: 153 lines (+49/-14)
8 files modified
NEWS (+5/-2)
oops_amqp/__init__.py (+1/-1)
oops_amqp/anybson.py (+31/-0)
oops_amqp/publisher.py (+1/-1)
oops_amqp/receiver.py (+1/-2)
oops_amqp/tests/test_publisher.py (+4/-4)
oops_amqp/tests/test_receiver.py (+4/-2)
setup.py (+2/-2)
To merge this branch: bzr merge lp:~james-w/python-oops-amqp/bson-compat
Reviewer Review Type Date Requested Status
Ian Booth (community) code Approve
Review via email: mp+92389@code.launchpad.net

Description of the change

Hi,

The world has two bson libraries with incompatible APIs. This is unfortunate.

However, we can make the world bright again if we support either API. This
is my attempt to do that.

Have a nice day!

James

To post a comment you must log in.
12. By James Westby

Add the missing file.

Revision history for this message
Ian Booth (wallyworld) wrote :

Thanks for this change to improve the robustness of our tools. It looks like a nice solution to a problem not of our making. I wonder, do we have a preferred bson library or can people just install whatever and hence we need this fix to cope with that?

review: Approve (code)
Revision history for this message
James Westby (james-w) wrote :

On Fri, 10 Feb 2012 01:24:17 -0000, Ian Booth <email address hidden> wrote:
> Review: Approve code

Thanks for the review. Would you be able to land the change for me as I
don't have access to do so? A release would be really nice too, but I
can always add the patch to our packaging.

> Thanks for this change to improve the robustness of our tools. It
> looks like a nice solution to a problem not of our making. I wonder,
> do we have a preferred bson library or can people just install
> whatever and hence we need this fix to cope with that?

The pymongo version seems to be winning (is packaged, is much faster, is
usually the one people refer to from what I can see.) That's not the
version that was in use though unfortunately.

People can install whatever, and if you use the python tools it's a bit
of a crapshoot which one you end up with.

The reason we are interested is that we're trying to depend on this
stuff, and we want it packaged up. As I have it now I have packaged the
non-pymongo version, but it conflicts with the pymongo version of the
code, and u1 already use that version. This will allow us to have the
package depend on the pymongo version.

Thanks,

James

Revision history for this message
Ian Booth (wallyworld) wrote :

Hi James,

I'll land and organise a release.

On Fri 10 Feb 2012 14:58:19 EST, James Westby wrote:
> On Fri, 10 Feb 2012 01:24:17 -0000, Ian Booth <email address hidden> wrote:
>> Review: Approve code
>
> Thanks for the review. Would you be able to land the change for me as I
> don't have access to do so? A release would be really nice too, but I
> can always add the patch to our packaging.
>
>> Thanks for this change to improve the robustness of our tools. It
>> looks like a nice solution to a problem not of our making. I wonder,
>> do we have a preferred bson library or can people just install
>> whatever and hence we need this fix to cope with that?
>
> The pymongo version seems to be winning (is packaged, is much faster, is
> usually the one people refer to from what I can see.) That's not the
> version that was in use though unfortunately.
>
> People can install whatever, and if you use the python tools it's a bit
> of a crapshoot which one you end up with.
>
> The reason we are interested is that we're trying to depend on this
> stuff, and we want it packaged up. As I have it now I have packaged the
> non-pymongo version, but it conflicts with the pymongo version of the
> code, and u1 already use that version. This will allow us to have the
> package depend on the pymongo version.
>
> Thanks,
>
> James
>

Revision history for this message
Ian Booth (wallyworld) wrote :

Hi James, I forgot to ask this originally.

Can you please update the NEWS file, adding something like:

<snip>
0.0.6
-----

* Support both pymongo and bson BSON libraries, whichever is installed.
  (James Westby)
<snip>

Also update version="0.0.5" to "0.0.6" in setup.py

Then I can merge in your changes without having to create a branch myself.

Revision history for this message
James Westby (james-w) wrote :

> Hi James, I forgot to ask this originally.
>
> Can you please update the NEWS file, adding something like:
>
> <snip>
> 0.0.6
> -----
>
> * Support both pymongo and bson BSON libraries, whichever is installed.
> (James Westby)
> <snip>
>
> Also update version="0.0.5" to "0.0.6" in setup.py
>
> Then I can merge in your changes without having to create a branch myself.

Done.

Thanks,

James

13. By James Westby

Add a NEWS entry and bump the version. Thanks Ian.

14. By James Westby

Ensure that datetimes returned by bson are timezone-aware.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2011-12-08 18:23:11 +0000
3+++ NEWS 2012-02-10 19:30:24 +0000
4@@ -3,8 +3,11 @@
5
6 Changes and improvements to oops-amqp, grouped by release.
7
8-NEXT
9-----
10+0.0.6
11+-----
12+
13+* Support either http://pypi.python.org/pypi/bson/ or
14+ http://pypi.python.org/pypi/pymongo as the bson library. (James Westby)
15
16 0.0.5
17 -----
18
19=== modified file 'oops_amqp/__init__.py'
20--- oops_amqp/__init__.py 2011-12-08 18:23:11 +0000
21+++ oops_amqp/__init__.py 2012-02-10 19:30:24 +0000
22@@ -97,7 +97,7 @@
23 # established at this point, and setup.py will use a version of next-$(revno).
24 # If the releaselevel is 'final', then the tarball will be major.minor.micro.
25 # Otherwise it is major.minor.micro~$(revno).
26-__version__ = (0, 0, 5, 'beta', 0)
27+__version__ = (0, 0, 6, 'final', 0)
28
29 __all__ = [
30 'Publisher',
31
32=== added file 'oops_amqp/anybson.py'
33--- oops_amqp/anybson.py 1970-01-01 00:00:00 +0000
34+++ oops_amqp/anybson.py 2012-02-10 19:30:24 +0000
35@@ -0,0 +1,31 @@
36+# Copyright (c) 2012, Canonical Ltd
37+#
38+# This program is free software: you can redistribute it and/or modify
39+# it under the terms of the GNU Lesser General Public License as published by
40+# the Free Software Foundation, version 3 only.
41+#
42+# This program is distributed in the hope that it will be useful,
43+# but WITHOUT ANY WARRANTY; without even the implied warranty of
44+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45+# GNU Lesser General Public License for more details.
46+#
47+# You should have received a copy of the GNU Lesser General Public License
48+# along with this program. If not, see <http://www.gnu.org/licenses/>.
49+# GNU Lesser General Public License version 3 (see the file LICENSE).
50+
51+__all__ = [
52+ 'dumps',
53+ 'loads',
54+ ]
55+
56+
57+try:
58+ from bson import dumps, loads
59+except ImportError:
60+ from bson import BSON
61+
62+ def dumps(obj):
63+ return BSON.encode(obj)
64+
65+ def loads(data):
66+ return BSON(data).decode(tz_aware=True)
67
68=== modified file 'oops_amqp/publisher.py'
69--- oops_amqp/publisher.py 2011-12-08 09:29:35 +0000
70+++ oops_amqp/publisher.py 2012-02-10 19:30:24 +0000
71@@ -21,7 +21,7 @@
72 from threading import local
73
74 from amqplib import client_0_8 as amqp
75-from bson import dumps
76+from anybson import dumps
77
78 from utils import (
79 amqplib_error_types,
80
81=== modified file 'oops_amqp/receiver.py'
82--- oops_amqp/receiver.py 2011-12-08 10:15:23 +0000
83+++ oops_amqp/receiver.py 2012-02-10 19:30:24 +0000
84@@ -19,8 +19,7 @@
85
86 import time
87
88-import bson
89-
90+import anybson as bson
91 from utils import (
92 amqplib_error_types,
93 close_ignoring_connection_errors,
94
95=== modified file 'oops_amqp/tests/test_publisher.py'
96--- oops_amqp/tests/test_publisher.py 2011-12-08 10:15:23 +0000
97+++ oops_amqp/tests/test_publisher.py 2012-02-10 19:30:24 +0000
98@@ -17,10 +17,10 @@
99
100 from hashlib import md5
101
102-import bson
103-
104-from oops_amqp import Publisher
105-from oops_amqp.utils import close_ignoring_connection_errors
106+from oops_amqp import (
107+ anybson as bson,
108+ Publisher,
109+ )
110 from oops_amqp.tests import (
111 ChannelFixture,
112 QueueFixture,
113
114=== modified file 'oops_amqp/tests/test_receiver.py'
115--- oops_amqp/tests/test_receiver.py 2011-12-08 09:29:35 +0000
116+++ oops_amqp/tests/test_receiver.py 2012-02-10 19:30:24 +0000
117@@ -19,10 +19,12 @@
118 import socket
119
120 from amqplib import client_0_8 as amqp
121-import bson
122 from oops import Config
123
124-from oops_amqp import Receiver
125+from oops_amqp import (
126+ anybson as bson,
127+ Receiver,
128+ )
129 from oops_amqp.tests import (
130 ChannelFixture,
131 QueueFixture,
132
133=== modified file 'setup.py'
134--- setup.py 2011-12-08 18:23:11 +0000
135+++ setup.py 2012-02-10 19:30:24 +0000
136@@ -23,7 +23,7 @@
137 os.path.join(os.path.dirname(__file__), 'README'), 'rb').read()
138
139 setup(name="oops_amqp",
140- version="0.0.5",
141+ version="0.0.6",
142 description=\
143 "OOPS AMQP transport.",
144 long_description=description,
145@@ -40,7 +40,7 @@
146 'Programming Language :: Python',
147 ],
148 install_requires = [
149- 'bson',
150+ 'pymongo',
151 'oops',
152 'amqplib',
153 ],

Subscribers

People subscribed via source and target branches

to all changes: