Skip to content

Commit 72b5b63

Browse files
committed
Merge pull request #31 from njsmith/pep-changes
PEP updates
2 parents df707e8 + d800d88 commit 72b5b63

File tree

2 files changed

+94
-29
lines changed

2 files changed

+94
-29
lines changed

Diff for: docker/build_scripts/manylinux1-check.py

-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ def is_manylinux1_compatible():
66
if get_platform() not in ["linux-x86_64", "linux-i686"]:
77
return False
88

9-
# "wide" Unicode mode is mandatory (always true on CPython 3.3+)
10-
import sys
11-
if sys.maxunicode <= 0xFFFF:
12-
return False
13-
149
# Check for presence of _manylinux module
1510
try:
1611
import _manylinux

Diff for: pep-513.rst

+94-24
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ For these reasons, to achieve broad portability, Python wheels
126126

127127
To be eligible for the ``manylinux1`` platform tag, a Python wheel must
128128
therefore both (a) contain binary executables and compiled code that links
129-
*only* to libraries (other than the appropriate ``libpython`` library, which is
130-
always a permitted dependency consistent with the PEP 425 ABI tag) with SONAMEs
129+
*only* to libraries with SONAMEs
131130
included in the following list: ::
132131

133132
libpanelw.so.5
@@ -153,11 +152,7 @@ included in the following list: ::
153152
libglib-2.0.so.0
154153

155154
and, (b) work on a stock CentOS 5.11 [6]_ system that contains the system
156-
package manager's provided versions of these libraries. In addition,
157-
for wheels targeting CPython 3.2 and earlier (including all 2.x
158-
versions), there is an extra requirement that (c) the wheel be
159-
built against a version of CPython compiled with 4-byte unicode
160-
support (i.e. one where ``sys.maxunicode > 0xFFFF``).
155+
package manager's provided versions of these libraries.
161156

162157
Because CentOS 5 is only available for x86_64 and i686 architectures,
163158
these are the only architectures currently supported by the ``manylinux1``
@@ -216,6 +211,81 @@ the list above to remove libraries that have turned out to be
216211
problematic or add libraries that have turned out to be safe.
217212

218213

214+
libpythonX.Y.so.1
215+
-----------------
216+
217+
Note that ``libpythonX.Y.so.1`` is *not* on the list of libraries that
218+
a ``manylinux1`` extension is allowed to link to. Explicitly linking
219+
to ``libpythonX.Y.so.1`` is unnecessary in almost all cases: the way
220+
ELF linking works, extension modules that are loaded into the
221+
interpreter automatically get access to all of the interpreter's
222+
symbols, regardless of whether or not the extension itself is
223+
explicitly linked against libpython. Furthermore, explicit linking to
224+
libpython creates problems in the common configuration where Python is
225+
not built with ``--enable-shared``. In particular, on Debian and
226+
Ubuntu systems, ``apt install pythonX.Y`` does not even install
227+
``libpythonX.Y.so.1``, meaning that any wheel that *did* depend on
228+
``libpythonX.Y.so.1`` could fail to import.
229+
230+
There is one situation where extensions that are linked in this way
231+
can fail to work: if a host program (e.g., ``apache2``) uses
232+
``dlopen()`` to load a module (e.g., ``mod_wsgi``) that embeds the
233+
CPython interpreter, and the host program does *not* pass the
234+
``RTLD_GLOBAL`` flag to ``dlopen()``, then the embedded CPython will
235+
be unable to load any extension modules that do not themselves link
236+
explicitly to ``libpythonX.Y.so.1``. Fortunately, ``apache2`` *does*
237+
set the ``RTLD_GLOBAL`` flag, as do all the other programs that
238+
embed-CPython-via-a-dlopened-plugin that we could locate, so this does
239+
not seem to be a serious problem in practice. The incompatibility with
240+
Debian/Ubuntu is more of an issue than the theoretical incompatibility
241+
with a rather obscure corner case.
242+
243+
This is a rather complex and subtle issue that extends beyond
244+
the scope of ``manylinux1``; for more discussion see: [9]_, [10]_,
245+
[11]_.
246+
247+
UCS-2 vs UCS-4 builds
248+
---------------------
249+
250+
All versions of CPython 2.x, plus CPython 3.0-3.2 inclusive, can be
251+
built in two ABI-incompatible modes: builds using the
252+
``--enable-unicode=ucs2`` configure flag store Unicode data in UCS-2
253+
(or really UTF-16) format, while builds using the
254+
``--enable-unicode=ucs4`` configure flag store Unicode data in
255+
UCS-4. (CPython 3.3 and greater use a different storage method that
256+
always supports UCS-4.) If we want to make sure ``ucs2`` wheels don't
257+
get installed into ``ucs4`` CPythons and vice-versa, then something
258+
must be done.
259+
260+
An earlier version of this PEP included a requirement that
261+
``manylinux1`` wheels targeting these older CPython versions should
262+
always use the ``ucs4`` ABI. But then, in between the PEP's initial
263+
acceptance and its implementation, ``pip`` and ``wheel`` gained
264+
first-class support for tracking and checking this aspect of ABI
265+
compatibility for the relevant CPython versions, which is a better
266+
solution. So we now allow the ``manylinux1`` platform tags to be used
267+
in combination with any ABI tag. However, to maintain compatibility it
268+
is crucial to ensure that all ``manylinux1`` wheels include a
269+
non-trivial abi tag. For example, a wheel built against a ``ucs4``
270+
CPython might have a name like::
271+
272+
PKG-VERSION-cp27-cp27mu-manylinux1_x86_64.whl
273+
^^^^^^ Good!
274+
275+
While a wheel built against the ``ucs2`` ABI might have a name like::
276+
277+
PKG-VERSION-cp27-cp27m-manylinux1_x86_64.whl
278+
^^^^^ Okay!
279+
280+
But you should never have a wheel with a name like::
281+
282+
PKG-VERSION-cp27-none-manylinux1_x86_64.whl
283+
^^^^ BAD! Don't do this!
284+
285+
We note for information that the ``ucs4`` ABI appears to be much more
286+
widespread among Linux CPython distributors.
287+
288+
219289
Compilation of Compliant Wheels
220290
===============================
221291

@@ -237,15 +307,15 @@ Docker Image
237307

238308
The first tool is a Docker image based on CentOS 5.11, which is recommended as
239309
an easy to use self-contained build box for compiling ``manylinux1`` wheels
240-
[9]_. Compiling on a more recently-released linux distribution will generally
310+
[12]_. Compiling on a more recently-released linux distribution will generally
241311
introduce dependencies on too-new versioned symbols. The image comes with a
242312
full compiler suite installed (``gcc``, ``g++``, and ``gfortran`` 4.8.2) as
243313
well as the latest releases of Python and ``pip``.
244314

245315
Auditwheel
246316
----------
247317

248-
The second tool is a command line executable called ``auditwheel`` [10]_ that
318+
The second tool is a command line executable called ``auditwheel`` [13]_ that
249319
may aid in package maintainers in dealing with third-party external
250320
dependencies.
251321

@@ -285,7 +355,7 @@ While we acknowledge many approaches for dealing with third-party library
285355
dependencies within ``manylinux1`` wheels, we recognize that the ``manylinux1``
286356
policy encourages bundling external dependencies, a practice
287357
which runs counter to the package management policies of many linux
288-
distributions' system package managers [11]_, [12]_. The primary purpose of
358+
distributions' system package managers [14]_, [15]_. The primary purpose of
289359
this is cross-distro compatibility. Furthermore, ``manylinux1`` wheels on PyPI
290360
occupy a different niche than the Python packages available through the
291361
system package manager.
@@ -352,17 +422,14 @@ think otherwise.
352422
We know of four main sources of potential incompatibility that are
353423
likely to arise in practice:
354424

355-
* "Narrow" unicode builds of Python 3.2 and earlier (including all
356-
versions of Python 2)
357425
* Eventually, in the future, there may exist distributions that break
358426
compatibility with this profile (e.g., if one of the libraries in
359427
the profile changes its ABI in a backwards-incompatible way)
360428
* A linux distribution that is too old (e.g. RHEL 4)
361429
* A linux distribution that does not use ``glibc`` (e.g. Alpine Linux, which is
362430
based on musl ``libc``, or Android)
363431

364-
Checking for unicode configuration compatibility is straightforward,
365-
but the other cases are more subtle. We propose a two-pronged
432+
To address these we propose a two-pronged
366433
approach. To handle potential future incompatibilities, we standardize
367434
a mechanism for a Python distributor to signal that a particular
368435
Python install definitely is or is not compatible with ``manylinux1``:
@@ -389,11 +456,6 @@ Specifically, the algorithm we propose is::
389456
if get_platform() not in ["linux-x86_64", "linux-i686"]:
390457
return False
391458

392-
# "wide" Unicode mode is mandatory (always true on CPython 3.3+)
393-
import sys
394-
if sys.maxunicode <= 0xFFFF:
395-
return False
396-
397459
# Check for presence of _manylinux module
398460
try:
399461
import _manylinux
@@ -522,13 +584,21 @@ References
522584
(https://groups.google.com/forum/#!topic/manylinux-discuss/-4l3rrjfr9U)
523585
.. [8] distutils-sig discussion
524586
(https://mail.python.org/pipermail/distutils-sig/2016-January/027997.html)
525-
.. [9] manylinux1 docker image
526-
(https://quay.io/repository/manylinux/manylinux)
527-
.. [10] auditwheel tool
587+
.. [9] distutils-sig discussion
588+
(https://mail.python.org/pipermail/distutils-sig/2016-February/028275.html)
589+
.. [10] github issue discussion
590+
(https://github.com/pypa/manylinux/issues/30)
591+
.. [11] python bug tracker discussion
592+
(https://bugs.python.org/issue21536)
593+
.. [12] manylinux1 docker images
594+
(Source: https://github.com/pypa/manylinux;
595+
x86-64: https://quay.io/repository/pypa/manylinux1_x86_64;
596+
x86-32: https://quay.io/repository/pypa/manylinux1_i686)
597+
.. [13] auditwheel tool
528598
(https://pypi.python.org/pypi/auditwheel)
529-
.. [11] Fedora Bundled Software Policy
599+
.. [14] Fedora Bundled Software Policy
530600
(https://fedoraproject.org/wiki/Bundled_Software_policy)
531-
.. [12] Debian Policy Manual -- 4.13: Convenience copies of code
601+
.. [15] Debian Policy Manual -- 4.13: Convenience copies of code
532602
(https://www.debian.org/doc/debian-policy/ch-source.html#s-embeddedfiles)
533603
534604

0 commit comments

Comments
 (0)