-
Notifications
You must be signed in to change notification settings - Fork 25
Add the kernels check subcommand
#158
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
Merged
Merged
Changes from all commits
Commits
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
Some comments aren't visible on the classic Files Changed page.
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
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,27 @@ | ||
| { | ||
| buildPythonPackage, | ||
| fetchPypi, | ||
| rustPlatform, | ||
| }: | ||
|
|
||
| buildPythonPackage rec { | ||
| pname = "kernel-abi-check"; | ||
| version = "0.6.2"; | ||
|
|
||
| src = fetchPypi { | ||
| inherit version; | ||
| pname = "kernel_abi_check"; | ||
| hash = "sha256-goWC7SK79FVNEvkp3bISBwbOqdSrmobANtrWIve9/Ys="; | ||
| }; | ||
|
|
||
| cargoDeps = rustPlatform.fetchCargoVendor { | ||
| inherit pname version src sourceRoot; | ||
| hash = "sha256-+1jdbKsDKmG+bf0NEVYMv8t7Meuge1z2cgYfbdB9q8A="; | ||
| }; | ||
|
|
||
| sourceRoot = "kernel_abi_check-${version}/bindings/python"; | ||
|
|
||
| pyproject = true; | ||
|
|
||
| nativeBuildInputs = with rustPlatform; [ cargoSetupHook maturinBuildHook ]; | ||
| } | ||
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,141 @@ | ||
| from pathlib import Path | ||
| import sys | ||
|
|
||
| from huggingface_hub import snapshot_download | ||
| from kernels.utils import CACHE_DIR | ||
| from kernel_abi_check import ( | ||
| BinaryFormat, | ||
| IncompatibleMacOSVersion, | ||
| ObjectFile, | ||
| IncompatibleAbi3Symbol, | ||
| NonAbi3Symbol, | ||
| IncompatibleManylinuxSymbol, | ||
| MissingMacOSVersion, | ||
| ) | ||
|
|
||
|
|
||
| def check_kernel( | ||
| *, macos: str, manylinux: str, python_abi: str, repo_id: str, revision: str | ||
| ): | ||
| variants_path = ( | ||
| Path( | ||
| snapshot_download( | ||
| repo_id, | ||
| allow_patterns=["build/*"], | ||
| cache_dir=CACHE_DIR, | ||
| revision=revision, | ||
| ) | ||
| ) | ||
| / "build" | ||
| ) | ||
|
|
||
| has_issues = False | ||
| for variant_path in variants_path.iterdir(): | ||
| if not variant_path.is_dir(): | ||
| print( | ||
| f"⛔ `build/` must only contain directories, found: {variant_path.name}", | ||
| file=sys.stderr, | ||
| ) | ||
| has_issues = True | ||
| continue | ||
|
|
||
| print(f"Checking variant: {variant_path.name}", file=sys.stderr) | ||
|
|
||
| indent = 2 | ||
|
|
||
| for dylib_path in variant_path.rglob("*.so"): | ||
| print_with_indent( | ||
| indent, | ||
| f"Dynamic library {dylib_path.relative_to(variant_path)}:", | ||
| ) | ||
|
|
||
| o = ObjectFile(dylib_path) | ||
| has_issues |= check_abi3(o, python_abi, indent + 2) | ||
|
|
||
| # TODO: also check operating system | ||
| if o.format() == BinaryFormat.ELF: | ||
| has_issues |= check_manylinux(o, manylinux, indent + 2) | ||
| elif o.format() == BinaryFormat.MACH_O: | ||
| has_issues |= check_macos(o, macos, indent + 2) | ||
|
|
||
| if has_issues: | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| def check_abi3(object_file: ObjectFile, python_abi: str, indent: int) -> bool: | ||
| has_issues = False | ||
| violations = object_file.check_python_abi(python_abi) | ||
| if violations != []: | ||
| has_issues = True | ||
| print_with_indent( | ||
| indent, | ||
| f"⛔ Found symbols that are incompatible with Python ABI {python_abi}:", | ||
| ) | ||
| for violation in violations: | ||
| if isinstance(violation, IncompatibleAbi3Symbol): | ||
| print_with_indent( | ||
| indent + 3, | ||
| f"{violation.name}: {violation.version_added}", | ||
| ) | ||
| elif isinstance(violation, NonAbi3Symbol): | ||
| print_with_indent( | ||
| indent + 3, | ||
| f"{violation.name}", | ||
| ) | ||
| else: | ||
| print_with_indent(indent, f"🐍 Python ABI {python_abi} compatible") | ||
|
|
||
| return has_issues | ||
|
|
||
|
|
||
| def check_macos(object_file: ObjectFile, macos: str, indent: int) -> bool: | ||
| has_issues = False | ||
| violations = object_file.check_macos(macos) | ||
| if violations != []: | ||
| has_issues = True | ||
| print_with_indent( | ||
| indent, | ||
| f"⛔ Found incompatibility with macOS {macos}:", | ||
| ) | ||
|
|
||
| for violation in violations: | ||
| if isinstance(violation, MissingMacOSVersion): | ||
| print_with_indent( | ||
| indent + 3, | ||
| "shared library does not contain macOS version", | ||
| ) | ||
| elif isinstance(violation, IncompatibleMacOSVersion): | ||
| print_with_indent( | ||
| indent + 3, | ||
| f"shared library requires macOS {violation.version}", | ||
| ) | ||
| else: | ||
| print_with_indent(indent, f"🍏 compatible with macOS {macos}") | ||
|
|
||
| return has_issues | ||
|
|
||
|
|
||
| def check_manylinux(object_file: ObjectFile, manylinux: str, indent: int) -> bool: | ||
| has_issues = False | ||
| violations = object_file.check_manylinux(manylinux) | ||
| if violations != []: | ||
| has_issues = True | ||
| print_with_indent( | ||
| indent, | ||
| f"⛔ Found symbols that are incompatible with {manylinux}:", | ||
| ) | ||
|
|
||
| for violation in violations: | ||
| if isinstance(violation, IncompatibleManylinuxSymbol): | ||
| print_with_indent( | ||
| indent + 3, | ||
| f"{violation.name}_{violation.dep}: {violation.version}", | ||
| ) | ||
| else: | ||
| print_with_indent(indent, f"🐧 {manylinux} compatible") | ||
|
|
||
| return has_issues | ||
|
|
||
|
|
||
| def print_with_indent(indent: int, message: str): | ||
| print(f"{' ' * indent}{message}", file=sys.stderr) |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean we can't install
kernelswithout installingkernel-abi-check?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an optional dependency in
pyproject.toml. The Nix is for the project's devshell, where we always want to have the package available.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect !