Skip to content

Commit 9a732ae

Browse files
authored
fix(vscode): allow uv pip executable called through tcloud (#4766)
1 parent c8ae8a8 commit 9a732ae

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

vscode/extension/src/auth/auth.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ export class AuthenticationProviderTobikoCloud
7979
}
8080
const tcloudBinPath = tcloudBin.value
8181
const result = await execAsync(
82-
tcloudBinPath,
82+
tcloudBinPath.bin,
8383
['auth', 'vscode', 'status'],
8484
{
8585
cwd: workspacePath.uri.fsPath,
86+
env: tcloudBinPath.env,
8687
},
8788
)
8889
if (result.exitCode !== 0) {
@@ -162,8 +163,9 @@ export class AuthenticationProviderTobikoCloud
162163
throw new Error('Failed to get tcloud bin')
163164
}
164165
const tcloudBinPath = tcloudBin.value
165-
const result = await execAsync(tcloudBinPath, ['auth', 'logout'], {
166+
const result = await execAsync(tcloudBinPath.bin, ['auth', 'logout'], {
166167
cwd: workspacePath.uri.fsPath,
168+
env: tcloudBinPath.env,
167169
})
168170
if (result.exitCode !== 0) {
169171
throw new Error('Failed to logout from tcloud')
@@ -187,7 +189,7 @@ export class AuthenticationProviderTobikoCloud
187189
}
188190
const tcloudBinPath = tcloudBin.value
189191
const result = await execAsync(
190-
tcloudBinPath,
192+
tcloudBinPath.bin,
191193
['auth', 'vscode', 'login-url'],
192194
{
193195
cwd: workspacePath.uri.fsPath,
@@ -214,11 +216,12 @@ export class AuthenticationProviderTobikoCloud
214216
1000 * 60 * 5,
215217
)
216218
const backgroundServerForLogin = execAsync(
217-
tcloudBinPath,
219+
tcloudBinPath.bin,
218220
['auth', 'vscode', 'start-server', urlCode.verifier_code],
219221
{
220222
cwd: workspacePath.uri.fsPath,
221223
signal: ac.signal,
224+
env: tcloudBinPath.env,
222225
},
223226
)
224227

@@ -283,10 +286,11 @@ export class AuthenticationProviderTobikoCloud
283286
}
284287
const tcloudBinPath = tcloudBin.value
285288
const result = await execAsync(
286-
tcloudBinPath,
289+
tcloudBinPath.bin,
287290
['auth', 'vscode', 'device'],
288291
{
289292
cwd: workspacePath.uri.fsPath,
293+
env: tcloudBinPath.env,
290294
},
291295
)
292296
if (result.exitCode !== 0) {
@@ -305,11 +309,12 @@ export class AuthenticationProviderTobikoCloud
305309
1000 * 60 * 5,
306310
)
307311
const waiting = execAsync(
308-
tcloudBinPath,
312+
tcloudBinPath.bin,
309313
['auth', 'vscode', 'poll_device', deviceCodeResponse.device_code],
310314
{
311315
cwd: workspacePath.uri.fsPath,
312316
signal: ac.signal,
317+
env: tcloudBinPath.env,
313318
},
314319
)
315320

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

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const isTcloudProject = async (): Promise<Result<boolean, string>> => {
5555
*
5656
* @returns The tcloud executable for the current Python environment.
5757
*/
58-
export const getTcloudBin = async (): Promise<Result<string, ErrorType>> => {
58+
export const getTcloudBin = async (): Promise<Result<SqlmeshExecInfo, ErrorType>> => {
5959
const tcloud = IS_WINDOWS ? 'tcloud.exe' : 'tcloud'
6060
const interpreterDetails = await getInterpreterDetails()
6161
if (!interpreterDetails.path) {
@@ -68,7 +68,25 @@ export const getTcloudBin = async (): Promise<Result<string, ErrorType>> => {
6868
if (!fs.existsSync(binPath)) {
6969
return err({type: 'tcloud_bin_not_found'})
7070
}
71-
return ok(binPath)
71+
const envVariables = await getPythonEnvVariables()
72+
if (isErr(envVariables)) {
73+
return err({
74+
type: 'generic',
75+
message: envVariables.error,
76+
})
77+
}
78+
return ok({
79+
bin: binPath,
80+
workspacePath: interpreterDetails.resource?.fsPath ?? '',
81+
env: {
82+
...process.env,
83+
...envVariables.value,
84+
PYTHONPATH: interpreterDetails.path[0],
85+
VIRTUAL_ENV: path.dirname(interpreterDetails.binPath!),
86+
PATH: interpreterDetails.binPath!,
87+
},
88+
args: [],
89+
})
7290
}
7391

7492
const isSqlmeshInstalledSchema = z.object({
@@ -96,8 +114,9 @@ export const isSqlmeshEnterpriseInstalled = async (): Promise<
96114
message: resolvedPath.error,
97115
})
98116
}
99-
const called = await execAsync(tcloudBin.value, ['is_sqlmesh_installed'], {
117+
const called = await execAsync(tcloudBin.value.bin, ['is_sqlmesh_installed'], {
100118
cwd: resolvedPath.value,
119+
env: tcloudBin.value.env,
101120
})
102121
if (called.exitCode !== 0) {
103122
return err({
@@ -135,9 +154,10 @@ export const installSqlmeshEnterprise = async (
135154
message: resolvedPath.error,
136155
})
137156
}
138-
const called = await execAsync(tcloudBin.value, ['install_sqlmesh'], {
157+
const called = await execAsync(tcloudBin.value.bin, ['install_sqlmesh'], {
139158
signal: abortController.signal,
140159
cwd: resolvedPath.value,
160+
env: tcloudBin.value.env,
141161
})
142162
if (called.exitCode !== 0) {
143163
return err({
@@ -272,16 +292,10 @@ export const sqlmeshExec = async (): Promise<
272292
return ensured
273293
}
274294
return ok({
275-
bin: `${tcloudBin.value} sqlmesh`,
295+
bin: tcloudBin.value.bin,
276296
workspacePath,
277-
env: {
278-
...process.env,
279-
...envVariables.value,
280-
PYTHONPATH: interpreterDetails.path?.[0],
281-
VIRTUAL_ENV: path.dirname(interpreterDetails.binPath!),
282-
PATH: interpreterDetails.binPath!,
283-
},
284-
args: [],
297+
env: tcloudBin.value.env,
298+
args: ["sqlmesh"],
285299
})
286300
}
287301
const binPath = path.join(interpreterDetails.binPath!, sqlmesh)
@@ -423,15 +437,9 @@ export const sqlmeshLspExec = async (): Promise<
423437
// TODO: Remove this once we have a stable version of tcloud that supports sqlmesh_lsp.
424438
if (isSemVerGreaterThanOrEqual(tcloudBinVersion.value, [2, 10, 1])) {
425439
return ok ({
426-
bin: tcloudBin.value,
440+
bin: tcloudBin.value.bin,
427441
workspacePath,
428-
env: {
429-
PYTHONPATH: interpreterDetails.path?.[0],
430-
VIRTUAL_ENV: path.dirname(interpreterDetails.binPath!),
431-
PATH: interpreterDetails.binPath!,
432-
...process.env,
433-
...envVariables.value,
434-
},
442+
env: tcloudBin.value.env,
435443
args: ['sqlmesh_lsp'],
436444
})
437445
}
@@ -503,7 +511,9 @@ async function getTcloudBinVersion(): Promise<Result<[number, number, number], E
503511
if (isErr(tcloudBin)) {
504512
return tcloudBin
505513
}
506-
const called = await execAsync(tcloudBin.value, ['--version'])
514+
const called = await execAsync(tcloudBin.value.bin, ['--version'], {
515+
env: tcloudBin.value.env,
516+
})
507517
if (called.exitCode !== 0) {
508518
return err({
509519
type: 'generic',

0 commit comments

Comments
 (0)