Skip to content

[3.13] gh-131032: Add support.linked_to_musl() function (#131071) #131179

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 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2767,3 +2767,22 @@ def __iter__(self):
if self.iter_raises:
1/0
return self


def linked_to_musl():
"""
Test if the Python executable is linked to the musl C library.
"""
if sys.platform != 'linux':
return False

import subprocess
exe = getattr(sys, '_base_executable', sys.executable)
cmd = ['ldd', exe]
try:
stdout = subprocess.check_output(cmd,
text=True,
stderr=subprocess.STDOUT)
except (OSError, subprocess.CalledProcessError):
return False
return ('musl' in stdout)
5 changes: 3 additions & 2 deletions Lib/test/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -2712,8 +2712,9 @@ def test_fma_infinities(self):
# gh-73468: On some platforms, libc fma() doesn't implement IEE 754-2008
# properly: it doesn't use the right sign when the result is zero.
@unittest.skipIf(
sys.platform.startswith(("freebsd", "wasi", "netbsd"))
or (sys.platform == "android" and platform.machine() == "x86_64"),
sys.platform.startswith(("freebsd", "wasi", "netbsd", "emscripten"))
or (sys.platform == "android" and platform.machine() == "x86_64")
or support.linked_to_musl(), # gh-131032
f"this platform doesn't implement IEE 754-2008 properly")
def test_fma_zero_result(self):
nonnegative_finites = [0.0, 1e-300, 2.3, 1e300]
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,10 @@ def test_copy_python_src_ignore(self):
self.assertEqual(support.copy_python_src_ignore(path, os.listdir(path)),
ignored)

def test_linked_to_musl(self):
linked = support.linked_to_musl()
self.assertIsInstance(linked, bool)

# XXX -follows a list of untested API
# make_legacy_pyc
# is_resource_enabled
Expand Down
Loading