Skip to content

Commit 1860c56

Browse files
committed
fix(vscode): make work better with venvs
1 parent a149d13 commit 1860c56

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

vscode/extension/src/utilities/common/python.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { commands, Disposable, Event, EventEmitter, Uri } from 'vscode'
55
import { traceError, traceLog } from './log'
66
import { PythonExtension, ResolvedEnvironment } from '@vscode/python-extension'
77
import path from 'path'
8-
import { IS_WINDOWS } from '../isWindows'
98

109
export interface IInterpreterDetails {
1110
path?: string[]
@@ -39,15 +38,16 @@ export async function initializePython(
3938
api.environments.onDidChangeActiveEnvironmentPath(async e => {
4039
const environment = await api.environments.resolveEnvironment(e.path)
4140
const isVirtualEnv = environment?.environment !== undefined
42-
const binPath = isVirtualEnv
43-
? environment?.environment?.folderUri.fsPath
41+
// Get the directory of the Python executable for virtual environments
42+
const pythonDir = environment?.executable.uri
43+
? path.dirname(environment.executable.uri.fsPath)
4444
: undefined
4545

4646
onDidChangePythonInterpreterEvent.fire({
4747
path: [e.path],
4848
resource: e.resource?.uri,
4949
isVirtualEnvironment: isVirtualEnv,
50-
binPath,
50+
binPath: isVirtualEnv ? pythonDir : undefined,
5151
})
5252
}),
5353
)
@@ -76,17 +76,16 @@ export async function getInterpreterDetails(
7676
)
7777
if (environment?.executable.uri && checkVersion(environment)) {
7878
const isVirtualEnv = environment.environment !== undefined
79-
const binPath = isVirtualEnv
80-
? environment.environment?.folderUri.fsPath
81-
: undefined
79+
// Get the directory of the Python executable
80+
const pythonDir = path.dirname(environment?.executable.uri.fsPath)
8281

8382
return {
8483
path: [environment?.executable.uri.fsPath],
8584
resource,
8685
isVirtualEnvironment: isVirtualEnv,
87-
binPath: binPath
88-
? path.join(binPath, IS_WINDOWS ? 'Scripts' : 'bin')
89-
: undefined,
86+
// For virtual environments, we need to point directly to the bin directory
87+
// rather than constructing it from the environment folder
88+
binPath: isVirtualEnv ? pythonDir : undefined,
9089
}
9190
}
9291
return { path: undefined, resource }

vscode/extension/src/utilities/sqlmesh/sqlmesh.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export const sqlmeshExec = async (): Promise<
230230
workspacePath,
231231
env: {
232232
PYTHONPATH: interpreterDetails.path?.[0],
233-
VIRTUAL_ENV: path.dirname(interpreterDetails.binPath!),
233+
VIRTUAL_ENV: path.dirname(path.dirname(interpreterDetails.binPath!)), // binPath now points to bin dir
234234
PATH: interpreterDetails.binPath!,
235235
},
236236
args: [],
@@ -347,8 +347,8 @@ export const sqlmeshLspExec = async (): Promise<
347347
workspacePath,
348348
env: {
349349
PYTHONPATH: interpreterDetails.path?.[0],
350-
VIRTUAL_ENV: path.dirname(interpreterDetails.binPath!),
351-
PATH: path.join(path.dirname(interpreterDetails.binPath!), 'bin'),
350+
VIRTUAL_ENV: path.dirname(path.dirname(interpreterDetails.binPath!)), // binPath now points to bin dir
351+
PATH: interpreterDetails.binPath!, // binPath already points to the bin directory
352352
},
353353
args: [],
354354
})

0 commit comments

Comments
 (0)