1
1
import * as path from 'path' ;
2
- import { LogOutputChannel , QuickPickItem , Uri , window } from 'vscode' ;
2
+ import { CancellationError , CancellationToken , LogOutputChannel , QuickPickItem , Uri , window } from 'vscode' ;
3
3
import {
4
4
EnvironmentManager ,
5
5
Package ,
@@ -110,10 +110,20 @@ export async function isUvInstalled(log?: LogOutputChannel): Promise<boolean> {
110
110
return available . promise ;
111
111
}
112
112
113
- export async function runUV ( args : string [ ] , cwd ?: string , log ?: LogOutputChannel ) : Promise < string > {
113
+ export async function runUV (
114
+ args : string [ ] ,
115
+ cwd ?: string ,
116
+ log ?: LogOutputChannel ,
117
+ token ?: CancellationToken ,
118
+ ) : Promise < string > {
114
119
log ?. info ( `Running: uv ${ args . join ( ' ' ) } ` ) ;
115
120
return new Promise < string > ( ( resolve , reject ) => {
116
121
const proc = ch . spawn ( 'uv' , args , { cwd : cwd } ) ;
122
+ token ?. onCancellationRequested ( ( ) => {
123
+ proc . kill ( ) ;
124
+ reject ( new CancellationError ( ) ) ;
125
+ } ) ;
126
+
117
127
let builder = '' ;
118
128
proc . stdout ?. on ( 'data' , ( data ) => {
119
129
const s = data . toString ( 'utf-8' ) ;
@@ -134,10 +144,20 @@ export async function runUV(args: string[], cwd?: string, log?: LogOutputChannel
134
144
} ) ;
135
145
}
136
146
137
- export async function runPython ( python : string , args : string [ ] , cwd ?: string , log ?: LogOutputChannel ) : Promise < string > {
147
+ export async function runPython (
148
+ python : string ,
149
+ args : string [ ] ,
150
+ cwd ?: string ,
151
+ log ?: LogOutputChannel ,
152
+ token ?: CancellationToken ,
153
+ ) : Promise < string > {
138
154
log ?. info ( `Running: ${ python } ${ args . join ( ' ' ) } ` ) ;
139
155
return new Promise < string > ( ( resolve , reject ) => {
140
156
const proc = ch . spawn ( python , args , { cwd : cwd } ) ;
157
+ token ?. onCancellationRequested ( ( ) => {
158
+ proc . kill ( ) ;
159
+ reject ( new CancellationError ( ) ) ;
160
+ } ) ;
141
161
let builder = '' ;
142
162
proc . stdout ?. on ( 'data' , ( data ) => {
143
163
const s = data . toString ( 'utf-8' ) ;
@@ -312,6 +332,7 @@ export async function installPackages(
312
332
options : PackageInstallOptions ,
313
333
api : PythonEnvironmentApi ,
314
334
manager : PackageManager ,
335
+ token ?: CancellationToken ,
315
336
) : Promise < Package [ ] > {
316
337
if ( environment . version . startsWith ( '2.' ) ) {
317
338
throw new Error ( 'Python 2.* is not supported (deprecated)' ) ;
@@ -333,13 +354,15 @@ export async function installPackages(
333
354
[ ...installArgs , '--python' , environment . execInfo . run . executable , ...packages ] ,
334
355
undefined ,
335
356
manager . log ,
357
+ token ,
336
358
) ;
337
359
} else {
338
360
await runPython (
339
361
environment . execInfo . run . executable ,
340
362
[ '-m' , ...installArgs , ...packages ] ,
341
363
undefined ,
342
364
manager . log ,
365
+ token ,
343
366
) ;
344
367
}
345
368
@@ -353,6 +376,7 @@ export async function uninstallPackages(
353
376
api : PythonEnvironmentApi ,
354
377
manager : PackageManager ,
355
378
packages : string [ ] | Package [ ] ,
379
+ token ?: CancellationToken ,
356
380
) : Promise < Package [ ] > {
357
381
if ( environment . version . startsWith ( '2.' ) ) {
358
382
throw new Error ( 'Python 2.* is not supported (deprecated)' ) ;
@@ -383,13 +407,15 @@ export async function uninstallPackages(
383
407
[ 'pip' , 'uninstall' , '--python' , environment . execInfo . run . executable , ...remove ] ,
384
408
undefined ,
385
409
manager . log ,
410
+ token ,
386
411
) ;
387
412
} else {
388
413
await runPython (
389
414
environment . execInfo . run . executable ,
390
415
[ '-m' , 'pip' , 'uninstall' , '-y' , ...remove ] ,
391
416
undefined ,
392
417
manager . log ,
418
+ token ,
393
419
) ;
394
420
}
395
421
return refreshPackages ( environment , api , manager ) ;
0 commit comments