def byte_compile(self, files, prefix=None): """Byte-compile files to pyc and/or pyo files. This method requires that the calling class define compile and optimize options, like build_py and install_lib. It also automatically respects the force and dry-run options. prefix, if given, is a string that will be stripped off the filenames encoded in bytecode files. """ if self.compile: util.byte_compile(files, optimize=False, prefix=prefix, force=self.force, dry_run=self.dry_run) if self.optimize: util.byte_compile(files, optimize=self.optimize, prefix=prefix, force=self.force, dry_run=self.dry_run)
def byte_compile(self, files): if hasattr(sys, 'dont_write_bytecode') and sys.dont_write_bytecode: self.warn('byte-compiling is disabled, skipping.') return from distutils2.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, dry_run=self.dry_run) if self.optimize > 0: byte_compile(files, optimize=self.optimize, force=self.force, prefix=prefix, dry_run=self.dry_run)
def byte_compile(self, files): if hasattr(sys, 'dont_write_bytecode') and sys.dont_write_bytecode: self.warn('byte-compiling is disabled, skipping.') return from distutils2.util import byte_compile # Get the "--root" directory supplied to the "install" command, # and use it as a prefix to strip off the purported filename # encoded in bytecode files. This is far from complete, but it # should at least generate usable bytecode in RPM distributions. install_root = self.get_finalized_command('install').root if self.compile: byte_compile(files, optimize=0, force=self.force, prefix=install_root, dry_run=self.dry_run) if self.optimize > 0: byte_compile(files, optimize=self.optimize, force=self.force, prefix=install_root, verbose=self.verbose, dry_run=self.dry_run)
def test_byte_compile_under_B(self): # make sure byte compilation works under -B (dont_write_bytecode) self.addCleanup(setattr, sys, 'dont_write_bytecode', sys.dont_write_bytecode) sys.dont_write_bytecode = True byte_compile([])