Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/clang-format-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
--end-rev $END_REV \
--changed-files "$CHANGED_FILES"
apply_diff:
if: ${{ github.event_name == 'issue_comment' && endsWith(github.event.comment.body, '- [x] Check this box to apply formatting changes to this branch.') }}
if: ${{ github.event_name == 'issue_comment' && github.event.comment.user.login == 'github-actions[bot]' && endsWith(github.event.comment.body, '- [x] Check this box to apply formatting changes to this branch.') }}
runs-on: ubuntu-latest
env:
TMP_DIFF_FILE: /tmp/diff.patch
Expand Down
41 changes: 1 addition & 40 deletions utils/git/code-format-helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,46 +153,7 @@ def format_run(self, changed_files: [str], args: argparse.Namespace) -> str | No
return None


class DarkerFormatHelper(FormatHelper):
name = "darker"
friendly_name = "Python code formatter"

@property
def instructions(self):
return " ".join(self.darker_cmd)

def filter_changed_files(self, changed_files: [str]) -> [str]:
filtered_files = []
for path in changed_files:
name, ext = os.path.splitext(path)
if ext == ".py":
filtered_files.append(path)

return filtered_files

def format_run(self, changed_files: [str], args: argparse.Namespace) -> str | None:
py_files = self.filter_changed_files(changed_files)
if not py_files:
return
darker_cmd = [
"darker",
"--check",
"--diff",
"-r",
f"{args.start_rev}..{args.end_rev}",
] + py_files
print(f"Running: {' '.join(darker_cmd)}")
self.darker_cmd = darker_cmd
proc = subprocess.run(darker_cmd, capture_output=True)

# formatting needed
if proc.returncode == 1:
return proc.stdout.decode("utf-8")

return None


ALL_FORMATTERS = (DarkerFormatHelper(), ClangFormatHelper())
ALL_FORMATTERS = (ClangFormatHelper(),)

if __name__ == "__main__":
parser = argparse.ArgumentParser()
Expand Down
15 changes: 15 additions & 0 deletions utils/git/code-format-save-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
CR = '\r'


COMMENT_TAG = "<!--LLVM CODE FORMAT COMMENT:"


def get_diff_from_comment(comment: IssueComment.IssueComment) -> str:
diff_pat = re.compile(r"``````````diff(?P<DIFF>.+)``````````", re.DOTALL)
m = re.search(diff_pat, comment.body)
Expand All @@ -50,6 +53,18 @@ def apply_patches(args: argparse.Namespace) -> None:
if comment is None:
raise Exception(f"Comment {args.comment_id} does not exist")

if comment.user.login != "github-actions[bot]":
raise Exception(
f"Comment {args.comment_id} was not created by the expected bot "
f"(author: {comment.user.login})"
)

if COMMENT_TAG not in comment.body:
raise Exception(
f"Comment {args.comment_id} does not contain the expected "
f"format comment tag"
)

# get the diff from the comment
diff = get_diff_from_comment(comment)

Expand Down
26 changes: 4 additions & 22 deletions utils/git/requirements_formatting.txt
Original file line number Diff line number Diff line change
@@ -1,51 +1,33 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --output-file=llvm/utils/git/requirements_formatting.txt llvm/utils/git/requirements_formatting.txt.in
# pip-compile --output-file=utils/git/requirements_formatting.txt utils/git/requirements_formatting.txt.in
#
black==24.3.0
# via
# -r llvm/utils/git/requirements_formatting.txt.in
# darker
certifi==2024.7.4
# via requests
cffi==1.15.1
cffi==2.0.0
# via
# cryptography
# pynacl
charset-normalizer==3.2.0
# via requests
click==8.1.7
# via black
cryptography==46.0.5
# via pyjwt
darker==1.7.2
# via -r llvm/utils/git/requirements_formatting.txt.in
deprecated==1.2.14
# via pygithub
idna==3.7
# via requests
mypy-extensions==1.0.0
# via black
packaging==23.1
# via black
pathspec==0.11.2
# via black
platformdirs==3.10.0
# via black
pycparser==2.21
# via cffi
pygithub==1.59.1
# via -r llvm/utils/git/requirements_formatting.txt.in
# via -r utils/git/requirements_formatting.txt.in
pyjwt[crypto]==2.8.0
# via pygithub
pynacl==1.5.0
# via pygithub
requests==2.32.4
# via pygithub
toml==0.10.2
# via darker
urllib3==2.6.0
# via requests
wrapt==1.15.0
Expand Down
2 changes: 0 additions & 2 deletions utils/git/requirements_formatting.txt.in
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
black~=24.3
darker==1.7.2
PyGithub==1.59.1
Loading