Skip to content

feat: add --json output flag to auditwheel show#685

Open
lcarva wants to merge 3 commits into
pypa:mainfrom
lcarva:show-json
Open

feat: add --json output flag to auditwheel show#685
lcarva wants to merge 3 commits into
pypa:mainfrom
lcarva:show-json

Conversation

@lcarva
Copy link
Copy Markdown
Contributor

@lcarva lcarva commented Mar 27, 2026

Enable scripting by adding a --json flag that outputs structured JSON instead of human-readable text, including wheel tag, compatibility flags, versioned symbols, external libs, and policy upgrade info.

Copy link
Copy Markdown
Member

@mayeut mayeut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not reviewed thoroughly yet but left a couple comments inlined in addition to the following more general comment.

Per #676 (comment), as the json output should be an "API", it should be versioned, and, ideally, we might want to have a json schema for this.

Comment thread src/auditwheel/main_show.py Outdated
Comment thread .pre-commit-config.yaml Outdated
@mayeut
Copy link
Copy Markdown
Member

mayeut commented Mar 28, 2026

While this does not cover all functionality requested in #676, it does solve one of them so linking here.

Comment thread src/auditwheel/main_show.py Outdated
)
except NonPlatformWheelError as e:
logger.info("%s", e.message)
if args.JSON:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if handling this special json case is important. Also, the case below where pure wheels are allowed does not emit a json. What's the preference?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the preference?

If adding this, let's try to add it properly.
If pure wheels are allowed then we should not error but output a specific json output for pure wheels, e.g. the schema could have something like:

  "oneOf": [
    { "$ref": "#/$defs/result_pure" },
    { "$ref": "#/$defs/result_platform" },
    { "$ref": "#/$defs/error" }
  ],

adding a "pure" boolean property that's always true for result_pure and always false for result_platform

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good idea! Implemented that approach. (I also removed the unnecessary .. import json which already happens earlier in this function.)

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.79%. Comparing base (b10e60c) to head (29ada8a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #685      +/-   ##
==========================================
+ Coverage   95.73%   95.79%   +0.06%     
==========================================
  Files          23       23              
  Lines        1923     1952      +29     
  Branches      362      371       +9     
==========================================
+ Hits         1841     1870      +29     
  Misses         46       46              
  Partials       36       36              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lcarva
Copy link
Copy Markdown
Contributor Author

lcarva commented Apr 20, 2026

@mayeut, please let me know if there's something I can do to help move this work forward (assuming that there is an interest in doing so.)

@mayeut
Copy link
Copy Markdown
Member

mayeut commented Apr 25, 2026

@lcarva, there's still interest however I'd like to get a couple fixes & the android support so it might take a bit of time before this can be reviewed again.

Enable scripting by adding a --json flag that outputs structured JSON
instead of human-readable text, including wheel tag, compatibility
flags, versioned symbols, external libs, and policy upgrade info.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds machine-readable output support for auditwheel show via a new --json flag and validates the new output shape with unit tests and a JSON schema.

Changes:

  • Adds --json parsing and JSON output paths in main_show.py.
  • Adds show-schema.json describing pure, platform, and error outputs.
  • Adds unit tests for JSON output variants and updates mypy pre-commit deps for jsonschema typing.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/auditwheel/main_show.py Adds JSON output generation and --json CLI flag handling.
src/auditwheel/show-schema.json Defines the structured output schema for auditwheel show --json.
tests/unit/test_main_show.py Adds unit coverage for JSON output, schema validation, and pure/non-platform wheel behavior.
.pre-commit-config.yaml Adds types-jsonschema for mypy support.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +21 to +27
p.add_argument(
"--json",
dest="JSON",
action="store_true",
default=False,
help="Output results in JSON format",
)
@tonisbones
Copy link
Copy Markdown

Would love to see this PR get merged :)

mayeut added 2 commits May 23, 2026 13:37
When --json is requested and the specified wheel file does not exist, print a JSON error object (with version, wheel name, and error message) and return exit code 1 instead of invoking parser.error. Update the unit test to capture stdout, assert the return value is 1, and validate the emitted JSON contains the expected fields and message.
Add static type annotations to tests/unit/test_main_show.py: import Callable and annotate fixture and helper signatures (tmp_path: Path, capsys: pytest.CaptureFixture[str], patch_wheel_abi: Callable[..., None], monkeypatch: pytest.MonkeyPatch, etc.), add return types and parameter types for helper functions and the internal _set function. Purely typing refinements with no behavioral changes.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment on lines +74 to +86
policies = _FakePolicies()

external_refs = {
LINUX.name: SimpleNamespace(
libs=external_libs or {},
blacklist={},
),
MANYLINUX_2_17.name: SimpleNamespace(libs={}, blacklist={}),
MANYLINUX_2_28.name: SimpleNamespace(
libs=policy_upgrades_libs or {},
blacklist=policy_upgrades_blacklist or {},
),
}
Comment on lines +16 to +17
_SCHEMA_PATH = Path(__file__).resolve().parents[2] / "src" / "auditwheel" / "show-schema.json"
_SCHEMA = json.loads(_SCHEMA_PATH.read_text())
Comment on lines +54 to +61
class _FakePolicies:
linux = LINUX
lowest = LINUX
highest = MANYLINUX_2_28

def __iter__(self) -> Iterator[_FakePolicy]:
return iter(ALL_POLICIES)

@mayeut mayeut mentioned this pull request May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants