2 # py-compile - Compile a Python program
4 scriptversion=2005-05-14.22
6 # Copyright (C) 2000-2020 CEA/DEN, EDF R&D
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
13 # This library 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 GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 # This program is free software; you can redistribute it and/or modify
26 # it under the terms of the GNU General Public License as published by
27 # the Free Software Foundation; either version 2, or (at your option)
30 # This program is distributed in the hope that it will be useful,
31 # but WITHOUT ANY WARRANTY; without even the implied warranty of
32 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 # GNU General Public License for more details.
35 # You should have received a copy of the GNU General Public License
36 # along with this program; if not, write to the Free Software
37 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
40 # As a special exception to the GNU General Public License, if you
41 # distribute this file as part of a program that contains a
42 # configuration script generated by Autoconf, you may include it under
43 # the same distribution terms that you use for the rest of that program.
45 # This file is maintained in Automake, please report
46 # bugs to <bug-automake@gnu.org> or send patches to
47 # <automake-patches@gnu.org>.
49 if [ -z "$PYTHON" ]; then
56 while test $# -ne 0; do
60 if test -z "$basedir"; then
61 echo "$0: Missing argument to --basedir." 1>&2
68 if test -z "$destdir"; then
69 echo "$0: Missing argument to --destdir." 1>&2
76 Usage: py-compile [--help] [--version] [--basedir DIR] [--destdir DIR] FILES..."
78 Byte compile some python scripts FILES. Use --destdir to specify any
79 leading directory path to the FILES that you don't want to include in the
80 byte compiled file. Specify --basedir for any additional path information you
81 do want to be shown in the byte compiled file.
84 py-compile --destdir /tmp/pkg-root --basedir /usr/share/test test.py test2.py
86 Report bugs to <bug-automake@gnu.org>.
91 echo "py-compile $scriptversion"
101 if test -z "$files"; then
102 echo "$0: No files given. Try \`$0 --help' for more information." 1>&2
106 # if basedir was given, then it should be prepended to filenames before
108 if [ -z "$basedir" ]; then
109 pathtrans="path = file"
111 pathtrans="path = os.path.join('$basedir', file)"
114 # if destdir was given, then it needs to be prepended to the filename to
115 # byte compile but not go into the compiled file.
116 if [ -z "$destdir" ]; then
117 filetrans="filepath = path"
119 filetrans="filepath = os.path.normpath('$destdir' + os.sep + path)"
123 import sys, os, string, py_compile
127 print('Byte-compiling python modules...')
128 for file in string.split(files):
131 if not os.path.exists(filepath) or not (len(filepath) >= 3
132 and filepath[-3:] == '.py'):
136 py_compile.compile(filepath, filepath + 'c', path)
139 # this will fail for python < 1.5, but that doesn't matter ...
141 import sys, os, string, py_compile
144 print('Byte-compiling python modules (optimized versions) ...')
145 for file in string.split(files):
148 if not os.path.exists(filepath) or not (len(filepath) >= 3
149 and filepath[-3:] == '.py'):
153 py_compile.compile(filepath, filepath + 'o', path)
154 print()" 2>/dev/null || :