Skip to content

Commit

Permalink
Use Black to format Python files (#14161)
Browse files Browse the repository at this point in the history
Switch from yapf to Black to better align with the LLVM and broader
Python community. I decided not to go with Pyink as it seems much less
popular and differs in formatting style beyond indentation.

-  Reformat all python files outside of `third_party` with black.
- Update the lint workflow to use black. This only considers files
modified by the PR.
-  Delete old dotfiles.

The command used to reformat all files at once:
```shell
fd -e py --exclude third_party | xargs black
```

To learn more about Back, see: https://black.readthedocs.io/en/stable/
and https://github.com/psf/black.

In the next PR, once the commit SHA of this PR is finalized, I plan to
add this commit to `.git-blame-ignore-revs` to keep the blame history
clean.

Issue: #14135
  • Loading branch information
kuhar committed Jun 21, 2023
1 parent e6d6c39 commit be24f02
Show file tree
Hide file tree
Showing 260 changed files with 30,427 additions and 26,423 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
git diff --exit-code
exit "${EXIT_CODE?}"
yapf:
black:
runs-on: ubuntu-20.04
steps:
- name: Checking out repository
Expand All @@ -59,18 +59,18 @@ jobs:
- name: Fetching Base Branch
# We have to explicitly fetch the base branch as well
run: git fetch --no-tags --prune --depth=1 origin "${GITHUB_BASE_REF?}:${GITHUB_BASE_REF?}"
- name: Install yapf
- name: Install black
run: |
python3 -m pip install yapf==0.30.0
- name: Run format_diff.py with yapf
python3 -m pip install black==23.3
- name: Check if modified files are formatted
run: |
git diff -U0 "${GITHUB_BASE_REF?}" | python3 third_party/format_diff/format_diff.py yapf -i
git diff --exit-code
git diff "${GITHUB_BASE_REF?}" --name-only -- '*.py' ':!third_party' \
| xargs black --check --diff --verbose
- name: Instructions for fixing the above linting errors
if: failure()
run: |
printf "You can fix the lint errors above by running\n"
printf " git diff -U0 "${GITHUB_BASE_REF?}" | python3 third_party/format_diff/format_diff.py yapf -i\n"
printf "You can fix formatting by running 'black' on the modified python files:\n"
printf " git diff ${GITHUB_BASE_REF?} --name-only -- '*.py' ':!third_party' | xargs black\n"
pytype:
runs-on: ubuntu-20.04
Expand Down
1 change: 0 additions & 1 deletion .pylintrc

This file was deleted.

4 changes: 0 additions & 4 deletions .style.yapf

This file was deleted.

0 comments on commit be24f02

Please sign in to comment.