Skip to content

Commit

Permalink
cli: Render both mismatches and violations in the same table
Browse files Browse the repository at this point in the history
Previously, when violations were found (i.e. non-ABI3 symbols in an ABI3-tagged
extension), any subsequent version mismatches (i.e. using symbols that were made
part of the stable ABI, but in later versions than the provided wheel was built for),
were left unreported.

This is now fixed, by changing the audit rendering hook to include all offending
symbols and their ABI versions. In case of a violation, the "not ABI3" value is
given as ABI version, to clearly signal that the found symbol is not part of any
version of the stable ABI.
  • Loading branch information
nicholasjng committed Jan 6, 2025
1 parent cd1bf56 commit be9369f
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions abi3audit/_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,30 @@ def __bool__(self) -> bool:
return self.is_abi3() and self.is_abi3_baseline_compatible()

def __rich_console__(self, console: Console, options: ConsoleOptions) -> RenderResult:
# Violating abi3 entirely is more "serious" than having the wrong abi3
# version, so we check for it first when deciding the Rich representation.
if self.non_abi3_symbols:
yield f"[red]:thumbs_down: [green]{self.so}[/green] has non-ABI3 symbols"
"""
The rich representation of an audit result.
table = Table()
table.add_column("Symbol")
for sym in self.non_abi3_symbols:
table.add_row(sym.name)

yield table
elif self.computed > self.baseline:
yield (
f"[yellow]:thumbs_down: [green]{self.so}[/green] uses the Python "
f"[blue]{self.computed}[/blue] ABI, but is tagged for the Python "
f"[red]{self.baseline}[/red] ABI"
)
If problems are found, renders a table of ABI3 violations/mismatches with
the name and ABI3 version (or a "not ABI3" marker) of each offending symbol.
If no problems are found, renders a short "OK" message.
"""
has_violations = self.non_abi3_symbols or self.computed > self.baseline
if has_violations:
table = Table()
table.add_column("Symbol")
table.add_column("Version")

if self.non_abi3_symbols:
yield f"[red]:thumbs_down: [green]{self.so}[/green] has non-ABI3 symbols"
if self.computed > self.baseline:
yield (
f"[yellow]:thumbs_down: [green]{self.so}[/green] uses the Python "
f"[blue]{self.computed}[/blue] ABI, but is tagged for the Python "
f"[red]{self.baseline}[/red] ABI"
)
for sym in self.non_abi3_symbols:
table.add_row(sym.name, "not ABI3")
for obj in self.future_abi3_objects:
table.add_row(obj.symbol.name, str(obj.added))
yield table
Expand Down

0 comments on commit be9369f

Please sign in to comment.