MCPcopy Index your code
hub / github.com/python/cpython / find_executable

Function find_executable

Tools/c-analyzer/distutils/spawn.py:14–48  ·  view source on GitHub ↗

Tries to find 'executable' in the directories listed in 'path'. A string listing directories separated by 'os.pathsep'; defaults to os.environ['PATH']. Returns the complete filename or None if not found.

(executable, path=None)

Source from the content-addressed store, hash-verified

12
13
14def find_executable(executable, path=None):
15 """Tries to find 'executable' in the directories listed in 'path'.
16
17 A string listing directories separated by 'os.pathsep'; defaults to
18 os.environ['PATH']. Returns the complete filename or None if not found.
19 """
20 _, ext = os.path.splitext(executable)
21 if (sys.platform == 'win32') and (ext != '.exe'):
22 executable = executable + '.exe'
23
24 if os.path.isfile(executable):
25 return executable
26
27 if path is None:
28 path = os.environ.get('PATH', None)
29 if path is None:
30 try:
31 path = os.confstr("CS_PATH")
32 except (AttributeError, ValueError):
33 # os.confstr() or CS_PATH is not available
34 path = os.defpath
35 # bpo-35755: Don't use os.defpath if the PATH environment variable is
36 # set to an empty string
37
38 # PATH='' doesn't match, whereas PATH=':' looks in the current directory
39 if not path:
40 return None
41
42 paths = path.split(os.pathsep)
43 for p in paths:
44 f = os.path.join(p, executable)
45 if os.path.isfile(f):
46 # the file exists, we have a shot at spawn working
47 return f
48 return None

Callers 1

_find_exe_versionFunction · 0.90

Calls 5

splitextMethod · 0.80
isfileMethod · 0.45
getMethod · 0.45
splitMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…