[Python][CI] Add yapf formatting guidelines and run check in CI.

This follows the same setup as MLIR and NPCOMP, using yapf and the
Google style guidelines, with two-space indentation.
This commit is contained in:
Mike Urbach 2021-04-19 22:20:10 -06:00 committed by mikeurbach
parent 8183b7a961
commit b0e69ae120
4 changed files with 21 additions and 5 deletions

View File

@ -94,12 +94,14 @@ jobs:
fetch-depth: 2
submodules: "true"
# We'll be running clang-tidy later in this flow.
- name: Install clang-tidy
# We'll be running clang-tidy, etc. later in this flow.
- name: Install formatting and linting tools
run: |
sudo apt-get install -y clang-tidy-9
sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy \
/usr/bin/clang-tidy-9 100
pip3 install yapf
echo "Using $(yapf --version)"
# --------
# Restore LLVM from cache and build if it's not in there.
@ -246,6 +248,13 @@ jobs:
echo "Clang-tidy found no problems"
exit 0
# Run yapf to check Python formatting.
- name: python-format
if: ${{ always() }}
run: |
files=$(git diff --name-only $DIFF_COMMIT | grep .py)
yapf --diff $files
# Upload the format and tidy patches to an artifact (zip'd) associated
# with the workflow run. Only run this on a failure.
- name: Upload format and tidy patches

3
.style.yapf Normal file
View File

@ -0,0 +1,3 @@
[style]
based_on_style = google
indent_width = 2

1
.yapfignore Normal file
View File

@ -0,0 +1 @@
llvm/**/*.py

View File

@ -56,15 +56,18 @@ class CosimTestRunner:
sources = []
for line in fileReader:
# Arguments to circt-rtl-sim, except for source files list
if m := re.match(r"^//\s*ARGS:(.*)$", line):
m = re.match(r"^//\s*ARGS:(.*)$", line)
if m:
self.args.extend(m.group(1).split())
# SOURCES are the additional source files (if any). If specified,
# must include the current file. These files are either absolute or
# relative to the current file.
if m := re.match(r"^//\s*SOURCES:(.*)$", line):
m = re.match(r"^//\s*SOURCES:(.*)$", line)
if m:
sources.extend(m.group(1).split())
# Run this Python line.
if m := re.match(r"^//\s*PY:(.*)$", line):
m = re.match(r"^//\s*PY:(.*)$", line)
if m:
self.runs.append(m.group(1).strip())
fileReader.close()