Debian Codegraph @

autoconf/py-compile

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 # py-compile - Compile a Python program
3
4 scriptversion=2023-03-30.00; # UTC
5
6 # Copyright (C) 2000-2023 Free Software Foundation, Inc.
7
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)
11 # any later version.
12
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.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20
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.
25
26 # This file is maintained in Automake, please report
27 # bugs to <[email protected]> or send patches to
28 # <[email protected]>.
29
30 if testscip-shell system . . test. -z "$PYTHON"; then
31 PYTHON=python
32 fi
33
34 me=py-compile
35
36 usage_errorscip-shell shell lvm2 2.03.31-2 usage_error(). ()
37 {
38 echoscip-shell system . . echo. "$me: $*" >&2
39 echoscip-shell system . . echo. "Try '$me --help' for more information." >&2
40 exit 1
41 }
42
43 basedir=
44 destdir=
45 while testscip-shell system . . test. $# -ne 0; do
46 case "$1" in
47 --basedir)
48 if testscip-shell system . . test. $# -lt 2; then
49 usage_errorscip-shell shell lvm2 2.03.31-2 usage_error(). "option '--basedir' requires an argument"
50 else
51 basedir=$2
52 fi
53 shift
54 ;;
55 --destdir)
56 if testscip-shell system . . test. $# -lt 2; then
57 usage_errorscip-shell shell lvm2 2.03.31-2 usage_error(). "option '--destdir' requires an argument"
58 else
59 destdir=$2
60 fi
61 shift
62 ;;
63 -h|--help)
64 catscip-shell system . . cat. <<\EOF
65 Usage: py-compile [options] FILES...
66
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.
71
72 Options:
73 --basedir DIR Prefix all FILES with DIR, and include in error messages.
74 --destdir DIR Prefix all FILES with DIR before compiling.
75 -v, --version Display version information.
76 -h, --help This help screen.
77
78 Example:
79 py-compile --destdir /tmp/pkg-root --basedir /usr/share/test test.py test2.py
80
81 Report bugs to <[email protected]>.
82 EOF
83 exit $?
84 ;;
85 -v|--version)
86 echoscip-shell system . . echo. "$me $scriptversion"
87 exit $?
88 ;;
89 --)
90 shift
91 break
92 ;;
93 -*)
94 usage_errorscip-shell shell lvm2 2.03.31-2 usage_error(). "unrecognized option '$1'"
95 ;;
96 *)
97 break
98 ;;
99 esac
100 shift
101 done
102
103 if testscip-shell system . . test. $# -eq 0; then
104 usage_errorscip-shell shell lvm2 2.03.31-2 usage_error(). "no files given"
105 fi
106
107 # if basedir was given, then it should be prepended to filenames before
108 # byte compilation.
109 if testscip-shell system . . test. -z "$basedir"; then
110 pathtrans="path = file"
111 else
112 pathtrans="path = os.path.join('$basedir', file)"
113 fi
114
115 # if destdir was given, then it needs to be prepended to the filename to
116 # byte compile but not go into the compiled file.
117 if testscip-shell system . . test. -z "$destdir"; then
118 filetrans="filepath = path"
119 else
120 filetrans="filepath = os.path.normpath('$destdir' + os.sep + path)"
121 fi
122
123 python_major=`$PYTHON -c 'import sys; print(sys.version_info[0])'`
124 if testscip-shell system . . test. -z "$python_major"; then
125 usage_errorscip-shell shell lvm2 2.03.31-2 usage_error(). "could not determine $PYTHON major version"
126 fi
127
128 case $python_major in
129 [01])
130 usage_errorscip-shell shell lvm2 2.03.31-2 usage_error(). "python version 0.x and 1.x not supported"
131 ;;
132 esac
133
134 python_minor=`$PYTHON -c 'import sys; print(sys.version_info[1])'`
135
136 # NB: When adding support for newer versions, prefer copying & adding new cases
137 # rather than try to keep things merged with shell variables.
138
139 # First byte compile (no optimization) all the modules.
140 # This works for all currently known Python versions.
141 $PYTHON -c "
142 import sys, os, py_compile
143
144 try:
145 import importlib
146 except ImportError:
147 importlib = None
148
149 # importlib.util.cache_from_source was added in 3.4
150 if (
151 hasattr(importlib, 'util')
152 and hasattr(importlib.util, 'cache_from_source')
153 ):
154 destpath = importlib.util.cache_from_source
155 else:
156 destpath = lambda filepath: filepath + 'c'
157
158 sys.stdout.write('Byte-compiling python modules...\n')
159 for file in sys.argv[1:]:
160 $pathtrans
161 $filetrans
162 if (
163 not os.path.exists(filepath)
164 or not (len(filepath) >= 3 and filepath[-3:] == '.py')
165 ):
166 continue
167 sys.stdout.write(file + ' ')
168 sys.stdout.flush()
169 py_compile.compile(filepath, destpath(filepath), path)
170 sys.stdout.write('\n')" "$@" || exit $?
171
172 # Then byte compile w/optimization all the modules.
173 $PYTHON -O -c "
174 import sys, os, py_compile
175
176 try:
177 import importlib
178 except ImportError:
179 importlib = None
180
181 # importlib.util.cache_from_source was added in 3.4
182 if (
183 hasattr(importlib, 'util')
184 and hasattr(importlib.util, 'cache_from_source')
185 ):
186 destpath = importlib.util.cache_from_source
187 else:
188 destpath = lambda filepath: filepath + 'o'
189
190 # pypy2 does not use .pyo optimization
191 if sys.version_info.major <= 2 and hasattr(sys, 'pypy_translation_info'):
192 sys.exit(0)
193
194 sys.stdout.write('Byte-compiling python modules (optimized versions) ...\n')
195 for file in sys.argv[1:]:
196 $pathtrans
197 $filetrans
198 if (
199 not os.path.exists(filepath)
200 or not (len(filepath) >= 3 and filepath[-3:] == '.py')
201 ):
202 continue
203 sys.stdout.write(file + ' ')
204 sys.stdout.flush()
205 py_compile.compile(filepath, destpath(filepath), path)
206 sys.stdout.write('\n')" "$@" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || exit $?
207
208 # Then byte compile w/more optimization.
209 # Only do this for Python 3.5+, see https://bugs.gnu.org/38043 for background.
210 case $python_major.$python_minor in
211 2.*|3.[0-4])
212 ;;
213 *)
214 $PYTHON -OO -c "
215 import sys, os, py_compile, importlib
216
217 sys.stdout.write('Byte-compiling python modules (more optimized versions)'
218 ' ...\n')
219 for file in sys.argv[1:]:
220 $pathtrans
221 $filetrans
222 if (
223 not os.path.exists(filepath)
224 or not (len(filepath) >= 3 and filepath[-3:] == '.py')
225 ):
226 continue
227 sys.stdout.write(file + ' ')
228 sys.stdout.flush()
229 py_compile.compile(filepath, importlib.util.cache_from_source(filepath), path)
230 sys.stdout.write('\n')" "$@" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || exit $?
231 ;;
232 esac
233
234 # Local Variables:
235 # mode: shell-script
236 # sh-indentation: 2
237 # eval: (add-hook 'before-save-hook 'time-stamp)
238 # time-stamp-start: "scriptversion="
239 # time-stamp-format: "%:y-%02m-%02d.%02H"
240 # time-stamp-time-zone: "UTC0"
241 # time-stamp-end: "; # UTC"
242 # End: