Skip to content

Commit 81a859d

Browse files
committed
python: Fix immediate test failures with PyPy
Update the newly added tests to account for variables missing in `sysconfig` vars in PyPy. Update the Python logic to handle missing `c_api.pkgconfig_path`. The logic is actually still buggy, as it will fall back to using e.g. `python-3.11.pc` for PyPy3.11, and therefore building PyPy extensions against CPython headers. I've asked for suggestions how to best deal with it in: https://github.com/mesonbuild/meson/pull/13945/files#r2114254979
1 parent a5e27f1 commit 81a859d

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

mesonbuild/dependencies/python.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,13 @@ def __init__(self, environment: 'Environment', kwargs: T.Dict[str, T.Any],
449449
pkg_name = f'python-{installation.version}{pkg_embed}'
450450

451451
if installation.build_config:
452-
pkg_libdir = installation.build_config['c_api']['pkgconfig_path']
452+
pkg_libdir = installation.build_config.get('c_api.pkgconfig_path')
453453
pkg_libdir_origin = 'c_api.pkgconfig_path from the Python build config'
454454
else:
455455
pkg_libdir = installation.info['variables'].get('LIBPC')
456-
pkg_libdir_origin = 'LIBPC' if pkg_libdir else 'the default paths'
456+
pkg_libdir_origin = 'LIBPC'
457+
if pkg_libdir is None:
458+
pkg_libdir_origin = 'the default paths'
457459
mlog.debug(f'Searching for {pkg_libdir!r} via pkgconfig lookup in {pkg_libdir_origin}')
458460
pkgconfig_paths = [pkg_libdir] if pkg_libdir else []
459461

unittests/allplatformstests.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,18 +3023,23 @@ def test_python_build_config_extensions(self):
30233023
},
30243024
'libpython': {
30253025
'dynamic': sysconfig.get_config_var('LDLIBRARY'),
3026-
'dynamic_stableabi': sysconfig.get_config_var('PY3LIBRARY'),
30273026
'static': sysconfig.get_config_var('LIBRARY'),
30283027
'link_extensions': True,
30293028
},
30303029
'c_api': {
30313030
'headers': sysconfig.get_path('include'),
3032-
'pkgconfig_path': sysconfig.get_config_var('LIBPC'),
30333031
}
30343032
}
3033+
3034+
py3library = sysconfig.get_config_var('PY3LIBRARY')
3035+
if py3library is not None:
3036+
python_build_config['libpython']['dynamic_stableabi'] = py3library
3037+
libpc = sysconfig.get_config_var('LIBPC')
3038+
if libpc is not None:
3039+
python_build_config['c_api']['pkgconfig_path'] = libpc
3040+
30353041
with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as python_build_config_file:
30363042
json.dump(python_build_config, fp=python_build_config_file)
3037-
30383043
with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as cross_file:
30393044
cross_file.write(
30403045
textwrap.dedent(f'''

0 commit comments

Comments
 (0)