Skip to content

Commit

Permalink
mesonpy: only pull patchelf if needed
Browse files Browse the repository at this point in the history
Also move to the patchelf package instead of patchelf-wrapper as the
it's functionality is no longer needed and patchelf is better
maintained.

Fixed #52

Signed-off-by: Filipe Laíns <lains@riseup.net>
  • Loading branch information
FFY00 committed May 24, 2022
1 parent 86313a4 commit 931a06f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
7 changes: 5 additions & 2 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

class _depstr:
ninja = 'ninja >= 1.10.0'
patchelf_wrapper = 'patchelf-wrapper'
patchelf = 'patchelf >= 0.11.0'
wheel = 'wheel >= 0.36.0' # noqa: F811


Expand Down Expand Up @@ -778,7 +778,10 @@ def get_requires_for_build_wheel(
dependencies = [_depstr.wheel, _depstr.ninja]
with _project(config_settings) as project:
if not project.is_pure and platform.system() == 'Linux':
dependencies.append(_depstr.patchelf_wrapper)
# we may need patchelf
if not shutil.which('patchelf'): # XXX: This is slightly dangerous.
# patchelf not already acessible on the system
dependencies.append(_depstr.patchelf)
return dependencies


Expand Down
17 changes: 12 additions & 5 deletions tests/test_pep517.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,26 @@


if platform.system() == 'Linux':
VENDORING_DEPS = {mesonpy._depstr.patchelf_wrapper}
VENDORING_DEPS = {mesonpy._depstr.patchelf}
else:
VENDORING_DEPS = set()


@pytest.mark.parametrize(
('package', 'expected'),
('package', 'system_patchelf', 'expected'),
[
('pure', set()), # pure and no PEP 621
('library', VENDORING_DEPS), # not pure and not PEP 621
('pure', True, set()), # pure and system patchelf
('library', True, set()), # not pure and system patchelf
('pure', False, set()), # pure and no system patchelf
('library', False, VENDORING_DEPS), # not pure and no system patchelf
]
)
def test_get_requires_for_build_wheel(package, expected):
def test_get_requires_for_build_wheel(mocker, package, expected, system_patchelf):
mock = mocker.patch('shutil.which', return_value=system_patchelf)

if mock.called: # sanity check for the future if we add another usage
mock.assert_called_once_with('patchelf')

with cd_package(package):
assert set(mesonpy.get_requires_for_build_wheel()) == expected | {
mesonpy._depstr.wheel,
Expand Down

0 comments on commit 931a06f

Please sign in to comment.