|
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: MIT |
4 | 4 |
|
| 5 | +import argparse |
5 | 6 | import contextlib |
6 | 7 | import importlib.metadata |
7 | 8 | import os |
@@ -192,3 +193,31 @@ def cleanenv(): |
192 | 193 | # $MACOSX_DEPLOYMENT_TARGET affects the computation of the platform tag on macOS. |
193 | 194 | yield mpatch.delenv('MACOSX_DEPLOYMENT_TARGET', raising=False) |
194 | 195 | mpatch.undo() |
| 196 | + |
| 197 | + |
| 198 | +@pytest.fixture(autouse=True, scope='session') |
| 199 | +def meson_fatal_warnings(): |
| 200 | + # Cannot use the 'monkeypatch' fixture because of scope mismatch. |
| 201 | + mpatch = pytest.MonkeyPatch() |
| 202 | + mesonpy_validate_pyproject_config = mesonpy._validate_pyproject_config |
| 203 | + |
| 204 | + def _validate_pyproject_config(pyproject): |
| 205 | + pyproject_config = mesonpy_validate_pyproject_config(pyproject) |
| 206 | + |
| 207 | + meson_args = pyproject_config.setdefault('args', {}) |
| 208 | + meson_setup_args = meson_args.get('setup', []) |
| 209 | + |
| 210 | + # Add ``--fatal-meson-warnings`` to the ``meson setup`` arguments |
| 211 | + # unless the project specifies ``--no-fatal-meson-warnings`` in |
| 212 | + # ``tool.meson-build.args.setup``. |
| 213 | + parser = argparse.ArgumentParser(add_help=False) |
| 214 | + parser.add_argument('--no-fatal-meson-warnings', action='store_true') |
| 215 | + meson_setup_args = meson_args.get('setup', []) |
| 216 | + args, meson_setup_args = parser.parse_known_args(meson_setup_args) |
| 217 | + if not args.no_fatal_meson_warnings: |
| 218 | + meson_setup_args.append('--fatal-meson-warnings') |
| 219 | + meson_args['setup'] = meson_setup_args |
| 220 | + |
| 221 | + return pyproject_config |
| 222 | + |
| 223 | + mpatch.setattr(mesonpy, '_validate_pyproject_config', _validate_pyproject_config) |
0 commit comments