3 # py-compile - Compile a Python program
4 # Copyright 2000, 2001 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 # As a special exception to the GNU General Public License, if you
22 # distribute this file as part of a program that contains a
23 # configuration script generated by Autoconf, you may include it under
24 # the same distribution terms that you use for the rest of that program.
26 # called as "py-compile [--basedir DIR] PY_FILES ...
28 if [ -z "$PYTHON" ]; then
40 echo "Usage: py-compile [--basedir DIR] PY_FILES ..."
41 echo "Byte compile some python scripts. This should be performed"
42 echo "after they have been moved to the final installation location"
46 echo "py-compile version 0.0"
52 echo "No files given to $0" 1>&2
56 # if basedir was given, then it should be prepended to filenames before
58 if [ -z "$basedir" ]; then
61 trans="path = os.path.join('$basedir', file)"
65 import sys, os, string, py_compile
68 print 'Byte-compiling python modules...'
69 for file in string.split(files):
71 if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'):
75 py_compile.compile(path)
78 # this will fail for python < 1.5, but that doesn't matter ...
80 import sys, os, string, py_compile
83 print 'Byte-compiling python modules (optimised versions) ...'
84 for file in string.split(files):
86 if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'):
90 py_compile.compile(path)
91 print" 2>/dev/null || :