MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / find_executable

Function find_executable

tools/python-3.11.9-amd64/Lib/distutils/spawn.py:95–129  ·  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

93
94
95def find_executable(executable, path=None):
96 """Tries to find 'executable' in the directories listed in 'path'.
97
98 A string listing directories separated by 'os.pathsep'; defaults to
99 os.environ['PATH']. Returns the complete filename or None if not found.
100 """
101 _, ext = os.path.splitext(executable)
102 if (sys.platform == 'win32') and (ext != '.exe'):
103 executable = executable + '.exe'
104
105 if os.path.isfile(executable):
106 return executable
107
108 if path is None:
109 path = os.environ.get('PATH', None)
110 if path is None:
111 try:
112 path = os.confstr("CS_PATH")
113 except (AttributeError, ValueError):
114 # os.confstr() or CS_PATH is not available
115 path = os.defpath
116 # bpo-35755: Don't use os.defpath if the PATH environment variable is
117 # set to an empty string
118
119 # PATH='' doesn't match, whereas PATH=':' looks in the current directory
120 if not path:
121 return None
122
123 paths = path.split(os.pathsep)
124 for p in paths:
125 f = os.path.join(p, executable)
126 if os.path.isfile(f):
127 # the file exists, we have a shot at spawn working
128 return f
129 return None

Callers 4

_find_exe_versionFunction · 0.90
test_find_executableMethod · 0.90
spawnFunction · 0.70

Calls 5

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

Tested by 1

test_find_executableMethod · 0.72