From 1af49a8d55adaf62f292dcf08a3d9a88e9927482 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Fri, 10 May 2024 22:30:18 -0500 Subject: [PATCH 1/2] fix string formatting in error message --- delocate/delocating.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/delocate/delocating.py b/delocate/delocating.py index 6e540bac..8596a55d 100644 --- a/delocate/delocating.py +++ b/delocate/delocating.py @@ -992,7 +992,7 @@ def delocate_wheel( ) if copied_libs and lib_path_exists_before_delocate: raise DelocationError( - "f{lib_path} already exists in wheel but need to copy " + f"{lib_path} already exists in wheel but need to copy " + "; ".join(copied_libs) ) if len(os.listdir(lib_path)) == 0: From e4c8b6477815634e87aa08f401f6ece5d95ec8a2 Mon Sep 17 00:00:00 2001 From: Kyle Benesch <4b796c65+github@gmail.com> Date: Fri, 7 Jun 2024 01:41:54 -0700 Subject: [PATCH 2/2] Add changelog item and add tests for DelocationError --- Changelog.md | 6 ++++++ delocate/tests/test_delocating.py | 15 +++++++++++--- delocate/tests/test_libsana.py | 4 +++- delocate/tests/test_wheelies.py | 34 +++++++++++++++---------------- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/Changelog.md b/Changelog.md index a9b4644a..f2f32c0d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -21,6 +21,12 @@ rules on making a good Changelog. version to `delocate==0.11.0`. [#215](https://github.com/matthew-brett/delocate/pull/215) +### Fixed + +- Existing libraries causing DelocationError were not shown due to bad string + formatting. + [#216](https://github.com/matthew-brett/delocate/pull/216) + ## [0.11.0] - 2024-03-22 ### Added diff --git a/delocate/tests/test_delocating.py b/delocate/tests/test_delocating.py index 2ea0f3ee..7a565c7a 100644 --- a/delocate/tests/test_delocating.py +++ b/delocate/tests/test_delocating.py @@ -114,7 +114,9 @@ def test_delocate_tree_libs( sys_lib = EXT_LIBS[0] lib_dict = without_system_libs(tree_libs_func(subtree)) lib_dict.update({"/unlikely/libname.dylib": {}}) - with pytest.raises(DelocationError): + with pytest.raises( + DelocationError, match=r".*/unlikely/libname.dylib.*does not exist" + ): delocate_tree_libs(lib_dict, copy_dir, subtree) lib_dict = without_system_libs(tree_libs_func(subtree)) @@ -171,7 +173,11 @@ def test_delocate_tree_libs( # out-of-tree will raise an error because of duplicate library names # (libc and slibc both named /libc.dylib) lib_dict2 = without_system_libs(tree_libs_func(subtree2)) - with pytest.raises(DelocationError): + with pytest.raises( + DelocationError, + match=r"Already planning to copy library with same basename as: " + r"libc.dylib", + ): delocate_tree_libs(lib_dict2, copy_dir2, "/fictional") # Rename a library to make this work new_slibc = pjoin(dirname(slibc), "libc2.dylib") @@ -365,7 +371,10 @@ def filt_func(libname: Text) -> bool: shutil.copy2(libb, "subtree") # If liba is already present, barf shutil.copy2(liba, "subtree") - assert_raises(DelocationError, copy_recurse, "subtree", filt_func) + with pytest.raises( + DelocationError, match=r".*liba.dylib .*already exists" + ): + copy_recurse("subtree", filt_func) # Works if liba not present os.unlink(pjoin("subtree", "liba.dylib")) copy_recurse("subtree", filt_func) diff --git a/delocate/tests/test_libsana.py b/delocate/tests/test_libsana.py index 60c178e8..037671bd 100644 --- a/delocate/tests/test_libsana.py +++ b/delocate/tests/test_libsana.py @@ -463,7 +463,9 @@ def test_wheel_libs_ignore_missing() -> None: # Test wheel_libs ignore_missing parameter. with InTemporaryDirectory() as tmpdir: shutil.copy(RPATH_WHEEL, pjoin(tmpdir, "rpath.whl")) - with pytest.raises(DelocationError): + with pytest.raises( + DelocationError, match=r"Could not find all dependencies." + ): wheel_libs("rpath.whl") wheel_libs("rpath.whl", ignore_missing=True) diff --git a/delocate/tests/test_wheelies.py b/delocate/tests/test_wheelies.py index cd60b068..bb080ace 100644 --- a/delocate/tests/test_wheelies.py +++ b/delocate/tests/test_wheelies.py @@ -34,7 +34,7 @@ ) from ..wheeltools import InWheel from .env_tools import _scope_env -from .pytest_tools import assert_equal, assert_false, assert_raises, assert_true +from .pytest_tools import assert_equal, assert_false, assert_true from .test_install_names import DATA_PATH, EXT_LIBS from .test_tools import ARCH_BOTH, ARCH_M1 @@ -153,7 +153,12 @@ def test_fix_plat() -> None: assert exists(dylibs) assert os.listdir(dylibs) == ["libextfunc.dylib"] # Test check for existing output directory - with pytest.raises(DelocationError): + with pytest.raises( + DelocationError, + match=r".*wheel/fakepkg1/subpkg " + r"already exists in wheel but need to copy " + r".*libextfunc.dylib", + ): delocate_wheel(fixed_wheel, "broken_wheel.ext", "subpkg") # Test that `wheel unpack` works fixed_wheel, stray_lib = _fixed_wheel(tmpdir) @@ -301,9 +306,8 @@ def _fix_break_fix(arch_): ) # Now we check, and error raised _fix_break(arch) - assert_raises( - DelocationError, delocate_wheel, fixed_wheel, require_archs=() - ) + with pytest.raises(DelocationError, match=r".*(x86_64|arm64)"): + delocate_wheel(fixed_wheel, require_archs=()) # We can fix again by thinning the module too fixed_wheel2 = _fix_break_fix(arch) assert_equal( @@ -317,21 +321,17 @@ def _fix_break_fix(arch_): ARCH_BOTH.difference([arch]), ): fixed_wheel3 = _fix_break_fix(arch) - assert_raises( - DelocationError, - delocate_wheel, - fixed_wheel3, - require_archs=req_arch, - ) + with pytest.raises(DelocationError, match=r".*(x86_64|arm64)"): + delocate_wheel(fixed_wheel3, require_archs=req_arch) # Can be verbose (we won't check output though) _fix_break("x86_64") - assert_raises( + with pytest.raises( DelocationError, - delocate_wheel, - fixed_wheel, - require_archs=(), - check_verbose=True, - ) + match=r".*missing architectures in wheel\n" + r"fakepkg1/subpkg/module2.abi3.so needs arch arm64 missing from " + r".*/libextfunc.dylib", + ): + delocate_wheel(fixed_wheel, require_archs=(), check_verbose=True) def test_patch_wheel() -> None: