Skip to content

Commit cc2e326

Browse files
committed
ENH: implement runtime check for the required Meson version
meson-python correct behavior depends on fixes for Meson bugs released with version 0.63.3. Implement a belt and suspenders approach for making sure the version of the meson command line tool matches our minimum requirement.
1 parent f5d7f6e commit cc2e326

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

mesonpy/__init__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@
9191
'reset': '\33[0m',
9292
}
9393
_NO_COLORS = {color: '' for color in _COLORS}
94+
9495
_NINJA_REQUIRED_VERSION = '1.8.2'
96+
_MESON_REQUIRED_VERSION = '0.63.3' # keep in sync with the version requirement in pyproject.toml
9597

9698

9799
class _depstr:
@@ -750,7 +752,8 @@ def __init__(
750752
self._meson_args: MesonArgs = collections.defaultdict(list)
751753
self._env = os.environ.copy()
752754

753-
# prepare environment
755+
_check_meson_version()
756+
754757
self._ninja = _env_ninja_command()
755758
if self._ninja is None:
756759
raise ConfigError(f'Could not find ninja version {_NINJA_REQUIRED_VERSION} or newer.')
@@ -1130,6 +1133,22 @@ def _env_ninja_command(*, version: str = _NINJA_REQUIRED_VERSION) -> Optional[st
11301133
return None
11311134

11321135

1136+
def _check_meson_version(*, version: str = _MESON_REQUIRED_VERSION) -> None:
1137+
"""Check that the meson executable in the path has an appropriate version.
1138+
1139+
The meson Python package is a dependency of the meson-python
1140+
Python package, however, it may occur that the meson Python
1141+
package is installed but the corresponding meson command is not
1142+
available in $PATH. Implement a runtime check to verify that the
1143+
build environment is setup correcly.
1144+
1145+
"""
1146+
required_version = _parse_version_string(version)
1147+
meson_version = subprocess.run(['meson', '--version'], check=False, text=True, capture_output=True).stdout
1148+
if _parse_version_string(meson_version) < required_version:
1149+
raise ConfigError(f'Could not find meson version {version} or newer, found {meson_version}.')
1150+
1151+
11331152
def _pyproject_hook(func: Callable[P, T]) -> Callable[P, T]:
11341153
@functools.wraps(func)
11351154
def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:

0 commit comments

Comments
 (0)