Skip to content

Commit 40a6340

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 e2a34f7 commit 40a6340

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
@@ -3097,18 +3097,23 @@ def test_python_build_config_extensions(self):
30973097
},
30983098
'libpython': {
30993099
'dynamic': sysconfig.get_config_var('LDLIBRARY'),
3100-
'dynamic_stableabi': sysconfig.get_config_var('PY3LIBRARY'),
31013100
'static': sysconfig.get_config_var('LIBRARY'),
31023101
'link_extensions': True,
31033102
},
31043103
'c_api': {
31053104
'headers': sysconfig.get_path('include'),
3106-
'pkgconfig_path': sysconfig.get_config_var('LIBPC'),
31073105
}
31083106
}
3107+
3108+
py3library = sysconfig.get_config_var('PY3LIBRARY')
3109+
if py3library is not None:
3110+
python_build_config['libpython']['dynamic_stableabi'] = py3library
3111+
libpc = sysconfig.get_config_var('LIBPC')
3112+
if libpc is not None:
3113+
python_build_config['c_api']['pkgconfig_path'] = libpc
3114+
31093115
with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as python_build_config_file:
31103116
json.dump(python_build_config, fp=python_build_config_file)
3111-
31123117
with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as cross_file:
31133118
cross_file.write(
31143119
textwrap.dedent(f'''

0 commit comments

Comments
 (0)