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

[Workflow] Expand code-format-helper.py error reporting #69686

Merged
merged 2 commits into from Oct 27, 2023

Conversation

rprichard
Copy link
Contributor

  • Consider the darker/clang-format command to have failed if the exit code is non-zero, regardless of the stdout/stderr output.
  • Allow stderr from the formatter command to propagate to the script's caller (and into the GitHub log).
  • On success, dump stdout to the caller, so it ends up in GitHub's log. I'm not sure what this would ever be, but if it exists, it should be preserved.
  • Just before the script exits, if any formatter failed, print a line showing which formatters failed.

Replace [str] with list[str] to satisfy mypy/pytype.

@rprichard rprichard requested a review from tru October 20, 2023 07:48
@rprichard
Copy link
Contributor Author

I'm trying to fix a couple of issue I recently ran into:

I'm not sure how to test this change, but it does pass mypy and black.

I was a bit confused by the param: [str] type annotations... AFAICT mypy and pytype don't accept it and require param: list[str] instead, so I change the annotations.

@tru
Copy link
Collaborator

tru commented Oct 20, 2023

Hi, thanks for the updates, they seem sane to me. It's a little tough to review since it has a lot of stylistic changes mixed in with the functional ones. I would like to know if we could split the PR up so it's easier to review.

@rprichard
Copy link
Contributor Author

I'll try splitting out an earlier CL that just does black/mypy. That should help.

@rprichard rprichard force-pushed the format-helper-error-reporting branch from acb8511 to ac2b8dc Compare October 20, 2023 08:24
@rprichard
Copy link
Contributor Author

The "[Workflow] make code-format-helper.py mypy-safe (NFC)" commit in this PR is actually part of #69691 instead.

Copy link
Collaborator

@tru tru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I assume this has been tested somehow right?

@rprichard
Copy link
Contributor Author

LGTM, I assume this has been tested somehow right?

Unfortunately, it still needs to be tested somehow. I did notice that you had some way to demo it on tru#8.

@tru
Copy link
Collaborator

tru commented Oct 20, 2023

LGTM, I assume this has been tested somehow right?

Unfortunately, it still needs to be tested somehow. I did notice that you had some way to demo it on tru#8.

Yes, the way I tested it was that I pushed my changes to a branch in my fork (i.e. formatter), then I created a new branch based on formatter called something like test_formatter and do a small change where the formatted would fail. Then I would open a PR from test_formatter towards formatter and it will run the code.

@rprichard
Copy link
Contributor Author

rprichard commented Oct 20, 2023

I noticed that darker also accepts a -- argument before its file list, like git-clang-format does. Maybe we should add it for darker? It can be a separate PR.


Edit: I got darker and git-clang-format backwards.

@rprichard
Copy link
Contributor Author

One of my test PRs was supposed to fail C++ and Python formatting, but instead it only failed on C++, and it reproduced the failure mode where darker simply ignores code formatting errors:

https://github.com/rprichard/llvm-project/actions/runs/6592874295/job/17914345865?pr=4

Apparently darker is succeeding with no stdout/stderr output?

The darker command fails for me when I run it locally:

darker --check --diff -r e9a6609b7d4aedffa9109bb26ce1bee31d92dbb6..88be1bb44e96c38f550da9385f89aa427d4360b5 llvm/utils/git/test1.py

I still think this CL is an improvement on the error reporting, though. (I assume the latest fixup commit is OK.)

I used these PRs to test this PR so far: rprichard#1 rprichard#2 rprichard#3 rprichard#4 rprichard#5

 * Consider the darker/clang-format command to have failed if the
   exit code is non-zero, regardless of the stdout/stderr output.
 * Allow stderr from the formatter command to propagate to the script's
   caller (and into the GitHub log).
 * On success, dump stdout to the caller, so it ends up in GitHub's
   log. I'm not sure what this would ever be, but if it exists, it
   should be preserved.
 * Just before the script exits, if any formatter failed, print a line
   showing which formatters failed.

Replace [str] with list[str] to satisfy mypy/pytype.
 * Prefix "clang-format" to the Excluding lines rather than print
   "Formatter darker (Python code formatter):" and
   "Formatter clang-format (C/C++ code formatter):" Those formatter
   lines were being printed even when there were no C++/Python files to
   format.

 * Capture stderr and then print it out, rather than let the subprocess
   directly write it out. This ensures that output appears in the right
   order when the script's output is buffered.
@rprichard rprichard force-pushed the format-helper-error-reporting branch from cbfc351 to 6612b01 Compare October 20, 2023 22:10
@tru
Copy link
Collaborator

tru commented Oct 23, 2023

One of my test PRs was supposed to fail C++ and Python formatting, but instead it only failed on C++, and it reproduced the failure mode where darker simply ignores code formatting errors:

https://github.com/rprichard/llvm-project/actions/runs/6592874295/job/17914345865?pr=4

Apparently darker is succeeding with no stdout/stderr output?

Hmm that doesn't seem right. I am pretty sure I had it failing with the right code before. Are you sure this isn't related to your changes?

@rprichard
Copy link
Contributor Author

One of my test PRs was supposed to fail C++ and Python formatting, but instead it only failed on C++, and it reproduced the failure mode where darker simply ignores code formatting errors:
https://github.com/rprichard/llvm-project/actions/runs/6592874295/job/17914345865?pr=4
Apparently darker is succeeding with no stdout/stderr output?

Hmm that doesn't seem right. I am pretty sure I had it failing with the right code before. Are you sure this isn't related to your changes?

I don't think so? darker did the same thing to me on an actual PR, which motivated me to try and expand the error reporting. #69274. Maybe it's not checking newly added files?... I should see if I can get this to reproduce.

@rprichard
Copy link
Contributor Author

It appears that darker/black process their file list using the currently-checked out files, not by querying git for the contents of the two git revisions. A newly-added file isn't checked out, because the current GitHub workflow checks something else out instead (the target branch of the PR maybe?)

https://github.com/rprichard/llvm-project/actions/runs/6622055992/job/17986970016?pr=10

I think the fix is to specify a different commit to checkout in pr-code-format.yml.

@rprichard
Copy link
Contributor Author

These changes are pretty well-tested via https://github.com/rprichard/llvm-project/pulls.

@rprichard rprichard merged commit 56cadac into llvm:main Oct 27, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants