Skip to content

Commit dc23cff

Browse files
rgommersdnicolodi
authored andcommitted
MAINT: improve error message when meson isn't found
There are several ways that meson may go missing: - a non-isolated build and meson isn't installed - meson executable is specified in pyproject.toml and git submodule is containing it is not initialized (reported as resulting in a confusing error in numpy#26397) - MESON environmnent variable is used by the user and is misspelled The git submodule case was ending with: ``` meson-python: error: Could not find meson version 0.63.3 or newer, found . ``` and after this ends with: ``` meson-python: error: Could not find the specified meson: "vendored-meson/meson/meson.py" ``` If the executable is missing, the build ended with a very long traceback. Changing `FileNotFoundError` to `ConfigError` elides the traceback and clearly reports that the executable wasn't found. Easy to verify with any package with: ``` $ MESON=nonsense python -m build -wnx * Building wheel... meson-python: error: meson executable "nonsense" not found ERROR Backend subproccess exited when trying to invoke build_wheel ```
1 parent 0d2df77 commit dc23cff

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

mesonpy/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,8 @@ def _get_meson_command(
988988
# directly. For packages that vendor a forked Meson, the `meson.py` in the
989989
# root of the Meson repo can be used this way.
990990
if meson.endswith('.py'):
991+
if not os.path.exists(meson):
992+
raise ConfigError(f'Could not find the specified meson: "{meson}"')
991993
cmd = [sys.executable, meson]
992994
else:
993995
cmd = [meson]
@@ -997,7 +999,11 @@ def _get_meson_command(
997999
# but the corresponding meson command is not available in $PATH. Implement
9981000
# a runtime check to verify that the build environment is setup correcly.
9991001
required_version = _parse_version_string(version)
1000-
meson_version = subprocess.run(cmd + ['--version'], check=False, text=True, capture_output=True).stdout
1002+
try:
1003+
meson_version = subprocess.run(cmd + ['--version'], check=False, text=True, capture_output=True).stdout
1004+
except FileNotFoundError as err:
1005+
raise ConfigError(f'meson executable "{meson}" not found') from err
1006+
10011007
if _parse_version_string(meson_version) < required_version:
10021008
raise ConfigError(f'Could not find meson version {version} or newer, found {meson_version}.')
10031009

0 commit comments

Comments
 (0)