2
2
# py-compile - Compile a Python program
4
scriptversion=2004-01-12.23
4
scriptversion=2005-05-14.22
6
# Copyright (C) 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
6
# Copyright (C) 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
8
8
# This program is free software; you can redistribute it and/or modify
9
9
# it under the terms of the GNU General Public License as published by
18
18
# You should have received a copy of the GNU General Public License
19
19
# along with this program; if not, write to the Free Software
20
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23
23
# As a special exception to the GNU General Public License, if you
24
24
# distribute this file as part of a program that contains a
41
if test -z "$basedir"; then
42
echo "$0: Missing argument to --basedir." 1>&2
49
Usage: py-compile [--help] [--version] [--basedir DIR] FILES..."
51
Byte compile some python scripts FILES. This should be performed
52
after they have been moved to the final installation location
39
while test $# -ne 0; do
43
if test -z "$basedir"; then
44
echo "$0: Missing argument to --basedir." 1>&2
51
if test -z "$destdir"; then
52
echo "$0: Missing argument to --destdir." 1>&2
59
Usage: py-compile [--help] [--version] [--basedir DIR] [--destdir DIR] FILES..."
61
Byte compile some python scripts FILES. Use --destdir to specify any
62
leading directory path to the FILES that you don't want to include in the
63
byte compiled file. Specify --basedir for any additional path information you
64
do want to be shown in the byte compiled file.
67
py-compile --destdir /tmp/pkg-root --basedir /usr/share/test test.py test2.py
54
69
Report bugs to <bug-automake@gnu.org>.
59
echo "py-compile $scriptversion"
74
echo "py-compile $scriptversion"
84
if test -z "$files"; then
65
85
echo "$0: No files given. Try \`$0 --help' for more information." 1>&2
69
89
# if basedir was given, then it should be prepended to filenames before
70
90
# byte compilation.
71
91
if [ -z "$basedir" ]; then
74
trans="path = os.path.join('$basedir', file)"
92
pathtrans="path = file"
94
pathtrans="path = os.path.join('$basedir', file)"
97
# if destdir was given, then it needs to be prepended to the filename to
98
# byte compile but not go into the compiled file.
99
if [ -z "$destdir" ]; then
100
filetrans="filepath = path"
102
filetrans="filepath = os.path.normpath('$destdir' + os.sep + path)"
78
106
import sys, os, string, py_compile
81
110
print 'Byte-compiling python modules...'
82
111
for file in string.split(files):
84
if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'):
114
if not os.path.exists(filepath) or not (len(filepath) >= 3
115
and filepath[-3:] == '.py'):
87
118
sys.stdout.flush()
88
py_compile.compile(path)
119
py_compile.compile(filepath, filepath + 'c', path)
91
122
# this will fail for python < 1.5, but that doesn't matter ...
93
124
import sys, os, string, py_compile
96
127
print 'Byte-compiling python modules (optimized versions) ...'
97
128
for file in string.split(files):
99
if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'):
131
if not os.path.exists(filepath) or not (len(filepath) >= 3
132
and filepath[-3:] == '.py'):
102
135
sys.stdout.flush()
103
py_compile.compile(path)
136
py_compile.compile(filepath, filepath + 'o', path)
104
137
print" 2>/dev/null || :
106
139
# Local Variables: