2 # py-compile - Compile a Python program
4 scriptversion=2009-04-28.21; # UTC
6 # Copyright (C) 2000, 2001, 2003, 2004, 2005, 2008, 2009 Free Software
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3, or (at your option)
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # As a special exception to the GNU General Public License, if you
23 # distribute this file as part of a program that contains a
24 # configuration script generated by Autoconf, you may include it under
25 # the same distribution terms that you use for the rest of that program.
27 # This file is maintained in Automake, please report
28 # bugs to <bug-automake@gnu.org> or send patches to
29 # <automake-patches@gnu.org>.
31 if [ -z "$PYTHON" ]; then
38 while test $# -ne 0; do
42 if test -z "$basedir"; then
43 echo "$0: Missing argument to --basedir." 1>&2
50 if test -z "$destdir"; then
51 echo "$0: Missing argument to --destdir." 1>&2
58 Usage: py-compile [--help] [--version] [--basedir DIR] [--destdir DIR] FILES..."
60 Byte compile some python scripts FILES. Use --destdir to specify any
61 leading directory path to the FILES that you don't want to include in the
62 byte compiled file. Specify --basedir for any additional path information you
63 do want to be shown in the byte compiled file.
66 py-compile --destdir /tmp/pkg-root --basedir /usr/share/test test.py test2.py
68 Report bugs to <bug-automake@gnu.org>.
73 echo "py-compile $scriptversion"
83 if test -z "$files"; then
84 echo "$0: No files given. Try \`$0 --help' for more information." 1>&2
88 # if basedir was given, then it should be prepended to filenames before
90 if [ -z "$basedir" ]; then
91 pathtrans="path = file"
93 pathtrans="path = os.path.join('$basedir', file)"
96 # if destdir was given, then it needs to be prepended to the filename to
97 # byte compile but not go into the compiled file.
98 if [ -z "$destdir" ]; then
99 filetrans="filepath = path"
101 filetrans="filepath = os.path.normpath('$destdir' + os.sep + path)"
105 import sys, os, py_compile
109 sys.stdout.write('Byte-compiling python modules...\n')
110 for file in files.split():
113 if not os.path.exists(filepath) or not (len(filepath) >= 3
114 and filepath[-3:] == '.py'):
116 sys.stdout.write(file)
118 py_compile.compile(filepath, filepath + 'c', path)
119 sys.stdout.write('\n')" || exit $?
121 # this will fail for python < 1.5, but that doesn't matter ...
123 import sys, os, py_compile
126 sys.stdout.write('Byte-compiling python modules (optimized versions) ...\n')
127 for file in files.split():
130 if not os.path.exists(filepath) or not (len(filepath) >= 3
131 and filepath[-3:] == '.py'):
133 sys.stdout.write(file)
135 py_compile.compile(filepath, filepath + 'o', path)
136 sys.stdout.write('\n')" 2>/dev/null || :
141 # eval: (add-hook 'write-file-hooks 'time-stamp)
142 # time-stamp-start: "scriptversion="
143 # time-stamp-format: "%:y-%02m-%02d.%02H"
144 # time-stamp-time-zone: "UTC"
145 # time-stamp-end: "; # UTC"