Skip to content
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

Add --exclude option to delocate-wheel #106

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Releases

* [Unreleased]

* Dependencies can be manually excluded with the ``--exclude <name>`` flag.
[#106](https://github.com/matthew-brett/delocate/pull/106)

* [0.10.5] - 2023-11-14

* Fixed `UnicodeDecodeError` when an archive has non-ASCII characters.
Expand Down
29 changes: 29 additions & 0 deletions delocate/cmd/delocate_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
from typing import List, Optional, Text

from delocate import __version__, delocate_wheel
from delocate.delocating import filter_system_libs

logger = logging.getLogger(__name__)


def main() -> None:
Expand Down Expand Up @@ -64,6 +67,16 @@ def main() -> None:
action="store_true",
help="Only analyze files with known dynamic library extensions",
),
Option(
"-e",
"--exclude",
action="append",
default=[],
type="string",
help=(
"Exclude any libraries where path includes the given string"
),
),
Option(
"--require-archs",
action="store",
Expand Down Expand Up @@ -117,6 +130,21 @@ def main() -> None:
else:
require_archs = opts.require_archs
lib_filt_func = "dylibs-only" if opts.dylibs_only else None

exclude_files: List[str] = opts.exclude

def copy_filter_exclude(name: str) -> bool:
"""Returns False if name is excluded, uses normal rules otherwise."""
for exclude_str in exclude_files:
if exclude_str in name:
logger.info(
"%s excluded because of exclude %r rule.",
name,
exclude_str,
)
return False
return filter_system_libs(name)

for wheel in wheels:
if multi or opts.verbose:
print("Fixing: " + wheel)
Expand All @@ -129,6 +157,7 @@ def main() -> None:
out_wheel,
lib_filt_func=lib_filt_func,
lib_sdir=opts.lib_sdir,
copy_filt_func=copy_filter_exclude,
require_archs=require_archs,
executable_path=opts.executable_path,
ignore_missing=opts.ignore_missing_dependencies,
Expand Down
20 changes: 20 additions & 0 deletions delocate/tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,3 +574,23 @@ def test_add_platforms(script_runner: ScriptRunner) -> None:
assert sorted(os.listdir("wheels")) == res
assert_winfo_similar(local_out, EXTRA_EXPS)
assert_winfo_similar(local_out, EXTRA_EXPS)


@pytest.mark.xfail(sys.platform != "darwin", reason="Needs macOS linkage.")
def test_fix_wheel_with_excluded_dylibs(script_runner: ScriptRunner):
with InTemporaryDirectory() as tmpdir:
fixed_wheel, stray_lib = _fixed_wheel(tmpdir)
_rename_module(fixed_wheel, "module.other", "test.whl")
shutil.copyfile("test.whl", "test2.whl")
# We exclude the stray library so it shouldn't be present in the wheel
result = script_runner.run(
["delocate-wheel", "-vv", "-e", "extfunc", "test.whl"], check=True
)
assert "libextfunc.dylib excluded" in result.stderr
with InWheel("test.whl"):
assert not Path("plat_pkg/fakepkg1/.dylibs").exists()
# We exclude a library that does not exist so we should behave normally
script_runner.run(
["delocate-wheel", "-e", "doesnotexist", "test2.whl"], check=True
)
_check_wheel("test2.whl", ".dylibs")