Skip to content

Commit

Permalink
improved logging in case of run_python failure
Browse files Browse the repository at this point in the history
  • Loading branch information
mbway committed Jan 2, 2024
1 parent 1ee950a commit ae56747
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
21 changes: 15 additions & 6 deletions tests/import_hook/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

verbose = True


script_dir = Path(__file__).resolve().parent
maturin_dir = script_dir.parent.parent
test_crates = maturin_dir / "test-crates"
Expand All @@ -30,7 +29,6 @@
import_hook.install()
"""


EXCLUDED_PROJECTS = {
"hello-world", # not imported as a python module (subprocess only)
"license-test", # not imported as a python module (subprocess only)
Expand Down Expand Up @@ -88,16 +86,18 @@ def run_python(
message = "\n".join(
[
"-" * 40,
"ERROR:",
"Called Process Error:",
subprocess.list2cmdline(cmd),
"",
"Output:",
output,
"-" * 40,
]
)
print(message, file=sys.stderr)
print(message)
if not expect_error:
raise
# re-raising the CalledProcessError would cause
# unnecessary output since we are already printing it above
raise RuntimeError("run_python failed") from None
duration = time.perf_counter() - start

output = output.replace("\r\n", "\n")
Expand Down Expand Up @@ -188,6 +188,15 @@ def is_installed_correctly(project_name: str, project_dir: Path, is_mixed: bool)
f"checking if {project_name} is installed correctly. "
f"{is_mixed=}, {installed_as_pth=} {installed_editable_with_direct_url=}"
)

proc = subprocess.run(
[sys.executable, "-m", "pip", "show", "--disable-pip-version-check", "-f", project_name],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
check=False,
)
output = "None" if proc.stdout is None else proc.stdout.decode()
log(f"pip output (returned {proc.returncode}):\n{output}")
return installed_editable_with_direct_url and (installed_as_pth == is_mixed)


Expand Down
1 change: 1 addition & 0 deletions tests/import_hook/test_project_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def test_do_not_rebuild_if_installed_non_editable(workspace: Path, project_name:
uninstall(project_name)
project_dir = get_project_copy(test_crates / project_name, workspace / project_name)
install_non_editable(project_dir)
assert is_installed_correctly(project_name, project_dir, is_mixed="mixed" in project_name)

check_installed_outside_project = workspace / "check_installed"
check_installed_outside_project.mkdir()
Expand Down

0 comments on commit ae56747

Please sign in to comment.