[Distutils] Skipping compilation of some .py files on "install"?
Barry A. Warsaw
barry@zope.com
Fri May 31 23:35:01 2002
>>>>> "MAL" == M <mal@lemburg.com> writes:
>> The email package has two files to help it maintain
>> compatibility with Python 2.1 and Python 2.2+. There's a
>> _compat21.py and a _compat22.py that contains tricky bits that
>> are different between the two Python versions.
>> [...]
>> Naturally Python 2.1 won't be able to compile _compat22.py and
>> indeed you get a SyntaxError. Is there a way
>> -- in my setup.py -- that I can [...] skip byte
>> compilation of _compat22.py when I find I'm using Python 2.1?
MAL> Not builtin, but it should be easy to write your own subclass
MAL> which implements this.
And indeed it was! Thanks for the hint MAL. Below is what I came up
with.
-Barry
-------------------- snip snip --------------------setup.py
import sys
from os.path import basename
from distutils.core import setup
from distutils.command.install_lib import install_lib
class EmailInstall(install_lib):
def byte_compile(self, files):
# For Python 2.1.x do not byte compile the _compat22.py file since
# that will most definitely fail. Any newer Python can compile
# everything.
major, minor = sys.version_info[0:2]
if major == 2 and minor == 1:
files = [f for f in files if basename(f) <> '_compat22.py']
return install_lib.byte_compile(self, files)
setup(name='email',
version='2.0.5',
description='Next generation MIME library',
author='Barry Warsaw',
author_email='barry@zope.com',
url='http://sf.net/projects/mimelib',
packages=['email'],
# Because we need to selectively byte-compile
cmdclass={'install_lib': EmailInstall},
)