Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._vendor.packaging._musllinux Namespace Reference

Data Structures

class  _MuslVersion
 

Functions

Tuple[int,...] _read_unpacked (IO[bytes] f, str fmt)
 
Optional[str] _parse_ld_musl_from_elf (IO[bytes] f)
 
Optional[_MuslVersion_parse_musl_version (str output)
 
Optional[_MuslVersion_get_musl_version (str executable)
 
Iterator[str] platform_tags (str arch)
 

Variables

 plat = sysconfig.get_platform()
 
 end
 
 t
 

Detailed Description

PEP 656 support.

This module implements logic to detect if the currently running Python is
linked against musl, and what musl version is used.

Function Documentation

◆ _get_musl_version()

Optional[_MuslVersion] _get_musl_version ( str  executable)
protected
Detect currently-running musl runtime version.

This is done by checking the specified executable's dynamic linking
information, and invoking the loader to parse its output for a version
string. If the loader is musl, the output would be something like::

    musl libc (x86_64)
    Version 1.2.2
    Dynamic Program Loader

Definition at line 87 of file _musllinux.py.

87def _get_musl_version(executable: str) -> Optional[_MuslVersion]:
88 """Detect currently-running musl runtime version.
89
90 This is done by checking the specified executable's dynamic linking
91 information, and invoking the loader to parse its output for a version
92 string. If the loader is musl, the output would be something like::
93
94 musl libc (x86_64)
95 Version 1.2.2
96 Dynamic Program Loader
97 """
98 with contextlib.ExitStack() as stack:
99 try:
100 f = stack.enter_context(open(executable, "rb"))
101 except OSError:
102 return None
103 ld = _parse_ld_musl_from_elf(f)
104 if not ld:
105 return None
106 proc = subprocess.run([ld], stderr=subprocess.PIPE, universal_newlines=True)
107 return _parse_musl_version(proc.stderr)
108
109
for i

References pip._vendor.packaging._musllinux._parse_ld_musl_from_elf(), pip._vendor.packaging._musllinux._parse_musl_version(), and i.

Referenced by pip._vendor.packaging._musllinux.platform_tags().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _parse_ld_musl_from_elf()

Optional[str] _parse_ld_musl_from_elf ( IO[bytes]  f)
protected
Detect musl libc location by parsing the Python executable.

Based on: https://gist.github.com/lyssdod/f51579ae8d93c8657a5564aefc2ffbca
ELF header: https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html

Definition at line 22 of file _musllinux.py.

22def _parse_ld_musl_from_elf(f: IO[bytes]) -> Optional[str]:
23 """Detect musl libc location by parsing the Python executable.
24
25 Based on: https://gist.github.com/lyssdod/f51579ae8d93c8657a5564aefc2ffbca
26 ELF header: https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html
27 """
28 f.seek(0)
29 try:
30 ident = _read_unpacked(f, "16B")
31 except struct.error:
32 return None
33 if ident[:4] != tuple(b"\x7fELF"): # Invalid magic, not ELF.
34 return None
35 f.seek(struct.calcsize("HHI"), 1) # Skip file type, machine, and version.
36
37 try:
38 # e_fmt: Format for program header.
39 # p_fmt: Format for section header.
40 # p_idx: Indexes to find p_type, p_offset, and p_filesz.
41 e_fmt, p_fmt, p_idx = {
42 1: ("IIIIHHH", "IIIIIIII", (0, 1, 4)), # 32-bit.
43 2: ("QQQIHHH", "IIQQQQQQ", (0, 2, 5)), # 64-bit.
44 }[ident[4]]
45 except KeyError:
46 return None
47 else:
48 p_get = operator.itemgetter(*p_idx)
49
50 # Find the interpreter section and return its content.
51 try:
52 _, e_phoff, _, _, _, e_phentsize, e_phnum = _read_unpacked(f, e_fmt)
53 except struct.error:
54 return None
55 for i in range(e_phnum + 1):
56 f.seek(e_phoff + e_phentsize * i)
57 try:
58 p_type, p_offset, p_filesz = p_get(_read_unpacked(f, p_fmt))
59 except struct.error:
60 return None
61 if p_type != 3: # Not PT_INTERP.
62 continue
63 f.seek(p_offset)
64 interpreter = os.fsdecode(f.read(p_filesz)).strip("\0")
65 if "musl" not in interpreter:
66 return None
67 return interpreter
68 return None
69
70

References pip._vendor.packaging._musllinux._read_unpacked(), and i.

Referenced by pip._vendor.packaging._musllinux._get_musl_version().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _parse_musl_version()

Optional[_MuslVersion] _parse_musl_version ( str  output)
protected

Definition at line 76 of file _musllinux.py.

76def _parse_musl_version(output: str) -> Optional[_MuslVersion]:
77 lines = [n for n in (n.strip() for n in output.splitlines()) if n]
78 if len(lines) < 2 or lines[0][:4] != "musl":
79 return None
80 m = re.match(r"Version (\d+)\.(\d+)", lines[1])
81 if not m:
82 return None
83 return _MuslVersion(major=int(m.group(1)), minor=int(m.group(2)))
84
85
86@functools.lru_cache()

References i.

Referenced by pip._vendor.packaging._musllinux._get_musl_version().

Here is the caller graph for this function:

◆ _read_unpacked()

Tuple[int, ...] _read_unpacked ( IO[bytes]  f,
str  fmt 
)
protected

Definition at line 18 of file _musllinux.py.

18def _read_unpacked(f: IO[bytes], fmt: str) -> Tuple[int, ...]:
19 return struct.unpack(fmt, f.read(struct.calcsize(fmt)))
20
21

References i.

Referenced by pip._vendor.packaging._musllinux._parse_ld_musl_from_elf().

Here is the caller graph for this function:

◆ platform_tags()

Iterator[str] platform_tags ( str  arch)
Generate musllinux tags compatible to the current platform.

:param arch: Should be the part of platform tag after the ``linux_``
    prefix, e.g. ``x86_64``. The ``linux_`` prefix is assumed as a
    prerequisite for the current platform to be musllinux-compatible.

:returns: An iterator of compatible musllinux tags.

Definition at line 110 of file _musllinux.py.

110def platform_tags(arch: str) -> Iterator[str]:
111 """Generate musllinux tags compatible to the current platform.
112
113 :param arch: Should be the part of platform tag after the ``linux_``
114 prefix, e.g. ``x86_64``. The ``linux_`` prefix is assumed as a
115 prerequisite for the current platform to be musllinux-compatible.
116
117 :returns: An iterator of compatible musllinux tags.
118 """
119 sys_musl = _get_musl_version(sys.executable)
120 if sys_musl is None: # Python not dynamically linked against musl.
121 return
122 for minor in range(sys_musl.minor, -1, -1):
123 yield f"musllinux_{sys_musl.major}_{minor}_{arch}"
124
125

References pip._vendor.packaging._musllinux._get_musl_version(), and i.

Here is the call graph for this function:

Variable Documentation

◆ end

end

Definition at line 134 of file _musllinux.py.

◆ plat

plat = sysconfig.get_platform()

Definition at line 129 of file _musllinux.py.

◆ t

t

Definition at line 136 of file _musllinux.py.