-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-87414: add musl support to platform.libc_ver #103784
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
051e8f2
bpo-43248: add musl support to platform.libc_ver
cmaureir 625330a
Remove typehints and the MuslVersion structure
cmaureir 65d0bd8
Merge branch 'main' into musl_libc_ver
ambv c630633
The relative import is not valid
humitos 1a10966
Remove typing annotations from `_elffile.py`
humitos ee37ed7
Remove unused classes from `_elffile.py`
humitos e945a5d
Move ELFFile class from its own module to `platform.py`
humitos 8a3f515
Add some tests for ELFFile class and musl functions
humitos 18420f9
Add `@support.requires_musl` decorator to skip tests if needed
humitos 76550e7
Add `NEWS.d` entry
humitos 05ed7a2
Merge branch 'main' into musl_libc_ver
cmaureir 4216858
Adapt latest comments from review
cmaureir 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import io | ||
import os | ||
import copy | ||
import pickle | ||
|
@@ -68,6 +69,9 @@ | |
""" | ||
|
||
|
||
ELFFILE_HEADER = b"\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00" | ||
|
||
|
||
class PlatformTest(unittest.TestCase): | ||
def clear_caches(self): | ||
platform._platform_cache.clear() | ||
|
@@ -538,6 +542,49 @@ def test_parse_os_release(self): | |
self.assertEqual(info, expected) | ||
self.assertEqual(len(info["SPECIALS"]), 5) | ||
|
||
def test_parse_musl_version(self): | ||
output = """\ | ||
musl libc (x86_64) | ||
Version 1.2.3 | ||
Dynamic Program Loader | ||
Usage: /lib/ld-musl-x86_64.so.1 [options] [--] pathname [args] | ||
""" | ||
self.assertEqual(platform._parse_musl_version(output), "1.2") | ||
|
||
@support.requires_subprocess() | ||
@support.requires_musl() | ||
def test_libc_ver_musl(self): | ||
self.assertEqual(platform.libc_ver(), ("musl", "1.2")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this always be 1.2? |
||
|
||
|
||
@support.requires_musl() | ||
class ELFFileTest(unittest.TestCase): | ||
|
||
def test_get_interpreter(self): | ||
with open(sys.executable, "rb") as f: | ||
elffile = platform.ELFFile(f) | ||
self.assertEqual(elffile.interpreter, "/lib/ld-musl-x86_64.so.1") | ||
|
||
def test_init_invalid_magic(self): | ||
BAD_ELFFILE_HEADER = b"\x7fBAD\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00" | ||
f = io.BytesIO(BAD_ELFFILE_HEADER) | ||
self.assertRaisesRegex( | ||
platform.ELFInvalid, | ||
"invalid magic:", | ||
platform.ELFFile, | ||
f, | ||
) | ||
|
||
def test_init_parse_error(self): | ||
EMPTY_ELF_HEADER = b"\x00" | ||
f = io.BytesIO(EMPTY_ELF_HEADER) | ||
self.assertRaisesRegex( | ||
platform.ELFInvalid, | ||
"unable to parse identification", | ||
platform.ELFFile, | ||
f, | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2023-04-28-15-01-07.gh-issue-87414.r6fYP1.rst
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 @@ | ||
Add musl support to ``platform.libc_ver`` function. |
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.