Skip to content

Commit

Permalink
Add notes on musl detection and version extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Mar 19, 2021
1 parent ad1d0d4 commit 001f740
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion pep-0656.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,49 @@ Tags using the new scheme will take the form::

musllinux_${MUSLMAJOR}_${MUSLMINOR}_${ARCH}

Reading the musl version
------------------------

The musl version values can be obtains by executing the musl libc
shared library the Python interpreter is currently running on, and
parsing the output::

def get_musl_major_minor(ld_so: str) -> Optional[Tuple[int, int]]:
"""Detect musl runtime version.

Returns a two-tuple ``(major, minor)`` that indicates musl
library's version, or ``None`` if the given value does not output
expected information.

The libc library should output something like this to stderr::

musl libc (x86_64)
Version 1.2.2
Dynamic Program Loader
"""
proc = subprocess.run([ld_so], stderr=subprocess.PIPE, text=True)
lines = (line.strip() for line in proc.stderr.splitlines())
lines = [line for line in lines if line]
if len(lines) < 2 or lines[0][:4] != "musl":
return None
match = re.match(
r"Version (\d+)\.(\d+)",
lines[1],
flags=re.MULTILINE,
)
if match:
return (int(match.group(1)), int(match.group(2)))
return None

There are currently two possible ways to find the musl library's
location that a Python interpreter is running on, either with the
system ``ldd`` command [ldd]_, or by parsing the ``PT_INTERP``
section's value from the executable's ELF header [elf]_.


Formatting the tag
------------------

Distributions using the tag make similar promises to those described
in :pep:`600`, including:

Expand All @@ -85,6 +128,9 @@ The value can be formatted with the following Python code::
arch = arch.replace("-", "_")
return f"musllinux_{musl_version[0]}_{musl_version[1]}_{arch}"

Recommendations to package indexes
----------------------------------

It is recommended for Python package repositories, including PyPI, to
accept platform tags matching the following regular expression::

Expand All @@ -93,7 +139,8 @@ accept platform tags matching the following regular expression::
Python package repositories may impose additional requirements to
reject Wheels with known issues, including but not limited to:

* A ``musllinux_1_1`` wheel containing symbols only available in musl 1.2.
* A ``musllinux_1_1`` wheel containing symbols only available in musl
1.2 or later.
* Wheel that depends on external libraries not considered generally
available to the intended audience of the package index.
* A platform tag claiming compatibility to a non-existent musl version
Expand Down Expand Up @@ -134,6 +181,10 @@ References
.. [musl-compat-ml] https://mail.python.org/archives/list/distutils-sig@python.org/message/VRXSTNXWHPAVUW253ZCWWMP7WDTBAQDL/
.. [ldd] https://www.unix.com/man-page/posix/1/ldd/
.. [elf] https://refspecs.linuxfoundation.org/elf/elf.pdf
Copyright
=========
Expand Down

0 comments on commit 001f740

Please sign in to comment.