16 May 2012 20:57
Python 2/3 compatible distutils installation?
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(Continue reading)
RSS Feed