|
15 | 15 | REQ_OLD_PIP = 'pip==7.1.2'
|
16 | 16 | REQ_OLD_SETUPTOOLS = 'setuptools==18.5'
|
17 | 17 |
|
18 |
| - |
19 |
| -try: |
20 |
| - # Python 3.3 |
21 |
| - from shutil import which |
22 |
| -except ImportError: |
23 |
| - # Backport shutil.which() from Python 3.6 |
24 |
| - def which(cmd, mode=os.F_OK | os.X_OK, path=None): |
25 |
| - """Given a command, mode, and a PATH string, return the path which |
26 |
| - conforms to the given mode on the PATH, or None if there is no such |
27 |
| - file. |
28 |
| -
|
29 |
| - `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result |
30 |
| - of os.environ.get("PATH"), or can be overridden with a custom search |
31 |
| - path. |
32 |
| -
|
33 |
| - """ |
34 |
| - # Check that a given file can be accessed with the correct mode. |
35 |
| - # Additionally check that `file` is not a directory, as on Windows |
36 |
| - # directories pass the os.access check. |
37 |
| - def _access_check(fn, mode): |
38 |
| - return (os.path.exists(fn) and os.access(fn, mode) |
39 |
| - and not os.path.isdir(fn)) |
40 |
| - |
41 |
| - # If we're given a path with a directory part, look it up directly rather |
42 |
| - # than referring to PATH directories. This includes checking relative to the |
43 |
| - # current directory, e.g. ./script |
44 |
| - if os.path.dirname(cmd): |
45 |
| - if _access_check(cmd, mode): |
46 |
| - return cmd |
47 |
| - return None |
48 |
| - |
49 |
| - if path is None: |
50 |
| - path = os.environ.get("PATH", os.defpath) |
51 |
| - if not path: |
52 |
| - return None |
53 |
| - path = path.split(os.pathsep) |
54 |
| - |
55 |
| - if sys.platform == "win32": |
56 |
| - # The current directory takes precedence on Windows. |
57 |
| - if os.curdir not in path: |
58 |
| - path.insert(0, os.curdir) |
59 |
| - |
60 |
| - # PATHEXT is necessary to check on Windows. |
61 |
| - pathext = os.environ.get("PATHEXT", "").split(os.pathsep) |
62 |
| - # See if the given file matches any of the expected path extensions. |
63 |
| - # This will allow us to short circuit when given "python.exe". |
64 |
| - # If it does match, only test that one, otherwise we have to try |
65 |
| - # others. |
66 |
| - if any(cmd.lower().endswith(ext.lower()) for ext in pathext): |
67 |
| - files = [cmd] |
68 |
| - else: |
69 |
| - files = [cmd + ext for ext in pathext] |
70 |
| - else: |
71 |
| - # On other platforms you don't have things like PATHEXT to tell you |
72 |
| - # what file suffixes are executable, so just pass on cmd as-is. |
73 |
| - files = [cmd] |
74 |
| - |
75 |
| - seen = set() |
76 |
| - for dir in path: |
77 |
| - normdir = os.path.normcase(dir) |
78 |
| - if normdir not in seen: |
79 |
| - seen.add(normdir) |
80 |
| - for thefile in files: |
81 |
| - name = os.path.join(dir, thefile) |
82 |
| - if _access_check(name, mode): |
83 |
| - return name |
84 |
| - return None |
85 |
| - |
86 |
| - |
87 | 18 | PERFORMANCE_ROOT = os.path.realpath(os.path.dirname(__file__))
|
88 | 19 |
|
89 | 20 |
|
|
0 commit comments