Skip to content
Open
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
13 changes: 11 additions & 2 deletions src/auditwheel/lddtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,17 @@ def load_ld_paths(
"""
ldpaths: dict[str, list[str]] = {"conf": [], "env": [], "interp": []}

# Load up $LD_LIBRARY_PATH.
env_ldpath = os.environ.get("LD_LIBRARY_PATH")
# Load up $AUDITWHEEL_LD_LIBRARY_PATH and $LD_LIBRARY_PATH
env_ldpath = ":".join(
filter(
None,
(
os.environ.get("AUDITWHEEL_LD_LIBRARY_PATH"),
os.environ.get("LD_LIBRARY_PATH"),
),
)
)

if env_ldpath is not None:
Copy link
Preview

Copilot AI Jul 6, 2025

Choose a reason for hiding this comment

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

Using env_ldpath is not None means an empty string from no vars still enters the block. Change to if env_ldpath: to skip when both variables are unset.

Suggested change
if env_ldpath is not None:
if env_ldpath:

Copilot uses AI. Check for mistakes.

if root != "/":
log.warning("ignoring LD_LIBRARY_PATH due to ROOT usage")
Expand Down
43 changes: 31 additions & 12 deletions tests/integration/test_bundled_wheels.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from __future__ import annotations

import importlib
import os
import platform
import sys
import zipfile
from argparse import Namespace
from datetime import datetime, timezone
from os.path import isabs
from pathlib import Path
from unittest.mock import Mock

import pytest

import auditwheel.wheel_abi
from auditwheel import lddtree, main_repair
from auditwheel.architecture import Architecture
from auditwheel.libc import Libc
Expand All @@ -23,70 +22,90 @@


@pytest.mark.parametrize(
("file", "external_libs", "exclude"),
("file", "external_libs", "exclude", "env"),
[
(
"cffi-1.5.0-cp27-none-linux_x86_64.whl",
{"libffi.so.5", "libpython2.7.so.1.0"},
frozenset(),
None,
),
(
"cffi-1.5.0-cp27-none-linux_x86_64.whl",
set(),
frozenset(["libffi.so.5", "libpython2.7.so.1.0"]),
None,
),
(
"cffi-1.5.0-cp27-none-linux_x86_64.whl",
{"libffi.so.5", "libpython2.7.so.1.0"},
frozenset(["libffi.so.noexist", "libnoexist.so.*"]),
None,
),
(
"cffi-1.5.0-cp27-none-linux_x86_64.whl",
{"libpython2.7.so.1.0"},
frozenset(["libffi.so.[4,5]"]),
None,
),
(
"cffi-1.5.0-cp27-none-linux_x86_64.whl",
{"libffi.so.5", "libpython2.7.so.1.0"},
frozenset(["libffi.so.[6,7]"]),
None,
),
(
"cffi-1.5.0-cp27-none-linux_x86_64.whl",
{"libpython2.7.so.1.0"},
frozenset([f"{HERE}/*"]),
"LD_LIBRARY_PATH",
),
(
"cffi-1.5.0-cp27-none-linux_x86_64.whl",
{"libpython2.7.so.1.0"},
frozenset([f"{HERE}/*"]),
"AUDITWHEEL_LD_LIBRARY_PATH",
),
(
"cffi-1.5.0-cp27-none-linux_x86_64.whl",
{"libffi.so.5", "libpython2.7.so.1.0"},
frozenset([f"{HERE}/*"]),
None,
),
(
"cffi-1.5.0-cp27-none-linux_x86_64.whl",
{"libpython2.7.so.1.0"},
frozenset(["libffi.so.*"]),
None,
),
("cffi-1.5.0-cp27-none-linux_x86_64.whl", set(), frozenset(["*"])),
("cffi-1.5.0-cp27-none-linux_x86_64.whl", set(), frozenset(["*"]), None),
(
"python_snappy-0.5.2-pp260-pypy_41-linux_x86_64.whl",
{"libsnappy.so.1"},
frozenset(),
None,
),
],
)
def test_analyze_wheel_abi(file, external_libs, exclude):
def test_analyze_wheel_abi(file, external_libs, exclude, env):
# If exclude libs contain path, LD_LIBRARY_PATH need to be modified to find the libs
# `lddtree.load_ld_paths` needs to be reloaded for it's `lru_cache`-ed.
modify_ld_library_path = any(isabs(e) for e in exclude)

with pytest.MonkeyPatch.context() as cp:
if modify_ld_library_path:
cp.setenv("LD_LIBRARY_PATH", f"{HERE}")
importlib.reload(lddtree)
if env:
cp.setenv(env, f"{HERE}")
importlib.reload(lddtree)
importlib.reload(auditwheel.wheel_abi)

winfo = analyze_wheel_abi(
Libc.GLIBC, Architecture.x86_64, HERE / file, exclude, False, True
)
assert set(winfo.external_refs["manylinux_2_5_x86_64"].libs) == external_libs, (
f"{HERE}, {exclude}, {os.environ}"
f"{HERE}, {exclude}, {env}"
)

if modify_ld_library_path:
importlib.reload(lddtree)
importlib.reload(lddtree)
importlib.reload(auditwheel.wheel_abi)


def test_analyze_wheel_abi_pyfpe():
Expand Down