Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ before_install:
- git clone https://github.com/GoogleCloudPlatform/gcloud-python-wheels
gcloud-python-wheels
- export WHEELHOUSE="$(pwd)/gcloud-python-wheels/wheelhouse/"
- export GCLOUD_REMOTE_FOR_LINT="origin"
- export GCLOUD_BRANCH_FOR_LINT="master"

install:
- scripts/custom_pip_install.sh tox
Expand Down
42 changes: 30 additions & 12 deletions run_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,40 @@ def is_production_filename(filename):
def get_files_for_linting():
"""Gets a list of files in the repository.

By default returns all files via `git ls-files`. However, if the
environment variables `GCLOUD_REMOTE_FOR_LINT` and `GCLOUD_BRANCH_FOR_LINT`
are set, this will return only those files which have changed since
the last commit in `REMOTE_FOR_LINT/BRANCH_FOR_LINT`
By default, returns all files via `git ls-files`. However, in some cases
uses a specific commit or branch (a so-called diff base) to compare
against for changed files.

To speed up linting on Travis pull requests against master, we manually
set the diff base to origin/master. We don't do this on non-pull requests
since origin/master will be equivalent to the currently checked out code.
One could potentially use ${TRAVIS_COMMIT_RANGE} to find a diff base but
this value is not dependable.

To allow faster local `tox` runs, the environment variables
`GCLOUD_REMOTE_FOR_LINT` and `GCLOUD_BRANCH_FOR_LINT` can be set to specify
a remote branch to diff against.
"""
remote = os.getenv('GCLOUD_REMOTE_FOR_LINT')
branch = os.getenv('GCLOUD_BRANCH_FOR_LINT')

if remote is None or branch is None:
print 'Remote branch not specified, listing all files in repository.'
diff_base = None
if (os.getenv('TRAVIS_BRANCH') == 'master' and
os.getenv('TRAVIS_PULL_REQUEST') != 'false'):
# In the case of a pull request into master, we want to
# diff against HEAD in master.
diff_base = 'origin/master'
elif os.getenv('TRAVIS') is None:
# Only allow specified remote and branch in local dev.
remote = os.getenv('GCLOUD_REMOTE_FOR_LINT')
branch = os.getenv('GCLOUD_BRANCH_FOR_LINT')
if remote is not None and branch is not None:
diff_base = '%s/%s' % (remote, branch)

if diff_base is None:
print 'Diff base not specified, listing all files in repository.'
result = subprocess.check_output(['git', 'ls-files'])
else:
remote_branch = '%s/%s' % (remote, branch)
result = subprocess.check_output(['git', 'diff', '--name-only',
remote_branch])
print 'Using files changed relative to %s:' % (remote_branch,)
diff_base])
print 'Using files changed relative to %s:' % (diff_base,)
print '-' * 60
print result.rstrip('\n') # Don't print trailing newlines.
print '-' * 60
Expand Down