--- build_exe.py.orig Mon Jan 26 08:59:25 2004 +++ build_exe.py Mon Jan 26 10:24:18 2004 @@ -615,6 +615,9 @@ if src[-3:] == ".py": py_files.append(item) continue + elif src[-4:] in ['.pyc', '.pyo']: + py_files.append(item) + continue for suffix in _c_suffixes: if endswith(src, suffix): extensions.append(item) @@ -1231,6 +1234,18 @@ # class Module() +def pyoCopy(srcfile, cfile, dfile): + in_ = out = None + try: + in_ = open(srcfile, 'rb') + out = open(cfile, 'wb') + b = in_.read(8192) + while b: + out.write(b) + b = in_.read(8192) + finally: + if in_: in_.close() + if out: out.close() def byte_compile(py_files, optimize=0, force=0, target_dir=None, verbose=1, dry_run=0, @@ -1282,7 +1297,15 @@ from distutils.dir_util import mkpath for file in py_files: - if file.__file__[-3:] != ".py": + ext4 = file.__file__[-4:] + if file.__file__[-3:] == ".py": + compile_or_copy = compile + ext4 = __debug__ and '.pyc' or '.pyo' + msg = "byte-compiling %s to %s" + elif ext4 in [".pyc", ".pyo"] : + compile_or_copy = pyoCopy + msg = "copying bytecode %s to %s" + else: raise RuntimeError, "cannot compile '%s'" % file.__file__ # Terminology from the py_compile module: @@ -1291,18 +1314,18 @@ cfile = string.replace(file.__name__, '.', '\\') if file.__path__: - dfile = cfile + '\\__init__.py' + (__debug__ and 'c' or 'o') + dfile = cfile + '\\__init__' + ext4 else: - dfile = cfile + '.py' + (__debug__ and 'c' or 'o') + dfile = cfile + ext4 if target_dir: cfile = os.path.join(target_dir, dfile) if force or newer(file.__file__, cfile): if verbose: - print "byte-compiling %s to %s" % (file.__file__, dfile) + print msg % (file.__file__, dfile) if not dry_run: mkpath(os.path.dirname(cfile)) - compile(file.__file__, cfile, dfile) + compile_or_copy(file.__file__, cfile, dfile) else: if verbose: print "skipping byte-compilation of %s to %s" % \ --- tools\modulefinder.py.orig Mon Jan 26 09:52:53 2004 +++ tools\modulefinder.py Mon Jan 26 09:17:17 2004 @@ -16,6 +16,7 @@ else: # remain compatible with Python < 2.3 READ_MODE = "r" +BINARY_READ_MODE = "rb" LOAD_CONST = dis.opname.index('LOAD_CONST') IMPORT_NAME = dis.opname.index('IMPORT_NAME') @@ -109,8 +110,12 @@ def run_script(self, pathname): self.msg(2, "run_script", pathname) - fp = open(pathname, READ_MODE) - stuff = ("", "r", imp.PY_SOURCE) + if pathname[-4:] in [".pyc", ".pyo"]: + fp = open(pathname, BINARY_READ_MODE) + stuff = ("", "rb", imp.PY_COMPILED) + else: + fp = open(pathname, READ_MODE) + stuff = ("", "r", imp.PY_SOURCE) self.load_module('__main__', fp, pathname, stuff) def load_file(self, pathname):