-
Notifications
You must be signed in to change notification settings - Fork 76
Print meson output in case of error during editable rebuild #750
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
base: main
Are you sure you want to change the base?
Changes from all commits
09a119a
7b7330a
84b650b
bce0787
284ebff
ba938be
8cfc7e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -340,11 +340,28 @@ def _rebuild(self) -> Node: | |
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) | ||
subprocess.run( | ||
self._build_cmd, | ||
cwd=self._build_path, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.STDOUT, | ||
env=env, | ||
check=True, | ||
) | ||
else: | ||
subprocess.run(self._build_cmd, cwd=self._build_path, env=env, stdout=subprocess.DEVNULL, check=True) | ||
subprocess.run( | ||
self._build_cmd, | ||
cwd=self._build_path, | ||
env=env, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.STDOUT, | ||
check=True, | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The compilation output can be very long. Buffering it all in memory does not seems a very good idea to me. |
||
except subprocess.CalledProcessError as exc: | ||
raise ImportError(f're-building the {self._name} meson-python editable wheel package failed') from exc | ||
output = exc.output.decode(errors='replace') if exc.output is not None else 'No error details available' | ||
raise ImportError( | ||
f're-building the {self._name} meson-python editable wheel package failed with: \n{output}' | ||
) from exc | ||
|
||
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: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -336,9 +336,52 @@ def test_editable_rebuild_error(package_purelib_and_platlib, tmp_path, verbose): | |
# Import module and trigger rebuild: the build fails and ImportErrror is raised | ||
stdout = io.StringIO() | ||
with redirect_stdout(stdout): | ||
with pytest.raises(ImportError, match='re-building the purelib-and-platlib '): | ||
with pytest.raises( | ||
ImportError, match=r're-building the purelib-and-platlib (?s:.)*error: expected identifier' | ||
): | ||
import plat # noqa: F401 | ||
assert not verbose or stdout.getvalue().startswith('meson-python: building ') | ||
if verbose: | ||
assert stdout.getvalue().startswith('meson-python: building ') | ||
else: | ||
assert not stdout.getvalue() | ||
|
||
finally: | ||
del sys.meta_path[0] | ||
sys.modules.pop('pure', None) | ||
path.write_text(code) | ||
|
||
|
||
@pytest.mark.parametrize('verbose', [False, True], ids=('', 'verbose')) | ||
def test_editable_meson_file_rebuild_error(package_purelib_and_platlib, tmp_path, verbose): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you adding this test? Why do you expect that a failure in running meson produces a different outcome that a failure in running a compilation tool? |
||
with mesonpy._project({'builddir': os.fspath(tmp_path)}) as project: | ||
finder = _editable.MesonpyMetaFinder( | ||
project._metadata.name, | ||
{'plat', 'pure'}, | ||
os.fspath(tmp_path), | ||
project._build_command, | ||
verbose=verbose, | ||
) | ||
path = package_purelib_and_platlib / 'meson.build' | ||
code = path.read_text() | ||
|
||
try: | ||
# Install editable hooks | ||
sys.meta_path.insert(0, finder) | ||
|
||
# Insert invalid code in the meson build file | ||
path.write_text('<not valid') | ||
|
||
# Import module and trigger rebuild: the build fails and ImportErrror is raised | ||
stdout = io.StringIO() | ||
with redirect_stdout(stdout): | ||
with pytest.raises( | ||
ImportError, match=r're-building the purelib-and-platlib (?s:.)*ERROR: Invalid source tree:' | ||
): | ||
import plat # noqa: F401 | ||
if verbose: | ||
assert stdout.getvalue().startswith('meson-python: building ') | ||
else: | ||
assert not stdout.getvalue() | ||
|
||
finally: | ||
del sys.meta_path[0] | ||
|
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.
This now hides output that was directed to standard output before.