From 202020ace72fec9b6c7b8e9bca5db5bb71894f24 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Tue, 5 Jan 2016 18:01:12 -0800 Subject: [PATCH 1/2] Moving run_pylint into scripts. --- .gitignore | 2 +- pylintrc_default => scripts/pylintrc_default | 0 run_pylint.py => scripts/run_pylint.py | 5 +++-- tox.ini | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) rename pylintrc_default => scripts/pylintrc_default (100%) rename run_pylint.py => scripts/run_pylint.py (98%) diff --git a/.gitignore b/.gitignore index 3f9406901fd2..b7d72ad8e7f8 100644 --- a/.gitignore +++ b/.gitignore @@ -48,7 +48,7 @@ coverage.xml system_tests/local_test_setup # Make sure a generated file isn't accidentally committed. -pylintrc_reduced +scripts/pylintrc_reduced # Travis build directories. gcloud-python-wheels/ diff --git a/pylintrc_default b/scripts/pylintrc_default similarity index 100% rename from pylintrc_default rename to scripts/pylintrc_default diff --git a/run_pylint.py b/scripts/run_pylint.py similarity index 98% rename from run_pylint.py rename to scripts/run_pylint.py index 1ba6f0601015..8f9c0fe25f97 100644 --- a/run_pylint.py +++ b/scripts/run_pylint.py @@ -36,8 +36,9 @@ 'docs/conf.py', 'setup.py', ] -PRODUCTION_RC = 'pylintrc_default' -TEST_RC = 'pylintrc_reduced' +SCRIPTS_DIR = os.path.abspath(os.path.dirname(__file__)) +PRODUCTION_RC = os.path.join(SCRIPTS_DIR, 'pylintrc_default') +TEST_RC = os.path.join(SCRIPTS_DIR, 'pylintrc_reduced') TEST_DISABLED_MESSAGES = [ 'attribute-defined-outside-init', 'exec-used', diff --git a/tox.ini b/tox.ini index 4de28f423371..8ff801bce229 100644 --- a/tox.ini +++ b/tox.ini @@ -71,7 +71,7 @@ basepython = python2.7 commands = {toxinidir}/scripts/pep8_on_repo.sh - python run_pylint.py + python {toxinidir}/scripts/run_pylint.py deps = pep8 pylint From 2c4c17e4e4ecff384577ecf6762b98e611f33bfe Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Tue, 5 Jan 2016 18:08:42 -0800 Subject: [PATCH 2/2] 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.) --- scripts/pep8_on_repo.py | 39 +++++++++++++++++++++++++++++++++++++++ scripts/pep8_on_repo.sh | 19 ------------------- tox.ini | 2 +- 3 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 scripts/pep8_on_repo.py delete mode 100755 scripts/pep8_on_repo.sh diff --git a/scripts/pep8_on_repo.py b/scripts/pep8_on_repo.py new file mode 100644 index 000000000000..267fd00ae857 --- /dev/null +++ b/scripts/pep8_on_repo.py @@ -0,0 +1,39 @@ +# Copyright 2016 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Custom script to run pep8 on gcloud codebase. + +This runs pep8 as a script via subprocess but only runs it on the +.py files that are checked in to the repository. +""" + + +import os +import subprocess + + +def main(): + """Run pep8 on all Python files in the repository.""" + git_root = subprocess.check_output( + ['git', 'rev-parse', '--show-toplevel']).strip() + os.chdir(git_root) + python_files = subprocess.check_output(['git', 'ls-files', '*py']) + python_files = python_files.strip().split() + + pep8_command = ['pep8'] + python_files + subprocess.call(pep8_command) + + +if __name__ == '__main__': + main() diff --git a/scripts/pep8_on_repo.sh b/scripts/pep8_on_repo.sh deleted file mode 100755 index 6afcd7f75370..000000000000 --- a/scripts/pep8_on_repo.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -# Copyright 2015 Google Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -ev - -pep8 $(git ls-files '*py') diff --git a/tox.ini b/tox.ini index 8ff801bce229..add311318e26 100644 --- a/tox.ini +++ b/tox.ini @@ -70,7 +70,7 @@ verbose = 1 basepython = python2.7 commands = - {toxinidir}/scripts/pep8_on_repo.sh + python {toxinidir}/scripts/pep8_on_repo.py python {toxinidir}/scripts/run_pylint.py deps = pep8