2 # py-compile - Compile a Python program
4 scriptversion
=2011-06-08.12
; # UTC
6 # Copyright (C) 2000, 2001, 2003, 2004, 2005, 2008, 2009, 2011 Free
7 # Software Foundation, Inc.
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 2, 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
40 echo "Try \`$me --help' for more information." >&2
46 while test $# -ne 0; do
49 if test $# -lt 2; then
50 usage_error
"option '--basedir' requires an argument"
57 if test $# -lt 2; then
58 usage_error
"option '--destdir' requires an argument"
66 Usage
: py-compile
[--help] [--version] [--basedir DIR
] [--destdir DIR
] FILES...
"
68 Byte compile some python scripts FILES. Use --destdir to specify any
69 leading directory path to the FILES that you don't want to include in the
70 byte compiled file. Specify --basedir for any additional path information you
71 do want to be shown in the byte compiled file.
74 py-compile --destdir /tmp/pkg-root --basedir /usr/share/test test.py test2.py
76 Report bugs to <bug-automake@gnu.org>.
81 echo "$me $scriptversion"
89 usage_error "unrecognized option
'$1'"
99 if test -z "$files"; then
100 usage_error "no files given
"
103 # if basedir was given, then it should be prepended to filenames before
105 if [ -z "$basedir" ]; then
106 pathtrans="path
= file"
108 pathtrans="path
= os.path.
join('$basedir', file)"
111 # if destdir was given, then it needs to be prepended to the filename to
112 # byte compile but not go into the compiled file.
113 if [ -z "$destdir" ]; then
114 filetrans="filepath
= path
"
116 filetrans="filepath
= os.path.normpath
('$destdir' + os.sep
+ path
)"
120 import sys
, os
, py_compile
124 sys.stdout.
write('Byte-compiling python modules...\n')
125 for file in files.
split():
128 if not os.path.exists
(filepath
) or not
(len
(filepath
) >= 3
129 and filepath
[-3:] == '.py'):
131 sys.stdout.
write(file)
133 py_compile.compile
(filepath
, filepath
+ 'c', path
)
134 sys.stdout.
write('\n')" || exit $?
136 # this will fail for python < 1.5, but that doesn't matter ...
138 import sys
, os
, py_compile
141 sys.stdout.
write('Byte-compiling python modules (optimized versions) ...\n')
142 for file in files.
split():
145 if not os.path.exists
(filepath
) or not
(len
(filepath
) >= 3
146 and filepath
[-3:] == '.py'):
148 sys.stdout.
write(file)
150 py_compile.compile
(filepath
, filepath
+ 'o', path
)
151 sys.stdout.
write('\n')" 2>/dev/null || :
156 # eval: (add-hook 'write-file-hooks 'time-stamp)
157 # time-stamp-start: "scriptversion
="
158 # time-stamp-format: "%:y-
%02m-
%02d.
%02H
"
159 # time-stamp-time-zone: "UTC
"
160 # time-stamp-end: "; # UTC"