Skip to content
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

Share the stderr with the user, when non-zero exit code #927

Merged
merged 7 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/setuptools_scm/_run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ def has_command(
) -> bool:
try:
p = run([name, *args], cwd=".", timeout=5)
if p.returncode != 0:
log.error(f"Command '{name}' returned non-zero. This is stderr:")
log.error(p.stderr)
except OSError as e:
log.warning("command %s missing: %s", name, e)
res = False
Expand Down
14 changes: 14 additions & 0 deletions testing/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ def test_has_command() -> None:
assert not has_command("yadayada_setuptools_aint_ne")


def test_has_command_logs_stderr(caplog: pytest.LogCaptureFixture) -> None:
"""
If the name provided to has_command() exists as a command, but gives a non-zero
return code, there should be a log message generated.
"""
with pytest.warns(RuntimeWarning, match="ls"):
has_command("ls", ["--a-flag-that-doesnt-exist-should-give-output-on-stderr"])
found_it = False
for record in caplog.records:
if "returned non-zero. This is stderr" in record.message:
found_it = True
assert found_it, "Did not find expected log record for "


@pytest.mark.parametrize(
"tag, expected_version",
[
Expand Down
Loading