[Python-checkins] CVS: distutils/distutils/command build_py.py,1.32,1.33
Greg Ward
python-dev@python.org
Sun, 1 Oct 2000 19:19:07 -0700
Update of /cvsroot/python/distutils/distutils/command
In directory slayer.i.sourceforge.net:/tmp/cvs-serv5068
Modified Files:
build_py.py
Log Message:
Added the ability to do byte-compilation at build time, currently off
by default (since compiling at install time works just fine). Details:
- added 'compile' and 'optimize' options
- added 'byte_compile()' method
- changed 'get_outputs()' so it includes bytecode files
A lot of the code added is very similar to code in install_lib.py;
would be nice to factor it out further.
Index: build_py.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/command/build_py.py,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -r1.32 -r1.33
*** build_py.py 2000/09/30 18:27:54 1.32
--- build_py.py 2000/10/02 02:19:04 1.33
***************
*** 21,28 ****
user_options = [
('build-lib=', 'd', "directory to \"build\" (copy) to"),
('force', 'f', "forcibly build everything (ignore file timestamps)"),
]
! boolean_options = ['force']
--- 21,34 ----
user_options = [
('build-lib=', 'd', "directory to \"build\" (copy) to"),
+ ('compile', 'c', "compile .py to .pyc"),
+ ('no-compile', None, "don't compile .py files [default]"),
+ ('optimize=', 'O',
+ "also compile with optimization: -O1 for \"python -O\", "
+ "-O2 for \"python -OO\", and -O0 to disable [default: -O0]"),
('force', 'f', "forcibly build everything (ignore file timestamps)"),
]
! boolean_options = ['compile', 'force']
! negative_opt = {'no-compile' : 'compile'}
***************
*** 32,35 ****
--- 38,43 ----
self.package = None
self.package_dir = None
+ self.compile = 0
+ self.optimize = 0
self.force = None
***************
*** 45,48 ****
--- 53,64 ----
self.package_dir = self.distribution.package_dir
+ # Ick, copied straight from install_lib.py (fancy_getopt needs a
+ # type system! Hell, *everything* needs a type system!!!)
+ if type(self.optimize) is not IntType:
+ try:
+ self.optimize = int(self.optimize)
+ assert 0 <= self.optimize <= 2
+ except (ValueError, AssertionError):
+ raise DistutilsOptionError, "optimize must be 0, 1, or 2"
def run (self):
***************
*** 88,91 ****
--- 104,109 ----
self.build_packages()
+ self.byte_compile(self.get_outputs(include_bytecode=0))
+
# run ()
***************
*** 285,295 ****
! def get_outputs (self):
modules = self.find_all_modules()
outputs = []
for (package, module, module_file) in modules:
package = string.split(package, '.')
! outputs.append(self.get_module_outfile(self.build_lib,
! package, module))
return outputs
--- 303,319 ----
! def get_outputs (self, include_bytecode=1):
modules = self.find_all_modules()
outputs = []
for (package, module, module_file) in modules:
package = string.split(package, '.')
! filename = self.get_module_outfile(self.build_lib, package, module)
! outputs.append(filename)
! if include_bytecode:
! if self.compile:
! outputs.append(filename + "c")
! if self.optimize > 0:
! outputs.append(filename + "o")
!
return outputs
***************
*** 348,351 ****
# build_packages ()
!
# class build_py
--- 372,397 ----
# build_packages ()
!
!
! def byte_compile (self, files):
! from distutils.util import byte_compile
! prefix = self.build_lib
! if prefix[-1] != os.sep:
! prefix = prefix + os.sep
!
! # XXX this code is essentially the same as the 'byte_compile()
! # method of the "install_lib" command, except for the determination
! # of the 'prefix' string. Hmmm.
!
! if self.compile:
! byte_compile(files, optimize=0,
! force=self.force,
! prefix=prefix,
! verbose=self.verbose, dry_run=self.dry_run)
! if self.optimize > 0:
! byte_compile(files, optimize=self.optimize,
! force=self.force,
! prefix=prefix,
! verbose=self.verbose, dry_run=self.dry_run)
!
# class build_py