1- import { access } from 'node:fs/promises' ;
21import { platform } from 'node:os' ;
32import { join } from 'node:path' ;
43import process from 'node:process' ;
@@ -9,6 +8,7 @@ import which from 'which';
98
109import type { Runtime } from '../useCwdProject.js' ;
1110import { normalizeExecutablePath } from './utils.js' ;
11+ import { cliDebugPrint } from '../../utils/cliDebugPrint.js' ;
1212
1313const cwdCache = new Map < string , Option < Runtime > > ( ) ;
1414
@@ -44,6 +44,7 @@ export async function usePythonRuntime({
4444 const cached = cwdCache . get ( cwd ) ;
4545
4646 if ( cached && ! force ) {
47+ cliDebugPrint ( 'usePythonRuntime' , { cacheHit : true , cwd, runtime : cached . unwrapOr ( null ) } ) ;
4748 return cached ;
4849 }
4950
@@ -62,8 +63,6 @@ export async function usePythonRuntime({
6263 fullPythonVenvPath = normalizeExecutablePath ( fullPythonVenvPath ) ;
6364
6465 try {
65- await access ( fullPythonVenvPath ) ;
66-
6766 const version = await getPythonVersion ( fullPythonVenvPath ) ;
6867
6968 if ( version ) {
@@ -75,10 +74,9 @@ export async function usePythonRuntime({
7574 } ) ,
7675 ) ;
7776
78- return some ( {
79- executablePath : fullPythonVenvPath ,
80- version,
81- } ) ;
77+ cliDebugPrint ( 'usePythonRuntime' , { cacheHit : false , cwd, runtime : cwdCache . get ( cwd ) ?. unwrap ( ) } ) ;
78+
79+ return cwdCache . get ( cwd ) ! ;
8280 }
8381 } catch {
8482 // Ignore errors
@@ -101,10 +99,9 @@ export async function usePythonRuntime({
10199 } ) ,
102100 ) ;
103101
104- return some ( {
105- executablePath : fullPath ,
106- version,
107- } ) ;
102+ cliDebugPrint ( 'usePythonRuntime' , { cacheHit : false , cwd, runtime : cwdCache . get ( cwd ) ?. unwrap ( ) } ) ;
103+
104+ return cwdCache . get ( cwd ) ! ;
108105 }
109106 } catch {
110107 // Continue
@@ -113,5 +110,7 @@ export async function usePythonRuntime({
113110
114111 cwdCache . set ( cwd , none ) ;
115112
113+ cliDebugPrint ( 'usePythonRuntime' , { cacheHit : false , cwd, runtime : null } ) ;
114+
116115 return none ;
117116}
0 commit comments