I have been doing the same thing over the last week. At PyCon Barry Warsaw, Lennart Regebro, and several others held a porting from 2 to 3 clinic where I got some really great tips. They answered all the issues I thought would be hard, and I figured I should do the updates while the fixes were fresh in my mind. So over the last week I have been merging my Python 2 & 3 code, and I finally finished it yesterday. I cleaned up the C/generator code today, and tested it by reading & writing to Riak.
So some notes about my approach:
- I went with single code base as well. When I got to the point of updating the setup to run 2to3 I realized this would be hard (specifically for tests). The 2 & 3 code was already 99% similar, so I figured single source is better.
- We run 2.6 and 3.2 at OpenX, and that is what I developed against. Everything works for 2.6+ and 3.2+.
- The python 2 API might be slightly different now. I still need to do more testing here to make sure everything works as I expect. String fields should only accept unicode (u"") now, and byte fields should only accept bytes/str (b""). Literals ("") are by default str, but if you import unicode_literals, they become unicode. I'm not sure how strictly protobufs enforces these type checks, but python2 code that passed in str objects for string fields might need to be fixed to pass in unicode.
The repo is located here.
Also, for those that want to test this I have some simple build instructions. I don't have much C experience, so I spent a good 20-30 minutes figuring out the build the first time. I had to install gcc-c++, autoconf and automake. Then in the base directory I ran:
./autogen.sh
./configure
make checks (optional)
make install
Thanks,
Charles
On Wednesday, March 20, 2013 7:53:18 AM UTC-7, Malthe Borch wrote:
– in as much as that all tests run without fail on both 2.7 and 3.3. I have used a single-source approach (which is only really feasible starting with those two for syntax compatibility reasons).
Python 2.4, 2.5 and I believe even 2.6 simply aren't going to work. It's too much effort.
\malthe