source: chapter08/python.xml@ a093e70

multilib trunk xry111/arm64 xry111/loongarch
Last change on this file since a093e70 was a093e70, checked in by Xi Ruoyao <xry111@…>, 2 months ago

python: Run test suite with a time limit

The test hang issue is not related to partial environment. It's just a
known issue (for eg https://github.com/python/cpython/issues/91155) and
happens when we are unlucky.

So just run the test suite with a timeout. 1 SBU should be enough: it's
approximately 4 times of the time used by the slowest test case, on both
an old Athlon 64 3000+ and a Core i5-11300H.

I've not seen any test failure on a complete system (the expat-related
failure seems fixed by expat-2.6.2 or 2.6.1). TODO: really test this
with LFS chroot and document failures if any.

  • Property mode set to 100644
File size: 10.4 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4 <!ENTITY % general-entities SYSTEM "../general.ent">
5 %general-entities;
6]>
7
8<sect1 id="ch-system-Python" role="wrap">
9 <?dbhtml filename="Python.html"?>
10
11 <sect1info condition="script">
12 <productname>Python</productname>
13 <productnumber>&python-version;</productnumber>
14 <address>&python-url;</address>
15 </sect1info>
16
17 <title>Python-&python-version;</title>
18
19 <indexterm zone="ch-system-Python">
20 <primary sortas="a-Python">Python</primary>
21 </indexterm>
22
23 <sect2 role="package">
24 <title/>
25
26 <para>The Python 3 package contains the Python development environment. It
27 is useful for object-oriented programming, writing scripts, prototyping
28 large programs, and developing entire applications. Python is an interpreted
29 computer language.</para>
30
31 <segmentedlist>
32 <segtitle>&buildtime;</segtitle>
33 <segtitle>&diskspace;</segtitle>
34
35 <seglistitem>
36 <seg>&python-fin-sbu;</seg>
37 <seg>&python-fin-du;</seg>
38 </seglistitem>
39 </segmentedlist>
40
41 </sect2>
42
43 <sect2 role="installation">
44 <title>Installation of Python 3</title>
45
46 <para>Prepare Python for compilation:</para>
47
48<screen><userinput remap="configure">./configure --prefix=/usr \
49 --enable-shared \
50 --with-system-expat \
51 --enable-optimizations</userinput></screen>
52
53 <variablelist>
54 <title>The meaning of the configure options:</title>
55
56 <varlistentry>
57 <term><parameter>--with-system-expat</parameter></term>
58 <listitem>
59 <para>This switch enables linking against the system version of
60 <application>Expat</application>.</para>
61 </listitem>
62 </varlistentry>
63
64 <varlistentry>
65 <term><parameter>--enable-optimizations</parameter></term>
66 <listitem>
67 <para>This switch enables extensive, but time-consuming, optimization
68 steps. The interpreter is built twice; tests performed on the first
69 build are used to improve the optimized final version.</para>
70 <!-- This description was drawn from the README.rst file
71 in the Python-3.11.0 package. -->
72 </listitem>
73 </varlistentry>
74
75 </variablelist>
76
77 <para>Compile the package:</para>
78
79<screen><userinput remap="make">make</userinput></screen>
80
81 <para>Some tests are known to hang indefinitely. So to test the
82 results, run the test suite but set a 2-minute time limit for each
83 test case:</para>
84
85<screen><userinput remap="test">make test TESTOPTS="--timeout 120"</userinput></screen>
86
87 <para>For a relatively slow system you may need to increase the time
88 limit and 1 SBU (measured when building Binutils pass 1 with one CPU
89 core) should be enough. Some tests are flaky, so the test suite will
90 automatically re-run failed tests. If a test failed but then passed
91 when re-run, it should be considered as passed.</para>
92
93 <para>Install the package:</para>
94
95<screen><userinput remap="install">make install</userinput></screen>
96
97 <para>We use the <command>pip3</command> command to
98 install Python 3 programs and modules for all users as
99 <systemitem class='username'>root</systemitem> in several places in this book.
100 This conflicts with the Python developers' recommendation: to install packages into a
101 virtual environment, or into the home directory of a regular user (by running
102 <command>pip3</command> as this user). A multi-line warning
103 is triggered whenever <command>pip3</command> is issued by the
104 <systemitem class='username'>root</systemitem> user.</para>
105
106 <para>The main reason
107 for the recommendation is to avoid conflicts with the system's
108 package manager (<command>dpkg</command>, for example). LFS does not
109 have a system-wide package manager, so this is not a problem. Also,
110 <command>pip3</command> will check for a new version of
111 itself whenever it's run. Since domain name resolution is not yet configured
112 in the LFS chroot environment, <command>pip3</command> cannot check
113 for a new version of itself, and will
114 produce a warning. </para>
115
116 <para>After we boot the LFS system and set up a network connection,
117 a different warning will be issued, telling the user to update <command>pip3</command>
118 from a pre-built wheel on PyPI (whenever a new version is available). But LFS
119 considers <command>pip3</command> to be a part of Python 3, so it should not be
120 updated separately. Also, an update from a pre-built wheel would deviate
121 from our objective: to build a Linux system from source code. So the
122 warning about a new version of <command>pip3</command> should be ignored as
123 well. If you wish, you can suppress all these warnings by running the following
124 command, which creates a configuration file:</para>
125
126<screen><userinput remap="install">cat &gt; /etc/pip.conf &lt;&lt; EOF
127<literal>[global]
128root-user-action = ignore
129disable-pip-version-check = true</literal>
130EOF
131</userinput></screen>
132<!--
133<screen><userinput remap="install">sed -e '/def warn_if_run_as_root/a\ return' \
134 -i /usr/lib/python3.10/site-packages/pip/_internal/cli/req_command.py
135</userinput></screen>
136-->
137 <important>
138 <para>
139 In LFS and BLFS we normally build and install Python modules with the
140 <command>pip3</command> command. Please be sure that the
141 <command>pip3 install</command> commands in both books are
142 run as the &root; user (unless it's for a Python virtual environment).
143 Running <command>pip3 install</command> as a non-&root; user may seem
144 to work, but it will cause the installed module to be inaccessible
145 by other users.
146 </para>
147
148 <para>
149 <command>pip3 install</command> will not reinstall an already installed
150 module automatically. When using the <command>pip3 install</command>
151 command to upgrade a module (for example, from meson-0.61.3 to
152 meson-0.62.0), insert the option <parameter>--upgrade</parameter> into
153 the command line. If it's really necessary to downgrade a module, or
154 reinstall the same version for some reason, insert
155 <parameter>--force-reinstall --no-deps</parameter> into the command
156 line.
157 </para>
158 </important>
159
160 <para>If desired, install the preformatted documentation:</para>
161
162<screen><userinput remap="install">install -v -dm755 /usr/share/doc/python-&python-version;/html
163
164tar --no-same-owner \
165 -xvf ../python-&python-version;-docs-html.tar.bz2
166cp -R --no-preserve=mode python-&python-version;-docs-html/* \
167 /usr/share/doc/python-&python-version;/html</userinput></screen>
168
169 <variablelist>
170 <title>The meaning of the documentation install commands:</title>
171
172 <varlistentry>
173 <term><option>--no-same-owner</option> (tar) and <option>--no-preserve=mode</option> (cp)</term>
174 <listitem>
175 <para>Ensure the installed files have the correct ownership and
176 permissions. Without these options, <application>tar</application>
177 will install the package files with the upstream creator's values
178 and files would have restrictive permissions.
179 </para>
180 </listitem>
181 </varlistentry>
182
183 </variablelist>
184
185 </sect2>
186
187 <sect2 id="contents-python" role="content">
188 <title>Contents of Python 3</title>
189
190 <segmentedlist>
191 <segtitle>Installed programs</segtitle>
192 <segtitle>Installed library</segtitle>
193 <segtitle>Installed directories</segtitle>
194
195 <seglistitem>
196 <seg>
197 2to3, idle3, pip3, pydoc3, python3, and python3-config
198 </seg>
199 <seg>
200 libpython&python-minor;.so and libpython3.so
201 </seg>
202 <seg>
203 /usr/include/python&python-minor;,
204 /usr/lib/python3, and
205 /usr/share/doc/python-&python-version;
206 </seg>
207 </seglistitem>
208 </segmentedlist>
209
210 <variablelist>
211 <bridgehead renderas="sect3">Short Descriptions</bridgehead>
212 <?dbfo list-presentation="list"?>
213 <?dbhtml list-presentation="table"?>
214
215 <varlistentry id="python-2to3">
216 <term><command>2to3</command></term>
217 <listitem>
218 <para>
219 is a <application>Python</application> program that reads
220 <application>Python 2.x</application> source code and applies a
221 series of fixes to transform it into
222 valid <application>Python 3.x</application> code
223 </para>
224 <indexterm zone="ch-system-Python">
225 <primary sortas="b-2to3">2to3</primary>
226 </indexterm>
227 </listitem>
228 </varlistentry>
229
230 <varlistentry id="idle3">
231 <term><command>idle3</command></term>
232 <listitem>
233 <para>
234 is a wrapper script that opens a <application>Python</application>
235 aware GUI editor. For this script to run, you must have installed
236 <application>Tk</application> before Python, so that the Tkinter
237 Python module is built.
238 </para>
239 <indexterm zone="ch-system-Python">
240 <primary sortas="b-idle3">idle3</primary>
241 </indexterm>
242 </listitem>
243 </varlistentry>
244
245 <varlistentry id="pip3">
246 <term><command>pip3</command></term>
247 <listitem>
248 <para>
249 The package installer for Python. You can use pip to install
250 packages from Python Package Index and other indexes.
251 </para>
252 <indexterm zone="ch-system-Python">
253 <primary sortas="b-pip3">pip3</primary>
254 </indexterm>
255 </listitem>
256 </varlistentry>
257
258 <varlistentry id="pydoc3">
259 <term><command>pydoc3</command></term>
260 <listitem>
261 <para>
262 is the <application>Python</application> documentation tool
263 </para>
264 <indexterm zone="ch-system-Python">
265 <primary sortas="b-pydoc3">pydoc3</primary>
266 </indexterm>
267 </listitem>
268 </varlistentry>
269
270 <varlistentry id="python3">
271 <term><command>python3</command></term>
272 <listitem>
273 <para>
274 is the interpreter for Python, an interpreted, interactive,
275 object-oriented programming language
276 </para>
277 <indexterm zone="ch-system-Python">
278 <primary sortas="b-python3">python3</primary>
279 </indexterm>
280 </listitem>
281 </varlistentry>
282
283 </variablelist>
284
285 </sect2>
286
287</sect1>
288
Note: See TracBrowser for help on using the repository browser.