Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 90
ENH: capture and report build errors when rebuilding editable wheels#859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dnicolodi
merged 3 commits into
mesonbuild:main
from
dnicolodi:editable-verbose-on-errorAug 21, 2026
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -319,7 +319,7 @@ def _work_to_do(self, env: dict[str, str]) -> bool: | ||
| dry_run_build_cmd = self._build_cmd + ['-n'] | ||
| # Check adapted from | ||
| # https://github.com/mesonbuild/meson/blob/a35d4d368a21f4b70afa3195da4d6292a649cb4c/mesonbuild/mtest.py#L1635-L1636 | ||
| p = subprocess.run(dry_run_build_cmd, cwd=self._build_path, env=env, capture_output=True) | ||
| p = subprocess.run(dry_run_build_cmd, cwd=self._build_path, env=env, check=False, capture_output=True) | ||
| return b'ninja: no work to do.' not in p.stdout and b'samu: nothing to do' not in p.stdout | ||
| @functools.lru_cache(maxsize=1) | ||
| @@ -332,15 +332,43 @@ def _rebuild(self) -> Node: | ||
| env[MARKER] = os.pathsep.join((env.get(MARKER, ''), self._build_path)) | ||
| if self._verbose or bool(env.get(VERBOSE, '')): | ||
| log_path = None | ||
| # We want to show some output only if there is some work to do. | ||
| if self._work_to_do(env): | ||
| build_command = ' '.join(self._build_cmd) | ||
| print(f'meson-python: building {self._name}: {build_command}', flush=True) | ||
| subprocess.run(self._build_cmd, cwd=self._build_path, env=env, check=True) | ||
| else: | ||
| subprocess.run(self._build_cmd, cwd=self._build_path, env=env, stdout=subprocess.DEVNULL, check=True) | ||
| except subprocess.CalledProcessError as exc: | ||
| raise ImportError(f're-building the {self._name} meson-python editable wheel package failed') from exc | ||
| # Redirect build log to file. | ||
| log_path = os.path.join(self._build_path, 'meson-logs', 'meson-python-build-log.txt') | ||
| with open(log_path, 'w') as log: | ||
| subprocess.run(self._build_cmd, cwd=self._build_path, env=env, check=True, | ||
| stderr=subprocess.STDOUT, stdout=log) | ||
| except subprocess.CalledProcessError as err: | ||
| msg = f'rebuilding the "{self._name}" editable package failed' | ||
| if log_path: | ||
| with open(log_path, 'r', encoding='utf8') as log: | ||
| # Skip to the error. | ||
| for line in log: | ||
| if line.startswith('FAILED: '): | ||
| break | ||
| else: | ||
| # When no `FAILED: ` line is found, rewind to the | ||
| # beginning of the log. | ||
| log.seek(0) | ||
| if line.strip().endswith(' build.ninja'): | ||
| # When the error occurred when rebuilding `ninja.build`, | ||
| # the meson output appears before the `FAILED: ` line. | ||
| # Rewind the build log to the beginning to report the | ||
| # error. | ||
| log.seek(0) | ||
| error = log.read() | ||
| if sys.version_info >= (3, 11): | ||
| exc = ImportError(msg) | ||
| exc.add_note(error) | ||
| raise exc from err | ||
| msg = f'{msg}:\n{error}' | ||
dnicolodi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. dnicolodi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| raise ImportError(msg) from err | ||
| install_plan_path = os.path.join(self._build_path, 'meson-info', 'intro-install_plan.json') | ||
| with open(install_plan_path, 'r', encoding='utf8') as f: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first
linethat thebreaktriggers on won't get printed here, right? Would be nice to capture that line as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving it out was a conscious decision. That line reads:
and I don't think it adds much information: the exit code is not relevant in the vast majority of the cases, and the target name is more often than not completely opaque to the user.
However, if you insist, I can include this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To give an idea in a scikit-learn context, this line would look like this:
I am fine with not having it, since one of the next line points directly at the Cython file (which is more useful than the ninja target I think).