@@ -107,22 +107,29 @@ def is_production_filename(filename):
107107 or filename .startswith ('regression' ))
108108
109109
110- def get_files_for_linting ():
110+ def get_files_for_linting (allow_limited = True ):
111111 """Gets a list of files in the repository.
112112
113- By default, returns all files via `git ls-files`. However, in some cases
113+ By default, returns all files via `` git ls-files` `. However, in some cases
114114 uses a specific commit or branch (a so-called diff base) to compare
115- against for changed files.
115+ against for changed files. (This requires ``allow_limited=True``.)
116116
117117 To speed up linting on Travis pull requests against master, we manually
118118 set the diff base to origin/master. We don't do this on non-pull requests
119119 since origin/master will be equivalent to the currently checked out code.
120120 One could potentially use ${TRAVIS_COMMIT_RANGE} to find a diff base but
121121 this value is not dependable.
122122
123- To allow faster local `tox` runs, the environment variables
124- `GCLOUD_REMOTE_FOR_LINT` and `GCLOUD_BRANCH_FOR_LINT` can be set to specify
125- a remote branch to diff against.
123+ To allow faster local ``tox`` runs, the environment variables
124+ ``GCLOUD_REMOTE_FOR_LINT`` and ``GCLOUD_BRANCH_FOR_LINT`` can be set to
125+ specify a remote branch to diff against.
126+
127+ :type allow_limited: boolean
128+ :param allow_limited: Boolean indicating if a reduced set of files can
129+ be used.
130+
131+ :rtype: list
132+ :returns: List of filenames to be linted.
126133 """
127134 diff_base = None
128135 if (os .getenv ('TRAVIS_BRANCH' ) == 'master' and
@@ -137,34 +144,37 @@ def get_files_for_linting():
137144 if remote is not None and branch is not None :
138145 diff_base = '%s/%s' % (remote , branch )
139146
140- if diff_base is None :
141- print 'Diff base not specified, listing all files in repository.'
142- result = subprocess .check_output (['git' , 'ls-files' ])
143- else :
147+ if diff_base is not None and allow_limited :
144148 result = subprocess .check_output (['git' , 'diff' , '--name-only' ,
145149 diff_base ])
146150 print 'Using files changed relative to %s:' % (diff_base ,)
147151 print '-' * 60
148152 print result .rstrip ('\n ' ) # Don't print trailing newlines.
149153 print '-' * 60
154+ else :
155+ print 'Diff base not specified, listing all files in repository.'
156+ result = subprocess .check_output (['git' , 'ls-files' ])
150157
151158 return result .rstrip ('\n ' ).split ('\n ' )
152159
153160
154- def get_python_files ():
161+ def get_python_files (all_files = None ):
155162 """Gets a list of all Python files in the repository that need linting.
156163
157- Relies on get_files_for_linting() to determine which files should be
158- considered.
164+ Relies on :func:`get_files_for_linting()` to determine which files should
165+ be considered.
166+
167+ NOTE: This requires ``git`` to be installed and requires that this
168+ is run within the ``git`` repository.
159169
160- NOTE: This requires `git` to be installed and requires that this
161- is run within the `git` repository .
170+ :type all_files: list or ``NoneType``
171+ :param all_files: Optional list of files to be linted .
162172
163- :rtype: ` tuple`
173+ :rtype: tuple
164174 :returns: A tuple containing two lists. The first list contains
165175 all production files and the next all test/demo files.
166176 """
167- all_files = get_files_for_linting ()
177+ all_files = all_files or get_files_for_linting ()
168178
169179 library_files = []
170180 non_library_files = []
@@ -203,8 +213,17 @@ def main():
203213 """Script entry point. Lints both sets of files."""
204214 make_test_rc (PRODUCTION_RC , TEST_RC_ADDITIONS , TEST_RC )
205215 library_files , non_library_files = get_python_files ()
206- lint_fileset (library_files , PRODUCTION_RC , 'library code' )
207- lint_fileset (non_library_files , TEST_RC , 'test and demo code' )
216+ try :
217+ lint_fileset (library_files , PRODUCTION_RC , 'library code' )
218+ lint_fileset (non_library_files , TEST_RC , 'test and demo code' )
219+ except SystemExit :
220+ message = 'Restricted lint failed, expanding to full fileset.'
221+ print >> sys .stderr , message
222+ all_files = get_files_for_linting (allow_limited = False )
223+ library_files , non_library_files = get_python_files (
224+ all_files = all_files )
225+ lint_fileset (library_files , PRODUCTION_RC , 'library code' )
226+ lint_fileset (non_library_files , TEST_RC , 'test and demo code' )
208227
209228
210229if __name__ == '__main__' :
0 commit comments