Skip to content

Commit

Permalink
MAINT: improve error message when meson isn't found
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
rgommers authored and dnicolodi committed May 19, 2024
1 parent 0d2df77 commit dc23cff
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,8 @@ def _get_meson_command(
# directly. For packages that vendor a forked Meson, the `meson.py` in the
# root of the Meson repo can be used this way.
if meson.endswith('.py'):
if not os.path.exists(meson):
raise ConfigError(f'Could not find the specified meson: "{meson}"')
cmd = [sys.executable, meson]
else:
cmd = [meson]
Expand All @@ -997,7 +999,11 @@ def _get_meson_command(
# but the corresponding meson command is not available in $PATH. Implement
# a runtime check to verify that the build environment is setup correcly.
required_version = _parse_version_string(version)
meson_version = subprocess.run(cmd + ['--version'], check=False, text=True, capture_output=True).stdout
try:
meson_version = subprocess.run(cmd + ['--version'], check=False, text=True, capture_output=True).stdout
except FileNotFoundError as err:
raise ConfigError(f'meson executable "{meson}" not found') from err

if _parse_version_string(meson_version) < required_version:
raise ConfigError(f'Could not find meson version {version} or newer, found {meson_version}.')

Expand Down

0 comments on commit dc23cff

Please sign in to comment.