Skip to content

Commit eadd75b

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 201ba14 commit eadd75b

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.')
@@ -1129,6 +1132,22 @@ def _env_ninja_command(*, version: str = _NINJA_REQUIRED_VERSION) -> Optional[st
11291132
return None
11301133

11311134

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

0 commit comments

Comments
 (0)