Debian Codegraph @

src/auditwheel/main_show.py

raw
1 from __future__ import annotations
2
3 import logging
4 from pathlib import Path
5 from typing import TYPE_CHECKING, Any
6
7 from auditwheel import options
8
9 if TYPE_CHECKING:
10 import argparse
11
12 logger = logging.getLogger(__name__)
13
14
15 def configure_parser(sub_parsers: Any) -> None: # noqa: ANN401
16 help_ = "Audit a wheel for external shared library dependencies."
17 p = sub_parsers.add_parser("show", help=help_, description=help_)
18 p.add_argument("WHEEL_FILE", type=Path, help="Path to wheel file.")
19 options.disable_isa_check(p)
20 options.allow_pure_python_wheel(p)
21 options.ldpaths(p)
22 p.set_defaults(func=execute)
23
24
25 def printp(text: str) -> None:
26 from textwrap import wrap
27
28 print()
29 print("\n".join(wrap(text, break_long_words=False, break_on_hyphens=False)))
30
31
32 def execute(args: argparse.Namespace, parser: argparse.ArgumentParser) -> int:
33 from auditwheel import json
34 from auditwheel.error import NonPlatformWheelError, WheelToolsError
35 from auditwheel.wheel_abi import analyze_wheel_abi
36 from auditwheel.wheeltools import get_wheel_architecture, get_wheel_libc
37
38 wheel_file: Path = args.WHEEL_FILE
39 fn = wheel_file.name
40
41 if not wheel_file.is_file():
42 parser.error(f"cannot access {wheel_file}. No such file")
43
44 fn = wheel_file.name
45 is_pure_python = False
46 try:
47 arch = get_wheel_architecture(fn)
48 except (WheelToolsError, NonPlatformWheelError) as e:
49 logger.warning("The architecture could not be deduced from the wheel filename")
50 is_pure_python = isinstance(e, NonPlatformWheelError)
51 arch = None
52
53 try:
54 libc = get_wheel_libc(fn)
55 except WheelToolsError:
56 logger.debug("The libc could not be deduced from the wheel filename")
57 libc = None
58
59 try:
60 winfo = analyze_wheel_abi(
61 libc,
62 arch,
63 wheel_file,
64 frozenset(),
65 disable_isa_ext_check=args.DISABLE_ISA_EXT_CHECK,
66 allow_graft=False,
67 args_ldpaths=args.LDPATHS,
68 )
69 except NonPlatformWheelError as e:
70 logger.info("%s", e.message)
71 if is_pure_python and args.ALLOW_PURE_PY_WHEEL:
72 return 0
73 return 1
74
75 policies = winfo.policies
76
77 libs_with_versions = [f"{k} with versions {v}" for k, v in winfo.versioned_symbols.items()]
78
79 printp(
80 f'{fn} is consistent with the following platform tag: "{winfo.overall_policy.name}".',
81 )
82
83 if winfo.pyfpe_policy == policies.linux:
84 printp(
85 "This wheel uses the PyFPE_jbuf function, which is not compatible with the"
86 " manylinux/musllinux tags. (see https://www.python.org/dev/peps/pep-0513/"
87 "#fpectl-builds-vs-no-fpectl-builds)",
88 )
89 if args.verbose < 1:
90 return 0
91
92 if winfo.ucs_policy == policies.linux:
93 printp(
94 "This wheel is compiled against a narrow unicode (UCS2) "
95 "version of Python, which is not compatible with the "
96 "manylinux/musllinux tags.",
97 )
98 if args.verbose < 1:
99 return 0
100
101 if winfo.machine_policy == policies.linux:
102 printp("This wheel depends on unsupported ISA extensions.")
103 if args.verbose < 1:
104 return 0
105
106 if len(libs_with_versions) == 0:
107 printp(
108 "The wheel references no external versioned symbols from "
109 "system-provided shared libraries.",
110 )
111 else:
112 printp(
113 "The wheel references external versioned symbols in these "
114 f"system-provided shared libraries: {', '.join(libs_with_versions)}",
115 )
116
117 if winfo.sym_policy < policies.highest:
118 printp(
119 f'This constrains the platform tag to "{winfo.sym_policy.name}". '
120 "In order to achieve a more compatible tag, you would "
121 "need to recompile a new wheel from source on a system "
122 "with earlier versions of these libraries, such as "
123 "a recent manylinux image.",
124 )
125 if args.verbose < 1:
126 return 0
127
128 libs = winfo.external_refs[policies.lowest.name].libs
129 if len(libs) == 0:
130 printp("The wheel requires no external shared libraries! :)")
131 else:
132 printp("The following external shared libraries are required by the wheel:")
133 print(json.dumps(dict(sorted(libs.items()))))
134
135 for p in policies:
136 if p > winfo.overall_policy:
137 libs = winfo.external_refs[p.name].libs
138 if len(libs):
139 printp(
140 f"In order to achieve the tag platform tag {p.name!r} "
141 "the following shared library dependencies "
142 "will need to be eliminated:",
143 )
144 printp(", ".join(sorted(libs.keys())))
145 blacklist = winfo.external_refs[p.name].blacklist
146 if len(blacklist):
147 printp(
148 f"In order to achieve the tag platform tag {p.name!r} "
149 "the following black-listed symbol dependencies "
150 "will need to be eliminated:",
151 )
152 for key in sorted(blacklist.keys()):
153 printp(f"From {key}: " + ", ".join(sorted(blacklist[key])))
154 return 0