22
22
import argparse
23
23
import logging
24
24
import os
25
- import re
26
25
import subprocess
27
26
import sys
28
27
import textwrap
@@ -144,7 +143,7 @@ def lint_py(files):
144
143
_flake8_warned = True
145
144
_logger .warn (textwrap .dedent (
146
145
"""
147
- Could not find flake8 on the path ; skipping python lint.
146
+ Could not find flake8 on $PATH ; skipping python lint.
148
147
Install with:
149
148
150
149
pip install --user flake8
@@ -182,41 +181,6 @@ def _unique(items):
182
181
return list (set (items ))
183
182
184
183
185
- def make_path ():
186
- """Makes a list of paths to search for binaries.
187
-
188
- Returns:
189
- A list of directories that can be sources of binaries to run. This includes
190
- both the PATH environment variable and any bin directories associated with
191
- python install locations.
192
- """
193
- # Start with the system-supplied PATH.
194
- path = os .environ ['PATH' ].split (os .pathsep )
195
-
196
- # In addition, add any bin directories near the lib directories in the python
197
- # path. This makes it possible to find flake8 in ~/Library/Python/2.7/bin
198
- # after pip install --user flake8. Also handle installations on Windows which
199
- # go in %APPDATA%/Python/Scripts.
200
- lib_pattern = re .compile (r'(.*)/[^/]*/site-packages' )
201
- for entry in sys .path :
202
- entry = entry .replace (os .sep , '/' )
203
- m = lib_pattern .match (entry )
204
- if not m :
205
- continue
206
-
207
- python_root = m .group (1 ).replace ('/' , os .sep )
208
-
209
- for bin_basename in ('bin' , 'Scripts' ):
210
- bin_dir = os .path .join (python_root , bin_basename )
211
- if bin_dir not in path and os .path .exists (bin_dir ):
212
- path .append (bin_dir )
213
-
214
- return path
215
-
216
-
217
- _PATH = make_path ()
218
-
219
-
220
184
def which (executable ):
221
185
"""Finds the executable with the given name.
222
186
@@ -227,8 +191,10 @@ def which(executable):
227
191
if executable .startswith ('/' ):
228
192
return executable
229
193
194
+ path = os .environ ['PATH' ].split (os .pathsep )
195
+
230
196
for executable_with_ext in _executable_names (executable ):
231
- for entry in _PATH :
197
+ for entry in path :
232
198
joined = os .path .join (entry , executable_with_ext )
233
199
if os .path .isfile (joined ) and os .access (joined , os .X_OK ):
234
200
return joined
0 commit comments