[Distutils] generating pyc and pyo files

Fred L. Drake Fred L. Drake, Jr." <fdrake@acm.org
Mon, 29 Mar 1999 13:19:20 -0500 (EST)

Andrew Dalke writes:
 > When should the .pyc and .pyo files be generated during the
 > install process, in the "build" directory or the "install" one?
 > OTOH, I know the normal Python install does a compileall after
 > the .py files have been transfered to the install directory. 

  I think the structure of the Python build process may be due to an
older behavior in Python which I think has been fixed.  Originally,
the __file__ name in a module was initialized at compile time, not at
import time.  I think it is now set in the .pyc/.pyo at compile time
and re-set in the module at import time.  If you load the .pyc/.pyo
without going through the import machinery you should see the name of
the file as it was accessed at compile time (which might be
relative).  In general, the compile-time __file__ value may be invalid 
in the importing process.
  I think the .pyc/.pyo files can be built in the work area and then
installed using the normal file installation mechanisms.  This
provides a little more flexibility in the installation machinery as

 > Also, looking at buildall, it doesn't give any sort of error
 > status on exit if a file could not be compiled.  I would prefer
 > the make process stop if that occurs, so compileall needs to exit
 > with a non-zero value.   Attached is a context diff patch to
 > "compileall" from 1.5.1 which supports this ability.  I can send

  I will integrate this patch; thanks!


Fred L. Drake, Jr.	     <fdrake@acm.org>
Corporation for National Research Initiatives