For PR automake/72:
[automake.git] / py-compile
blobb60649de66c4e28f90201ce8b25d6589921adce7
1 #!/bin/sh
2 # called as "py-compile [--basedir DIR] PY_FILES ...
4 if [ -z "$PYTHON" ]; then
5 PYTHON=python
6 fi
8 basedir=
10 case "$1" in
11 --basedir)
12 basedir=$2
13 shift 2
15 --help)
16 echo "Usage: py-compile [--basedir DIR] PY_FILES ..."
17 echo "Byte compile some python scripts. This should be performed"
18 echo "after they have been moved to the final installation location"
19 exit 0
21 --version)
22 echo "py-compile version 0.0"
23 exit 0
25 esac
27 if [ $# = 0 ]; then
28 echo "No files given to $0" 1>&2
29 exit 1
32 # if basedir was given, then it should be prepended to filenames before
33 # byte compilation.
34 if [ -z "$basedir" ]; then
35 trans="path = file"
36 else
37 trans="path = os.path.join('$basedir', file)"
40 $PYTHON -c "
41 import sys, os, string, py_compile
43 files = '''$*'''
44 print 'Byte-compiling python modules...'
45 for file in string.split(files):
46 $trans
47 if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'):
48 continue
49 print file,
50 sys.stdout.flush()
51 py_compile.compile(path)
52 print" || exit $?
54 # this will fail for python < 1.5, but that doesn't matter ...
55 $PYTHON -O -c "
56 import sys, os, string, py_compile
58 files = '''$*'''
59 print 'Byte-compiling python modules (optimised versions) ...'
60 for file in string.split(files):
61 $trans
62 if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'):
63 continue
64 print file,
65 sys.stdout.flush()
66 py_compile.compile(path)
67 print" 2>/dev/null || :