[Distutils] generating pyc and pyo files

Andrew Dalke dalke@bioreason.com
Sun, 28 Mar 1999 17:57:26 -0800


This is a multi-part message in MIME format.
--------------E888D53BE2DBB90B8E16359A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

When should the .pyc and .pyo files be generated during the
install process, in the "build" directory or the "install" one?

I ask because I've been looking into GNU autoconf and automake.
They compile emacs lisp code (.el->.elc) in the build dir before
the actual installation, and it might be nice to follow their
lead on that, and it would ensure that the downloaded python files
are compileable before they are installed.

OTOH, I know the normal Python install does a compileall after
the .py files have been transfered to the install directory. 

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
the full file as well if someone wants it.

						Andrew
						dalke@bioreason.com
--------------E888D53BE2DBB90B8E16359A
Content-Type: text/plain; charset=us-ascii; name="diff-compileall.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="diff-compileall.py"

*** /usr/local/lib/python1.5/compileall.py	Mon Jul 20 12:33:01 1998
--- compileall.py	Sun Mar 28 17:50:51 1999
***************
*** 34,39 ****
--- 34,40 ----
          print "Can't list", dir
          names = []
      names.sort()
+     success = 1
      for name in names:
          fullname = os.path.join(dir, name)
          if ddir:
***************
*** 54,64 ****
--- 55,67 ----
                      else: exc_type_name = sys.exc_type.__name__
                      print 'Sorry:', exc_type_name + ':',
                      print sys.exc_value
+ 		    success = 0
          elif maxlevels > 0 and \
               name != os.curdir and name != os.pardir and \
               os.path.isdir(fullname) and \
               not os.path.islink(fullname):
              compile_dir(fullname, maxlevels - 1, dfile)
+     return success
  
  def compile_path(skip_curdir=1, maxlevels=0):
      """Byte-compile all module on sys.path.
***************
*** 69,79 ****
      maxlevels:   max recursion level (default 0)
  
      """
      for dir in sys.path:
          if (not dir or dir == os.curdir) and skip_curdir:
              print 'Skipping current directory'
          else:
!             compile_dir(dir, maxlevels)
  
  def main():
      """Script main program."""
--- 72,84 ----
      maxlevels:   max recursion level (default 0)
  
      """
+     success = 1
      for dir in sys.path:
          if (not dir or dir == os.curdir) and skip_curdir:
              print 'Skipping current directory'
          else:
!             success = success and compile_dir(dir, maxlevels)
!     return success
  
  def main():
      """Script main program."""
***************
*** 98,109 ****
              sys.exit(2)
      try:
          if args:
              for dir in args:
!                 compile_dir(dir, maxlevels, ddir)
          else:
!             compile_path()
      except KeyboardInterrupt:
          print "\n[interrupt]"
  
  if __name__ == '__main__':
!     main()
--- 103,118 ----
              sys.exit(2)
      try:
          if args:
+ 	    success = 1
              for dir in args:
!                 success = success and compile_dir(dir, maxlevels, ddir)
          else:
!             success = compile_path()
      except KeyboardInterrupt:
          print "\n[interrupt]"
  
+     return success
+ 
  if __name__ == '__main__':
!     if not main():
! 	sys.exit(1)

--------------E888D53BE2DBB90B8E16359A--