-
Notifications
You must be signed in to change notification settings - Fork 309
Audit - general approach to auditing wheels with abi3audit default #2805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joerick
wants to merge
50
commits into
main
Choose a base branch
from
audit2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
619e1dc
WIP - initial punt at audit command
joerick 322f2c4
Add `abi3audit` as a dependency
agriyakhetarpal f917a24
Add helper functions to check stable ABI wheels
agriyakhetarpal f2fdc93
Run `abi3audit` for macOS and Windows wheels
agriyakhetarpal 1054219
Copy out of container for repairing?
agriyakhetarpal 03d1708
Add some notes that `cibuildwheel` runs `abi3audit`
agriyakhetarpal 97cc3c2
Add basic unit tests
agriyakhetarpal 97b6d51
Add a basic C extension with `Py_LIMITED_API`
agriyakhetarpal 87ac303
Add a test project that violates Stable ABI
agriyakhetarpal babfb13
Fix linux test
agriyakhetarpal 8d6988d
Skip abi3 wheel tests for Pyodide
agriyakhetarpal 6e9c281
Patch the correct subprocess module
agriyakhetarpal 597f061
wrap cleanup of abi3audit dir
agriyakhetarpal a8ee2e5
Merge branch 'audit' into audit2
joerick 91c394f
Write the docs for the new options
joerick 77f571d
Merge remote-tracking branch 'origin/main' into audit2
joerick e4c7164
Move to above testing in docs
joerick 4f3250d
Implement audit-requires and audit-command
joerick 46ce64a
Some cleanups after self-review
joerick 678d8f5
Add default value
joerick 08330a4
fix type errors
joerick d145df6
the key is `audit-command`, not `audit`
agriyakhetarpal ba25da0
Add a variety of tests for audit requires options
agriyakhetarpal 80b6529
Add `test_audit_requires` similar to `test_test_requires`
agriyakhetarpal 86d8f9a
Merge branch 'main' into audit2
agriyakhetarpal d65a33a
Add some configurability-related audit tests
agriyakhetarpal c53eb6b
Fix parsing error with options docs leaving out commands
agriyakhetarpal 6c20ebc
Better way to extract version (maybe helps Pyodide?)
agriyakhetarpal 7b1d688
Fix a case of unbound `use_uv`
agriyakhetarpal b95caa6
Standardise: rename to `abi3_wheel`
agriyakhetarpal 7886e96
Fix audit command run message
agriyakhetarpal f7d9ccb
Simplify custom audit command a bit
agriyakhetarpal 672299b
Remove unnecessary skip for Pyodide
agriyakhetarpal b791437
Pyodide should have no default audit command
agriyakhetarpal dc354e0
More accurate skip messages for Pyodide skips
agriyakhetarpal e745612
Wheels are audited after they are repaired
agriyakhetarpal ab87881
Regenerate constraints to include `abi3audit`
agriyakhetarpal 389c580
Fix typos
agriyakhetarpal d80ed3b
Some attempts for Windows fixes
agriyakhetarpal 5bcd54c
Check `pyvenv.cfg` instead of directory existence
agriyakhetarpal 7168365
Add validation for lack of wheel placeholders
agriyakhetarpal 45e8825
Try yet another Windows `uv` fix
agriyakhetarpal 6bdb9d7
Regenerate diagram and re-trigger Azure CI
agriyakhetarpal 55bea88
Add missing `import sys` for abi3 C extension tests
agriyakhetarpal 854ee13
Remove audit-command at the global level
agriyakhetarpal e3c3b01
Clarify `abi3audit` pinning a little bit
agriyakhetarpal 6283752
Merge main
agriyakhetarpal dcb4cbb
Regen constraints
agriyakhetarpal cb81bd4
Discard changes to cibuildwheel/resources/constraints-pyodide312.txt
agriyakhetarpal 7cfec02
Discard changes to cibuildwheel/resources/constraints-pyodide313.txt
agriyakhetarpal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| from cibuildwheel import errors | ||
| from cibuildwheel.logger import log | ||
| from cibuildwheel.options import BuildOptions | ||
| from cibuildwheel.util.cmd import call, shell | ||
| from cibuildwheel.util.helpers import prepare_command | ||
| from cibuildwheel.util.packaging import is_abi3_wheel | ||
| from cibuildwheel.venv import activate_virtualenv, find_uv, virtualenv | ||
|
|
||
|
|
||
| def run_audit( | ||
| *, | ||
| tmp_dir: Path, | ||
| build_options: BuildOptions, | ||
| wheel: Path, | ||
| ) -> None: | ||
| """ | ||
| Run the audit commands on a single wheel. | ||
|
|
||
| Creates a virtualenv (or reuses an existing one) and installs any | ||
| audit requirements, then runs each audit command template against | ||
| the wheel. Commands containing {abi3_wheel} are skipped for | ||
| non-abi3 wheels. | ||
| """ | ||
|
|
||
| if not needs_audit(build_options.audit_command, wheel.name): | ||
| return | ||
|
|
||
| log.step("Auditing wheel...") | ||
|
|
||
| use_uv = find_uv() is not None | ||
| version = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}" | ||
| dependency_constraint = build_options.dependency_constraints.get_for_python_version( | ||
| version=version, tmp_dir=tmp_dir | ||
| ) | ||
|
|
||
| audit_venv_dir = tmp_dir / "audit_venv" | ||
| if not (audit_venv_dir / "pyvenv.cfg").exists(): | ||
| env = virtualenv( | ||
| version, | ||
| Path(sys.executable), | ||
| audit_venv_dir, | ||
| dependency_constraint=dependency_constraint, | ||
| use_uv=use_uv, | ||
| ) | ||
| else: | ||
| env = activate_virtualenv(audit_venv_dir) | ||
|
agriyakhetarpal marked this conversation as resolved.
|
||
|
|
||
| # install audit requirements. This is run every time in case the user has | ||
| # defined overrides. | ||
| audit_requires = build_options.audit_requires | ||
| if audit_requires: | ||
| print(f"Installing audit dependencies: {', '.join(audit_requires)}") | ||
|
|
||
| pip: list[str] | ||
| if use_uv: | ||
| uv_path = find_uv() | ||
| assert uv_path is not None | ||
| pip = [str(uv_path), "pip"] | ||
| else: | ||
| pip = ["pip"] | ||
| # we pin if the audit-requires is left as the default "abi3audit" | ||
| should_pin = audit_requires == ["abi3audit"] and dependency_constraint | ||
|
|
||
| call( | ||
| *pip, | ||
| "install", | ||
| *(["--constraint", str(dependency_constraint)] if should_pin else []), | ||
| *audit_requires, | ||
| env=env, | ||
| ) | ||
|
|
||
| audit_command = build_options.audit_command | ||
|
|
||
| for command_template in audit_command: | ||
| if "{abi3_wheel}" in command_template and "{wheel}" in command_template: | ||
| msg = ( | ||
| f"Invalid audit command {command_template!r}: cannot contain both {{abi3_wheel}} " | ||
| "and {{wheel}} placeholders" | ||
| ) | ||
| raise errors.ConfigurationError(msg) | ||
|
|
||
| if "{abi3_wheel}" in command_template and not is_abi3_wheel(wheel.name): | ||
| continue | ||
|
agriyakhetarpal marked this conversation as resolved.
|
||
|
|
||
| prepared_command = prepare_command( | ||
| command_template, | ||
| abi3_wheel=wheel, | ||
| wheel=wheel, | ||
| project=".", | ||
| package=build_options.package_dir, | ||
| ) | ||
|
|
||
| print(f"Running audit command: {prepared_command}") | ||
| try: | ||
| shell(prepared_command, env=env) | ||
| except subprocess.CalledProcessError as e: | ||
| print(f"Audit command failed with exit code {e.returncode}") | ||
| msg = f"Audit command failed: {prepared_command}" | ||
| raise errors.AuditCommandFailedError(msg) from e | ||
|
|
||
|
|
||
| def needs_audit(audit_commands: list[str], wheel_name: str) -> bool: | ||
| saw_abi3_placeholder = False | ||
| for audit_command in audit_commands: | ||
| if "{abi3_wheel}" not in audit_command and "{wheel}" not in audit_command: | ||
| msg = ( | ||
| f"Invalid audit command {audit_command!r}: must contain either " | ||
| "{{abi3_wheel}} or {{wheel}} placeholder" | ||
| ) | ||
| raise errors.ConfigurationError(msg) | ||
|
|
||
| if "{abi3_wheel}" in audit_command: | ||
| saw_abi3_placeholder = True | ||
| if is_abi3_wheel(wheel_name): | ||
| return True | ||
| elif "{wheel}" in audit_command: | ||
| return True | ||
|
|
||
| if saw_abi3_placeholder: | ||
| print("No audit required for this wheel, as it is not abi3") | ||
| else: | ||
| print("No audit configured") | ||
|
|
||
| return False | ||
|
agriyakhetarpal marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.