chore: auto-format GN and python files in our precommit (#16722)

* chore: auto-format GN files in our precommit

* chore: update python linting errors and auto-lint python files

* chore: add trick for CHROMIUM_BUILDTOOLS_PATH

* chore: apply suggestions from code review

Co-Authored-By: MarshallOfSound <samuel.r.attard@gmail.com>
This commit is contained in:
Samuel Attard 2019-02-05 13:54:45 -08:00 committed by GitHub
parent 6d674eebb1
commit b29e8d18a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View file

@ -82,6 +82,14 @@
],
"*.md": [
"remark -qf"
],
"*.{gn,gni}": [
"python script/run-gn-format.py",
"git add"
],
"*.py": [
"node script/lint.js --py --fix --only --",
"git add"
]
}
}

22
script/run-gn-format.py Normal file
View file

@ -0,0 +1,22 @@
import os
import subprocess
import sys
SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__))
# Helper to run gn format on multiple files
# (gn only formats a single file at a time)
def main():
new_env = os.environ.copy()
new_env['DEPOT_TOOLS_WIN_TOOLCHAIN'] = '0'
new_env['CHROMIUM_BUILDTOOLS_PATH'] = os.path.realpath(
os.path.join(SOURCE_ROOT, '..', 'buildtools')
)
for gn_file in sys.argv[1:]:
subprocess.check_call(
['gn', 'format', gn_file],
env=new_env
)
if __name__ == '__main__':
sys.exit(main())