[Python-porting] Python 2/3 compatible distutils installation?
Barry Warsaw
barry at python.org
Wed May 16 20:57:02 CEST 2012
Here's an interesting porting issue that came up today. I'm not crossposting
this to distutils-sig, but I will if no one here has come up with a solution.
I'm looking at testtools[1], which Jerry Seutter has done a good, initial port
of to Python 3. His merge proposal, along with the diff is here[2]. My
branch which fixes a few of Robert Collins' comments is here[3].
One of the tricky problems is with re-raise syntax, which can't be
compatibly represented syntactically across Python 2 and 3. The six module
has a hack for this, but testtools uses its own trick, which is to provide a
_compat2x.py and a _compat3x.py file containing the proper syntax.
This works well at execution time, because a simple sys.version_info check can
be used to decide which module gets imported; the other is for all intents and
purposes, ignored.
The problem comes when installing the package with distutils. The
byte-compilation of _compat2x.py throws a SyntaxError, of course rightly so.
The question I have is how can we avoid trying to byte compile _compat2x.py
when the package is installed via Python 3? I've tried various distutils
command overrides and hacks (including trying to load a MANIFEST3.in which
exclusions that file), but haven't hit upon the right magic to make it work in
all cases.
Has anybody encountered a similar situation, and if so, how have you worked
around this? Disgusting kludges welcome. :)
Cheers,
-Barry
[1] http://launchpad.net/testtools
[2] https://code.launchpad.net/~jseutter/testtools/py3_again/+merge/105569
[3] https://code.launchpad.net/~barry/testtools/py3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-porting/attachments/20120516/47f5ca20/attachment.pgp>
More information about the Python-porting
mailing list