Greg Ward wrote:
Hi all --
based on and inspired by recent patches from Marc-Andre Lemburg and Rene Liebscher, I've finally started tackling the byte-compilation problem in earnest. Here's the approach I'm taking: * new function 'byte_compile()' in distutils.util: this is the all- singing, all-dancing wrapper around py_compile that will do all the real work * reduce the 'bytecompile()' method in the install_lib command to a simple wrapper around 'util.byte_compile()', that does the Right Thing with respect to optimization and claimed source filename written to the .py{c,o} file * add similar functionality to the build_py command, so that you may optionally do byte-compilation at build time rather than install time.
The first two steps are done and checked in, except that install_lib's 'bytecompile()' method doesn't yet take advantage of the fancy features in the new 'byte_compile()' -- it doesn't rewrite filenames or do optimization.
The default will continue to be doing compilation at install time rather than build time. I'm still leaning towards build-time compilation, but it's too late in the Distutils 1.0 release cycle to change things like this. However, I want to have the *option* to do compilation at build time, so people can experiment with it, see if it works, figure out what other features are needed so it really works, etc. The idea is that developers could put settings in their setup.cfg that control when to do byte-compilation; I suspect developers who want to distribute closed-source modules will have to do build-time compilation. Probably the "install" command will need some sort of "don't install source" option, or maybe the build command should have a "blow away source after compiling it" option.
The latter is not very useful, IMHO. I will definitely need the "compile at build time and don't argue about not finding the sources at install time" option ;-)
Here's my 'byte_compile()' function: as usual, it works for me. Please review it, and if you're following CVS, try it out. (Should be enough to install any module distribution containing pure Python modules.)
Looks ok , except that I would pass the Python filenames through os.path.abspath() before writing any externally run scripts... both to work around possible security problems and to make sure the shell finds the right files.
------------------------------------------------------------------------ def byte_compile (py_files, optimize=0, force=0, prefix=None, base_dir=None, verbose=1, dry_run=0, direct=None): ...
-- Marc-Andre Lemburg ______________________________________________________________________ Business: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/