Skip to content

Commit be24f02

Browse files
authoredJun 21, 2023
Use Black to format Python files (iree-org#14161)
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: iree-org#14135
1 parent e6d6c39 commit be24f02

File tree

260 files changed

+30427
-26423
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

260 files changed

+30427
-26423
lines changed
 

‎.github/workflows/lint.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
git diff --exit-code
5050
exit "${EXIT_CODE?}"
5151
52-
yapf:
52+
black:
5353
runs-on: ubuntu-20.04
5454
steps:
5555
- name: Checking out repository
@@ -59,18 +59,18 @@ jobs:
5959
- name: Fetching Base Branch
6060
# We have to explicitly fetch the base branch as well
6161
run: git fetch --no-tags --prune --depth=1 origin "${GITHUB_BASE_REF?}:${GITHUB_BASE_REF?}"
62-
- name: Install yapf
62+
- name: Install black
6363
run: |
64-
python3 -m pip install yapf==0.30.0
65-
- name: Run format_diff.py with yapf
64+
python3 -m pip install black==23.3
65+
- name: Check if modified files are formatted
6666
run: |
67-
git diff -U0 "${GITHUB_BASE_REF?}" | python3 third_party/format_diff/format_diff.py yapf -i
68-
git diff --exit-code
67+
git diff "${GITHUB_BASE_REF?}" --name-only -- '*.py' ':!third_party' \
68+
| xargs black --check --diff --verbose
6969
- name: Instructions for fixing the above linting errors
7070
if: failure()
7171
run: |
72-
printf "You can fix the lint errors above by running\n"
73-
printf " git diff -U0 "${GITHUB_BASE_REF?}" | python3 third_party/format_diff/format_diff.py yapf -i\n"
72+
printf "You can fix formatting by running 'black' on the modified python files:\n"
73+
printf " git diff ${GITHUB_BASE_REF?} --name-only -- '*.py' ':!third_party' | xargs black\n"
7474
7575
pytype:
7676
runs-on: ubuntu-20.04

‎.pylintrc

-1
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.