diff -ur -x '*.pyc' -x '*.pyo' -x '.*.swp' /c/temp/distutils/command/bdist_wininst.py /c/DevTools/Python22/Lib/distutils/command/bdist_wininst.py --- /c/temp/distutils/command/bdist_wininst.py Wed Oct 30 00:00:34 2002 +++ /c/DevTools/Python22/Lib/distutils/command/bdist_wininst.py Thu Jun 19 13:19:20 2003 @@ -30,6 +30,9 @@ ('no-target-optimize', 'o', "do not compile .py to .pyo (optimized)" "on the target system"), + ('remove-source', None, + "don't include original .py source files" + "(remove from distribution)"), ('dist-dir=', 'd', "directory to put final built distributions in"), ('bitmap=', 'b', @@ -46,6 +49,7 @@ self.keep_temp = 0 self.no_target_compile = 0 self.no_target_optimize = 0 + self.remove_source = 0 self.target_version = None self.dist_dir = None self.bitmap = None @@ -87,9 +91,10 @@ install.warn_dir = 0 install_lib = self.reinitialize_command('install_lib') - # we do not want to include pyc or pyo files - install_lib.compile = 0 + # we DO want to include .pyc files, not .pyo files, not .py files + install_lib.compile = 1 install_lib.optimize = 0 + install_lib.remove_source = 1 # Use a custom scheme for the zip-file, because we have to decide # at installation time which scheme to use. @@ -159,6 +164,7 @@ lines.append("info=%s" % repr(info)[1:-1]) lines.append("target_compile=%d" % (not self.no_target_compile)) lines.append("target_optimize=%d" % (not self.no_target_optimize)) + lines.append("remove_source=%d" % (self.remove_source)) if self.target_version: lines.append("target_version=%s" % self.target_version) diff -ur -x '*.pyc' -x '*.pyo' -x '.*.swp' /c/temp/distutils/command/install_lib.py /c/DevTools/Python22/Lib/distutils/command/install_lib.py --- /c/temp/distutils/command/install_lib.py Wed Oct 30 00:00:34 2002 +++ /c/DevTools/Python22/Lib/distutils/command/install_lib.py Thu Jun 19 13:19:20 2003 @@ -36,6 +36,8 @@ ('optimize=', 'O', "also compile with optimization: -O1 for \"python -O\", " "-O2 for \"python -OO\", and -O0 to disable [default: -O0]"), + ('remove-source', None, "don't include original .py source files " + "(remove from distributions)"), ('skip-build', None, "skip the build steps"), ] @@ -50,6 +52,7 @@ self.force = 0 self.compile = None self.optimize = None + self.remove_source = 0 self.skip_build = None def finalize_options (self): @@ -92,6 +95,10 @@ if outfiles is not None and self.distribution.has_pure_modules(): self.byte_compile(outfiles) + # (Optionally) remove original .py files... + if outfiles is not None and self.distribution.has_pure_modules: + self.do_remove_source(outfiles) + # run () @@ -134,6 +141,18 @@ prefix=install_root, verbose=self.verbose, dry_run=self.dry_run) + def do_remove_source (self, files): + from distutils.util import remove_source + + # 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.remove_source: + remove_source(files, verbose=self.verbose, dry_run=self.dry_run) + # -- Utility methods ----------------------------------------------- diff -ur -x '*.pyc' -x '*.pyo' -x '.*.swp' /c/temp/distutils/util.py /c/DevTools/Python22/Lib/distutils/util.py --- /c/temp/distutils/util.py Fri Mar 21 19:48:48 2003 +++ /c/DevTools/Python22/Lib/distutils/util.py Thu Jun 19 13:19:20 2003 @@ -312,6 +312,31 @@ raise ValueError, "invalid truth value %s" % `val` +def remove_source (py_files, verbose=1, dry_run=0): + """Remove the original source for a collection of Python source files + (assuming they have been compiled to either .pyc or .pyo form). + 'py_files' is a list of files to remove; any files that don't end in + ".py" are silently skipped. + + If 'verbose' is true, prints out a report of each file. If 'dry_run' + is true, doesn't actually do anything that would affect the filesystem. + + """ + from os import remove + + for file in py_files: + if file[-3:] != ".py": + # This lets us be lazy and not filter filenames in + # the "install_lib" command. + continue + + if verbose: + print "removing source file %s" % (file) + if not dry_run: + remove(file) + +# remove_source () + def byte_compile (py_files, optimize=0, force=0, prefix=None, base_dir=None, Only in /c/DevTools/Python22/Lib/distutils/: util.py.orig