Skip to content

Commit 691b9f4

Browse files
committed
Fixing corner case where lint doesn't run outside of a PR.
1 parent 8e12e10 commit 691b9f4

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ before_install:
44
- git clone https://github.com/GoogleCloudPlatform/gcloud-python-wheels
55
gcloud-python-wheels
66
- export WHEELHOUSE="$(pwd)/gcloud-python-wheels/wheelhouse/"
7-
- export GCLOUD_REMOTE_FOR_LINT="origin"
8-
- export GCLOUD_BRANCH_FOR_LINT="master"
97

108
install:
119
- scripts/custom_pip_install.sh tox

run_pylint.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,40 @@ def is_production_filename(filename):
8888
def get_files_for_linting():
8989
"""Gets a list of files in the repository.
9090
91-
By default returns all files via `git ls-files`. However, if the
92-
environment variables `GCLOUD_REMOTE_FOR_LINT` and `GCLOUD_BRANCH_FOR_LINT`
93-
are set, this will return only those files which have changed since
94-
the last commit in `REMOTE_FOR_LINT/BRANCH_FOR_LINT`
91+
By default, returns all files via `git ls-files`. However, in some cases
92+
uses a specific commit or branch (a so-called diff base) to compare
93+
against for changed files.
94+
95+
To speed up linting on Travis pull requests against master, we manually
96+
set the diff base to origin/master. We don't do this on non-pull requests
97+
since origin/master will be equivalent to the currently checked out code.
98+
One could potentially use ${TRAVIS_COMMIT_RANGE} to find a diff base but
99+
this value is not dependable.
100+
101+
To allow faster local `tox` runs, the environment variables
102+
`GCLOUD_REMOTE_FOR_LINT` and `GCLOUD_BRANCH_FOR_LINT` can be set to specify
103+
a remote branch to diff against.
95104
"""
96-
remote = os.getenv('GCLOUD_REMOTE_FOR_LINT')
97-
branch = os.getenv('GCLOUD_BRANCH_FOR_LINT')
98-
99-
if remote is None or branch is None:
100-
print 'Remote branch not specified, listing all files in repository.'
105+
diff_base = None
106+
if (os.getenv('TRAVIS_BRANCH') == 'master' and
107+
os.getenv('TRAVIS_PULL_REQUEST') != 'false'):
108+
# In the case of a pull request into master, we want to
109+
# diff against HEAD in master.
110+
diff_base = 'origin/master'
111+
elif os.getenv('TRAVIS') is None:
112+
# Only allow specified remote and branch in local dev.
113+
remote = os.getenv('GCLOUD_REMOTE_FOR_LINT')
114+
branch = os.getenv('GCLOUD_BRANCH_FOR_LINT')
115+
if remote is not None and branch is not None:
116+
diff_base = '%s/%s' % (remote, branch)
117+
118+
if diff_base is None:
119+
print 'Diff base not specified, listing all files in repository.'
101120
result = subprocess.check_output(['git', 'ls-files'])
102121
else:
103-
remote_branch = '%s/%s' % (remote, branch)
104122
result = subprocess.check_output(['git', 'diff', '--name-only',
105-
remote_branch])
106-
print 'Using files changed relative to %s:' % (remote_branch,)
123+
diff_base])
124+
print 'Using files changed relative to %s:' % (diff_base,)
107125
print '-' * 60
108126
print result.rstrip('\n') # Don't print trailing newlines.
109127
print '-' * 60

0 commit comments

Comments
 (0)