@@ -69,6 +69,7 @@ export async function getPythonEnvironmentExtensionAPI(): Promise<PythonEnvironm
6969}
7070
7171export async function initializePython ( disposables : Disposable [ ] ) : Promise < void > {
72+ traceLog ( `initializePython: usingEnvExt='${ useEnvExtension ( ) } '` ) ;
7273 if ( ! useEnvExtension ( ) ) {
7374 await legacyInitializePython ( disposables , onDidChangePythonInterpreterEvent ) ;
7475 } else {
@@ -78,13 +79,16 @@ export async function initializePython(disposables: Disposable[]): Promise<void>
7879 disposables . push (
7980 api . onDidChangeEnvironments ( async ( ) => {
8081 // not sure if this is the right event....
81- onDidChangePythonInterpreterEvent . fire ( await getInterpreterDetails ( ) ) ;
82- traceLog ( 'Python environments changed.' ) ;
82+ const details = await getInterpreterDetails ( ) ;
83+ traceLog ( `initializePython:onDidChangeEnvironments fired executable='${ details . path ?. [ 0 ] } '` ) ;
84+ onDidChangePythonInterpreterEvent . fire ( details ) ;
85+ traceLog ( 'Python environments changed event processed.' ) ;
8386 } ) ,
8487 ) ;
8588
8689 traceLog ( 'Waiting for interpreter from python environments extension.' ) ;
8790 onDidChangePythonInterpreterEvent . fire ( await getInterpreterDetails ( ) ) ;
91+ traceLog ( 'initializePython: Initial interpreter details fired (env extension path)' ) ;
8892 }
8993 } catch ( error ) {
9094 traceError ( 'Error initializing python: ' , error ) ;
@@ -94,6 +98,7 @@ export async function initializePython(disposables: Disposable[]): Promise<void>
9498
9599export async function runPythonExtensionCommand ( command : string , ...rest : any [ ] ) {
96100 await activateExtensions ( ) ;
101+ traceLog ( `runPythonExtensionCommand: executing command='${ command } ' argsCount='${ rest . length } '` ) ;
97102 return await commands . executeCommand ( command , ...rest ) ;
98103}
99104
@@ -113,21 +118,33 @@ export async function getSettingsPythonPath(resource?: Uri): Promise<string[] |
113118 let pyEnv = await api . getEnvironment ( resource ) ;
114119
115120 if ( ! pyEnv ) {
121+ traceLog ( `getSettingsPythonPath: No environment for resource='${ resource ?. fsPath } '` ) ;
116122 return undefined ;
117123 }
118124
119125 // Resolve environment if execution info is not available
120126 if ( ! pyEnv . execInfo ) {
121127 pyEnv = await api . resolveEnvironment ( pyEnv . environmentPath ) ;
128+ traceLog (
129+ `getSettingsPythonPath: Resolved environment execInfo for '${
130+ pyEnv ?. environmentPath . fsPath || 'undefined'
131+ } '`,
132+ ) ;
122133 }
123134
124135 // Extract execution command from resolved environment
125136 const execInfo = pyEnv ?. execInfo ;
126137 if ( ! execInfo ) {
138+ traceLog ( 'getSettingsPythonPath: Missing execInfo after resolution' ) ;
127139 return undefined ;
128140 }
129141
130142 const runConfig = execInfo . activatedRun ?? execInfo . run ;
143+ traceLog (
144+ `getSettingsPythonPath: Using executable='${ runConfig . executable } ' args='${
145+ runConfig . args ?. join ( ' ' ) || ''
146+ } '`,
147+ ) ;
131148 return runConfig . args ? [ runConfig . executable , ...runConfig . args ] : [ runConfig . executable ] ;
132149 }
133150} // should I make this more async? rn it just becomes sync
@@ -157,10 +174,12 @@ export async function resolveEnvironment(
157174 : 'Unknown' ;
158175 const execUri = legacyResolvedEnv ?. executable . uri ;
159176 if ( execUri === undefined ) {
177+ traceLog ( 'resolveEnvironment: legacy path invalid (no executable uri)' ) ;
160178 // Should return undefined for invalid environment
161179 return undefined ;
162180 }
163181 if ( legacyResolvedEnv ) {
182+ traceLog ( `resolveEnvironment: legacy resolved executable='${ execUri . fsPath } ' version='${ pythonVersion } '` ) ;
164183 const pythonEnv : PythonEnvironment = {
165184 envId : {
166185 id : execUri . fsPath ,
@@ -187,11 +206,14 @@ export async function resolveEnvironment(
187206 // Handle different input types for the new API
188207 if ( typeof env === 'string' ) {
189208 // Convert string path to Uri for the new API
209+ traceLog ( `resolveEnvironment: new API resolving from string='${ env } '` ) ;
190210 return api . resolveEnvironment ( Uri . file ( env ) ) ;
191211 } else if ( typeof env === 'object' && 'path' in env ) {
192212 // EnvironmentPath has a uri property
213+ traceLog ( `resolveEnvironment: new API resolving from EnvironmentPath='${ env . path } '` ) ;
193214 return api . resolveEnvironment ( Uri . file ( env . path ) ) ;
194215 } else {
216+ traceLog ( 'resolveEnvironment: new API unsupported env input' ) ;
195217 return undefined ;
196218 }
197219 }
@@ -204,6 +226,7 @@ export async function getActiveEnvironmentPath(
204226 //TODO: fix this return type??
205227 if ( ! useEnvExtension ( ) ) {
206228 const envPath : EnvironmentPath = await legacyGetActiveEnvironmentPath ( resource ) ;
229+ traceLog ( `getActiveEnvironmentPath: legacy active path='${ envPath . path } '` ) ;
207230 return envPath ;
208231 } else {
209232 const api = await getPythonEnvironmentExtensionAPI ( ) ;
@@ -213,6 +236,9 @@ export async function getActiveEnvironmentPath(
213236 resource instanceof Uri ? resource : resource && 'uri' in resource ? resource . uri : undefined ;
214237
215238 const env = await api . getEnvironment ( resourceUri ) ;
239+ traceLog (
240+ `getActiveEnvironmentPath: new API envPath='${ env ?. environmentPath . fsPath } ' resource='${ resourceUri ?. fsPath } '` ,
241+ ) ;
216242 return env ;
217243 }
218244}
@@ -245,6 +271,7 @@ export async function getInterpreterDetails(resource?: Uri): Promise<IInterprete
245271 path : executablePath ? [ executablePath ] : undefined ,
246272 resource,
247273 } ;
274+ traceLog ( `getInterpreterDetails: resource='${ resource ?. fsPath } ' executable='${ executablePath } '` ) ;
248275 return a ;
249276 }
250277}
0 commit comments