11import path from 'path'
22import { traceInfo , traceLog , traceVerbose } from '../common/log'
3- import { getInterpreterDetails } from '../common/python'
3+ import { getInterpreterDetails , getPythonEnvVariables } from '../common/python'
44import { Result , err , isErr , ok } from '@bus/result'
55import { getProjectRoot } from '../common/utilities'
66import { isPythonModuleInstalled } from '../python'
@@ -230,6 +230,13 @@ export const sqlmeshExec = async (): Promise<
230230 message : resolvedPath . error ,
231231 } )
232232 }
233+ const envVariables = await getPythonEnvVariables ( )
234+ if ( isErr ( envVariables ) ) {
235+ return err ( {
236+ type : 'generic' ,
237+ message : envVariables . error ,
238+ } )
239+ }
233240 const workspacePath = resolvedPath . value
234241 const interpreterDetails = await getInterpreterDetails ( )
235242 traceLog ( `Interpreter details: ${ JSON . stringify ( interpreterDetails ) } ` )
@@ -271,6 +278,8 @@ export const sqlmeshExec = async (): Promise<
271278 PYTHONPATH : interpreterDetails . path ?. [ 0 ] ,
272279 VIRTUAL_ENV : path . dirname ( interpreterDetails . binPath ! ) ,
273280 PATH : interpreterDetails . binPath ! ,
281+ ...process . env ,
282+ ...envVariables . value ,
274283 } ,
275284 args : [ ] ,
276285 } )
@@ -284,6 +293,8 @@ export const sqlmeshExec = async (): Promise<
284293 PYTHONPATH : interpreterDetails . path ?. [ 0 ] ,
285294 VIRTUAL_ENV : path . dirname ( path . dirname ( interpreterDetails . binPath ! ) ) , // binPath now points to bin dir
286295 PATH : interpreterDetails . binPath ! ,
296+ ...process . env ,
297+ ...envVariables . value ,
287298 } ,
288299 args : [ ] ,
289300 } )
@@ -297,7 +308,10 @@ export const sqlmeshExec = async (): Promise<
297308 return ok ( {
298309 bin : sqlmesh ,
299310 workspacePath,
300- env : { } ,
311+ env : {
312+ ...process . env ,
313+ ...envVariables . value ,
314+ } ,
301315 args : [ ] ,
302316 } )
303317 }
@@ -353,6 +367,13 @@ export const sqlmeshLspExec = async (): Promise<
353367> => {
354368 const sqlmeshLSP = IS_WINDOWS ? 'sqlmesh_lsp.exe' : 'sqlmesh_lsp'
355369 const projectRoot = await getProjectRoot ( )
370+ const envVariables = await getPythonEnvVariables ( )
371+ if ( isErr ( envVariables ) ) {
372+ return err ( {
373+ type : 'generic' ,
374+ message : envVariables . error ,
375+ } )
376+ }
356377 const resolvedPath = resolveProjectPath ( projectRoot )
357378 if ( isErr ( resolvedPath ) ) {
358379 return err ( {
@@ -408,6 +429,8 @@ export const sqlmeshLspExec = async (): Promise<
408429 PYTHONPATH : interpreterDetails . path ?. [ 0 ] ,
409430 VIRTUAL_ENV : path . dirname ( interpreterDetails . binPath ! ) ,
410431 PATH : interpreterDetails . binPath ! ,
432+ ...process . env ,
433+ ...envVariables . value ,
411434 } ,
412435 args : [ 'sqlmesh_lsp' ] ,
413436 } )
@@ -431,6 +454,8 @@ export const sqlmeshLspExec = async (): Promise<
431454 PYTHONPATH : interpreterDetails . path ?. [ 0 ] ,
432455 VIRTUAL_ENV : path . dirname ( path . dirname ( interpreterDetails . binPath ! ) ) , // binPath now points to bin dir
433456 PATH : interpreterDetails . binPath ! , // binPath already points to the bin directory
457+ ...process . env ,
458+ ...envVariables . value ,
434459 } ,
435460 args : [ ] ,
436461 } )
@@ -444,7 +469,10 @@ export const sqlmeshLspExec = async (): Promise<
444469 return ok ( {
445470 bin : sqlmeshLSP ,
446471 workspacePath,
447- env : { } ,
472+ env : {
473+ ...process . env ,
474+ ...envVariables . value ,
475+ } ,
448476 args : [ ] ,
449477 } )
450478 }
0 commit comments