Skip to content

Commit 2c4c17e

Browse files
committed
Using Python script to run pep8 instead of bash.
We require a script (Python or bash) since we only run pep8 on files that are checked in to the repo by using `git ls-files`. (Prior to this change, spurious Python files would cause `tox -e lint` to fail.)
1 parent 202020a commit 2c4c17e

3 files changed

Lines changed: 40 additions & 20 deletions

File tree

scripts/pep8_on_repo.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Custom script to run pep8 on gcloud codebase.
16+
17+
This runs pep8 as a script via subprocess but only runs it on the
18+
.py files that are checked in to the repository.
19+
"""
20+
21+
22+
import os
23+
import subprocess
24+
25+
26+
def main():
27+
"""Run pep8 on all Python files in the repository."""
28+
git_root = subprocess.check_output(
29+
['git', 'rev-parse', '--show-toplevel']).strip()
30+
os.chdir(git_root)
31+
python_files = subprocess.check_output(['git', 'ls-files', '*py'])
32+
python_files = python_files.strip().split()
33+
34+
pep8_command = ['pep8'] + python_files
35+
subprocess.call(pep8_command)
36+
37+
38+
if __name__ == '__main__':
39+
main()

scripts/pep8_on_repo.sh

Lines changed: 0 additions & 19 deletions
This file was deleted.

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ verbose = 1
7070
basepython =
7171
python2.7
7272
commands =
73-
{toxinidir}/scripts/pep8_on_repo.sh
73+
python {toxinidir}/scripts/pep8_on_repo.py
7474
python {toxinidir}/scripts/run_pylint.py
7575
deps =
7676
pep8

0 commit comments

Comments
 (0)