[Python-porting] Installing different files on Python 2/3

Dirkjan Ochtman dirkjan at ochtman.nl
Thu Jul 17 09:03:39 CEST 2014


After porting CouchDB-Python and trying out an install on a system
that has both, I ran into a minor issue. I searched around a bit, but
didn't find any promising solution.

With CouchDB-Python, I chose a single-source solution, with a util
module that imports a util2 or util3 module based on the Python
version at run time. One of the problems solved in these files is the
exec incompatibility. util2 has this version of the function:

def pyexec(code, gns, lns):
    exec code in gns, lns

Whereas util3 has this version:

pyexec = exec

However, on installation, all modules are byte-compiled, and both of
these cause errors at the syntax level in the version of Python
they're not intended for. I'm using a MANIFEST.in to list out the
SOURCES.txt; is there any nice way of manipulating that data dependent
on the python version?

Cheers,

Dirkjan


More information about the Python-porting mailing list