-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix python linter errors and add linter checks to CI
Internal CI systems and the new GitHub CI system were out of sync, with the external system not doing any linting. Further, the internal system was using an internal-only linter for Python. This creates a script for Python linting based on the open-source pylint tool, checks in the Google Style Guide's pylintrc file, creates a custom action for linting and adds it to the existing workflows, fixes pre-existing linter errors in Python scripts, and updates pylint overrides. b/190743862 Change-Id: Iff1f5d4690b32479af777ded0834c31c2161bd10
- Loading branch information
1 parent
e32b35f
commit 56e2272
Showing
11 changed files
with
575 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
.github/workflows/custom-actions/lint-packager/action.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Lint Shaka Packager | ||
|
||
description: | | ||
A reusable action to lint Shaka Packager source. | ||
When checking out source, you must use 'fetch-depth: 2' in actions/checkout, | ||
or else the linter won't have another revision to compare to. | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Lint | ||
shell: bash | ||
run: | | ||
cd src/ | ||
echo "::group::Installing git-clang-format" | ||
wget https://raw.githubusercontent.com/llvm-mirror/clang/master/tools/clang-format/git-clang-format | ||
sudo install -m 755 git-clang-format /usr/local/bin/git-clang-format | ||
rm git-clang-format | ||
echo "::endgroup::" | ||
echo "::group::Check clang-format for C++ sources" | ||
# NOTE: --binary forces use of global clang-format (which works) instead | ||
# of depot_tools clang-format (which doesn't). | ||
# NOTE: Must use base.sha instead of base.ref, since we don't have | ||
# access to the branch name that base.ref would give us. | ||
# NOTE: Must also use fetch-depth: 2 in actions/checkout to have access | ||
# to the base ref for comparison. | ||
packager/tools/git/check_formatting.py \ | ||
--binary /usr/bin/clang-format \ | ||
${{ github.event.pull_request.base.sha || 'HEAD^' }} | ||
echo "::endgroup::" | ||
echo "::group::Check pylint for Python sources" | ||
packager/tools/git/check_pylint.py | ||
echo "::endgroup::" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/python3 | ||
"""Lints all Python sources in the repo, excluding third-party code.""" | ||
|
||
import os | ||
import subprocess | ||
|
||
import pylint.lint | ||
|
||
def ShouldLintFile(path): | ||
"""Returns True if this path should be linted.""" | ||
excluded_folders = [ | ||
'third_party', | ||
'protoc_wrapper', | ||
'ycm_extra_conf', | ||
] | ||
|
||
if (not path.endswith('.py') or | ||
any(f in path for f in excluded_folders)): | ||
return False | ||
|
||
return True | ||
|
||
def GetPyFileList(): | ||
"""Yield the paths of Python source files that should be linted.""" | ||
output = subprocess.check_output(['git', 'ls-files'], text=True) | ||
|
||
for path in output.split('\n'): | ||
if ShouldLintFile(path): | ||
yield path | ||
|
||
def main(): | ||
"""Lint Python source files. | ||
Pylint will exit with a non-zero status if there are any failures.""" | ||
dir_name = os.path.dirname(__file__) | ||
rc_path = os.path.join(dir_name, 'pylintrc') | ||
|
||
py_files = list(GetPyFileList()) | ||
# Run will call sys.exit, so no explicit call to sys.exit is used here. | ||
pylint.lint.Run(['--rcfile={}'.format(rc_path)] + py_files) | ||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.