|
29 | 29 | import subprocess |
30 | 30 | import sys |
31 | 31 |
|
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_files_for_linting |
37 | 33 |
|
38 | 34 |
|
39 | 35 | IGNORED_DIRECTORIES = [ |
@@ -141,58 +137,6 @@ def is_production_filename(filename): |
141 | 137 | return 'test' not in filename and 'docs' not in filename |
142 | 138 |
|
143 | 139 |
|
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 | | - |
196 | 140 | def get_python_files(all_files=None): |
197 | 141 | """Gets a list of all Python files in the repository that need linting. |
198 | 142 |
|
|
0 commit comments