2929import subprocess
3030import sys
3131
32- from script_utils import LOCAL_BRANCH_ENV
33- from script_utils import LOCAL_REMOTE_ENV
34- from script_utils import in_travis
35- from script_utils import in_travis_pr
36- from script_utils import travis_branch
32+ from script_utils import get_affected_files
3733
3834
3935IGNORED_DIRECTORIES = [
@@ -141,62 +137,10 @@ def is_production_filename(filename):
141137 return 'test' not in filename and 'docs' not in filename
142138
143139
144- def get_files_for_linting (allow_limited = True ):
145- """Gets a list of files in the repository.
146-
147- By default, returns all files via ``git ls-files``. However, in some cases
148- uses a specific commit or branch (a so-called diff base) to compare
149- against for changed files. (This requires ``allow_limited=True``.)
150-
151- To speed up linting on Travis pull requests against master, we manually
152- set the diff base to the branch the pull request is against. We don't do
153- this on "push" builds since "master" will be the currently checked out
154- code. One could potentially use ${TRAVIS_COMMIT_RANGE} to find a diff base
155- but this value is not dependable.
156-
157- To allow faster local ``tox`` runs, the local remote and local branch
158- environment variables can be set to specify a remote branch to diff
159- against.
160-
161- :type allow_limited: bool
162- :param allow_limited: Boolean indicating if a reduced set of files can
163- be used.
164-
165- :rtype: pair
166- :returns: Tuple of the diff base using the the list of filenames to be
167- linted.
168- """
169- diff_base = None
170- if in_travis ():
171- # In the case of a pull request into a branch, we want to
172- # diff against HEAD in that branch.
173- if in_travis_pr ():
174- diff_base = travis_branch ()
175- else :
176- # Only allow specified remote and branch in local dev.
177- remote = os .getenv (LOCAL_REMOTE_ENV )
178- branch = os .getenv (LOCAL_BRANCH_ENV )
179- if remote is not None and branch is not None :
180- diff_base = '%s/%s' % (remote , branch )
181-
182- if diff_base is not None and allow_limited :
183- result = subprocess .check_output (['git' , 'diff' , '--name-only' ,
184- diff_base ])
185- print ('Using files changed relative to %s:' % (diff_base ,))
186- print ('-' * 60 )
187- print (result .rstrip ('\n ' )) # Don't print trailing newlines.
188- print ('-' * 60 )
189- else :
190- print ('Diff base not specified, listing all files in repository.' )
191- result = subprocess .check_output (['git' , 'ls-files' ])
192-
193- return result .rstrip ('\n ' ).split ('\n ' ), diff_base
194-
195-
196140def get_python_files (all_files = None ):
197141 """Gets a list of all Python files in the repository that need linting.
198142
199- Relies on :func:`get_files_for_linting ()` to determine which files should
143+ Relies on :func:`get_affected_files ()` to determine which files should
200144 be considered.
201145
202146 NOTE: This requires ``git`` to be installed and requires that this
@@ -210,7 +154,7 @@ def get_python_files(all_files=None):
210154 contains all production files, the next all test files.
211155 """
212156 if all_files is None :
213- all_files , diff_base = get_files_for_linting ()
157+ all_files , diff_base = get_affected_files ()
214158
215159 library_files = []
216160 non_library_files = []
0 commit comments