Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 11 additions & 5 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,14 @@ def _string_or_strings(value: Any, name: str) -> List[str]:
return config


def _get_meson_args(args: Dict[str, List[str]]) -> MesonArgs:
# This mostly exists so that it can be monkeypatched in tests
meson_args: MesonArgs = collections.defaultdict(list)
for key, value in args.items():
meson_args[key].extend(value) # type: ignore[index]
return meson_args
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely happy with adding this function, but I didn't find a better way.



class Project():
"""Meson project wrapper to generate Python artifacts."""

Expand All @@ -674,16 +682,14 @@ def __init__(
self._editable_verbose = editable_verbose
self._meson_native_file = self._build_dir / 'meson-python-native-file.ini'
self._meson_cross_file = self._build_dir / 'meson-python-cross-file.ini'
self._meson_args: MesonArgs = collections.defaultdict(list)
self._limited_api = False

# load pyproject.toml
pyproject = tomllib.loads(self._source_dir.joinpath('pyproject.toml').read_text(encoding='utf-8'))

# load meson args from pyproject.toml
pyproject_config = _validate_pyproject_config(pyproject)
for key, value in pyproject_config.get('args', {}).items():
self._meson_args[key].extend(value)

# get meson args from pyproject.toml
self._meson_args = _get_meson_args(pyproject_config.get('args', {}))

# meson arguments from the command line take precedence over
# arguments from the configuration file thus are added later
Expand Down
26 changes: 26 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MIT

import argparse
import contextlib
import importlib.metadata
import os
Expand Down Expand Up @@ -192,3 +193,28 @@ def cleanenv():
# $MACOSX_DEPLOYMENT_TARGET affects the computation of the platform tag on macOS.
yield mpatch.delenv('MACOSX_DEPLOYMENT_TARGET', raising=False)
mpatch.undo()


@pytest.fixture(autouse=True, scope='session')
def meson_fatal_warnings():
# Cannot use the 'monkeypatch' fixture because of scope mismatch.
mpatch = pytest.MonkeyPatch()
mesonpy_get_meson_args = mesonpy._get_meson_args

def _get_meson_args(args):
meson_args = mesonpy_get_meson_args(args)
meson_setup_args = meson_args['setup']

# Add ``--fatal-meson-warnings`` to the ``meson setup`` arguments
# unless the project specifies ``--no-fatal-meson-warnings`` in
# ``tool.meson-build.args.setup``.
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--no-fatal-meson-warnings', action='store_true')
args, meson_setup_args = parser.parse_known_args(meson_setup_args)
if not args.no_fatal_meson_warnings:
meson_setup_args.append('--fatal-meson-warnings')

meson_args['setup'] = meson_setup_args
return meson_args

mpatch.setattr(mesonpy, '_get_meson_args', _get_meson_args)
2 changes: 1 addition & 1 deletion tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def test_ios_project(package_simple, monkeypatch, multiarch, tmp_path):
project = mesonpy.Project(source_dir=package_simple, build_dir=tmp_path)

# Meson configuration points at the cross file
assert project._meson_args['setup'] == ['--cross-file', os.fspath(tmp_path / 'meson-python-cross-file.ini')]
assert project._meson_args['setup'][-2:] == ['--cross-file', os.fspath(tmp_path / 'meson-python-cross-file.ini')]

# Meson config files exist, and have some relevant keys
assert (tmp_path / 'meson-python-native-file.ini').exists()
Expand Down