2 # py-compile - Compile a Python program
4 scriptversion
=2011-06-08.12
; # UTC
6 # Copyright (C) 2000-2012 Free Software Foundation, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
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 # This file is maintained in Automake, please report
27 # bugs to <bug-automake@gnu.org> or send patches to
28 # <automake-patches@gnu.org>.
30 if [ -z "$PYTHON" ]; then
39 echo "Try '$me --help' for more information." >&2
45 while test $# -ne 0; do
48 if test $# -lt 2; then
49 usage_error
"option '--basedir' requires an argument"
56 if test $# -lt 2; then
57 usage_error
"option '--destdir' requires an argument"
65 Usage
: py-compile
[--help] [--version] [--basedir DIR
] [--destdir DIR
] FILES...
"
67 Byte compile some python scripts FILES. Use --destdir to specify any
68 leading directory path to the FILES that you don't want to include in the
69 byte compiled file. Specify --basedir for any additional path information you
70 do want to be shown in the byte compiled file.
73 py-compile --destdir /tmp/pkg-root --basedir /usr/share/test test.py test2.py
75 Report bugs to <bug-automake@gnu.org>.
80 echo "$me $scriptversion"
88 usage_error "unrecognized option
'$1'"
98 if test -z "$files"; then
99 usage_error "no files given
"
102 # if basedir was given, then it should be prepended to filenames before
104 if [ -z "$basedir" ]; then
105 pathtrans="path
= file"
107 pathtrans="path
= os.path.
join('$basedir', file)"
110 # if destdir was given, then it needs to be prepended to the filename to
111 # byte compile but not go into the compiled file.
112 if [ -z "$destdir" ]; then
113 filetrans="filepath
= path
"
115 filetrans="filepath
= os.path.normpath
('$destdir' + os.sep
+ path
)"
119 import sys
, os
, py_compile
123 sys.stdout.
write('Byte-compiling python modules...\n')
124 for file in files.
split():
127 if not os.path.exists
(filepath
) or not
(len
(filepath
) >= 3
128 and filepath
[-3:] == '.py'):
130 sys.stdout.
write(file)
132 py_compile.compile
(filepath
, filepath
+ 'c', path
)
133 sys.stdout.
write('\n')" || exit $?
135 # this will fail for python < 1.5, but that doesn't matter ...
137 import sys
, os
, py_compile
140 sys.stdout.
write('Byte-compiling python modules (optimized versions) ...\n')
141 for file in files.
split():
144 if not os.path.exists
(filepath
) or not
(len
(filepath
) >= 3
145 and filepath
[-3:] == '.py'):
147 sys.stdout.
write(file)
149 py_compile.compile
(filepath
, filepath
+ 'o', path
)
150 sys.stdout.
write('\n')" 2>/dev/null || :
155 # eval: (add-hook 'write-file-hooks 'time-stamp)
156 # time-stamp-start: "scriptversion
="
157 # time-stamp-format: "%:y-
%02m-
%02d.
%02H
"
158 # time-stamp-time-zone: "UTC
"
159 # time-stamp-end: "; # UTC"