MCPcopy Index your code
hub / github.com/promptfoo/promptfoo / tryPath

Function tryPath

src/python/pythonUtils.ts:199–224  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

197 * @returns The validated path if successful, or null if invalid.
198 */
199export async function tryPath(path: string): Promise<string | null> {
200 let timeoutId: NodeJS.Timeout | undefined;
201
202 try {
203 const timeoutPromise = new Promise<never>((_, reject) => {
204 timeoutId = setTimeout(() => reject(new Error('Command timed out')), 2500);
205 });
206
207 const result = await Promise.race([execFileAsync(path, ['--version']), timeoutPromise]);
208
209 if (timeoutId) {
210 clearTimeout(timeoutId);
211 }
212
213 const versionOutput = (result as { stdout: string }).stdout.trim();
214 if (versionOutput.startsWith('Python')) {
215 return path;
216 }
217 return null;
218 } catch {
219 if (timeoutId) {
220 clearTimeout(timeoutId);
221 }
222 return null;
223 }
224}
225
226/**
227 * Validates and caches the Python executable path.

Callers 3

tryWindowsWhereFunction · 0.70
tryDirectCommandsFunction · 0.70
validatePythonPathFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…