Skip to content

Commit 349534b

Browse files
committed
fix(vscode): make work better with venvs (#4482)
1 parent 9d86f89 commit 349534b

5 files changed

Lines changed: 48 additions & 15 deletions

File tree

.circleci/continue_config.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,36 @@ commands:
3737
- run: circleci-agent step halt
3838

3939
jobs:
40+
vscode_e2e_test:
41+
docker:
42+
- image: cimg/node:20.19.1-browsers
43+
resource_class: medium
44+
steps:
45+
- checkout
46+
- run:
47+
name: Create Python venv
48+
command: |
49+
python -m venv venv
50+
. ./venv/bin/activate
51+
- run:
52+
name: Install Python dependencies
53+
command: |
54+
python -m pip install --upgrade pip
55+
make install-dev
56+
- run:
57+
name: Install Dependencies
58+
command: |
59+
pnpm install
60+
- run:
61+
name: Install VSCode
62+
command: |
63+
cd vscode/extension
64+
pnpm run fetch-vscode
65+
- run:
66+
name: Run VSCode extension tests
67+
command: |
68+
cd vscode/extension
69+
pnpm run test:e2e:ci
4070
vscode_test:
4171
docker:
4272
- image: cimg/node:20.19.1-browsers

vscode/extension/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"test:e2e": "playwright test",
8989
"test:e2e:ui": "playwright test --ui",
9090
"test:e2e:headed": "playwright test --headed",
91+
"test:e2e:ci": "xvfb-run --server-args=\"-screen 0 1280x720x24\" npx playwright test --reporter=line,junit",
9192
"fetch-vscode": "tsx scripts/fetch-vscode.ts",
9293
"compile": "pnpm run check-types && node esbuild.js",
9394
"check-types": "tsc --noEmit",

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/exec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function execAsync(
1313
options: ExecOptions & { signal?: AbortSignal } = {},
1414
): Promise<ExecResult> {
1515
const fullCmd = `${command} ${args.join(' ')}`
16-
traceInfo(`Executing command: ${fullCmd}`)
16+
traceInfo(`Executing command: ${fullCmd} in ${options.cwd}`)
1717

1818
try {
1919
const result = await execAsyncCore(command, args, options)

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ export const isSqlmeshEnterpriseInstalled = async (): Promise<
8282
if (isErr(tcloudBin)) {
8383
return tcloudBin
8484
}
85-
const called = await execAsync(tcloudBin.value, ['is_sqlmesh_installed'])
85+
const projectRoot = await getProjectRoot()
86+
const called = await execAsync(tcloudBin.value, ['is_sqlmesh_installed'], {
87+
cwd: projectRoot.uri.fsPath,
88+
})
8689
if (called.exitCode !== 0) {
8790
return err({
8891
type: 'generic',
@@ -232,7 +235,7 @@ export const sqlmeshExec = async (): Promise<
232235
workspacePath,
233236
env: {
234237
PYTHONPATH: interpreterDetails.path?.[0],
235-
VIRTUAL_ENV: path.dirname(interpreterDetails.binPath!),
238+
VIRTUAL_ENV: path.dirname(path.dirname(interpreterDetails.binPath!)), // binPath now points to bin dir
236239
PATH: interpreterDetails.binPath!,
237240
},
238241
args: [],
@@ -349,8 +352,8 @@ export const sqlmeshLspExec = async (): Promise<
349352
workspacePath,
350353
env: {
351354
PYTHONPATH: interpreterDetails.path?.[0],
352-
VIRTUAL_ENV: path.dirname(interpreterDetails.binPath!),
353-
PATH: path.join(path.dirname(interpreterDetails.binPath!), 'bin'),
355+
VIRTUAL_ENV: path.dirname(path.dirname(interpreterDetails.binPath!)), // binPath now points to bin dir
356+
PATH: interpreterDetails.binPath!, // binPath already points to the bin directory
354357
},
355358
args: [],
356359
})

0 commit comments

Comments
 (0)