File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
client/pythonEnvironments/common/environmentManagers
test/pythonEnvironments/common/environmentManagers Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -354,12 +354,34 @@ export class Conda {
354
354
. map ( ( line ) => path . join ( line , suffix ) ) ;
355
355
}
356
356
357
+ async function getCondaBatFile ( file : string ) {
358
+ const fileDir = path . dirname ( file ) ;
359
+ const possibleBatch = path . join ( fileDir , '..' , 'condabin' , 'conda.bat' ) ;
360
+ if ( await pathExists ( possibleBatch ) ) {
361
+ return possibleBatch ;
362
+ }
363
+ return undefined ;
364
+ }
365
+
357
366
// Probe the candidates, and pick the first one that exists and does what we need.
358
367
for await ( const condaPath of getCandidates ( ) ) {
359
368
traceVerbose ( `Probing conda binary: ${ condaPath } ` ) ;
360
- const conda = new Conda ( condaPath ) ;
369
+ let conda = new Conda ( condaPath ) ;
361
370
try {
362
371
await conda . getInfo ( ) ;
372
+ if ( getOSType ( ) === OSType . Windows ) {
373
+ // Prefer to use .bat files over .exe on windows as that is what cmd works best on.
374
+ const condaBatFile = await getCondaBatFile ( condaPath ) ;
375
+ try {
376
+ if ( condaBatFile ) {
377
+ const condaBat = new Conda ( condaBatFile ) ;
378
+ await condaBat . getInfo ( ) ;
379
+ conda = condaBat ;
380
+ }
381
+ } catch ( ex ) {
382
+ traceVerbose ( 'Failed to spawn conda bat file' , condaBatFile , ex ) ;
383
+ }
384
+ }
363
385
traceVerbose ( `Found conda via filesystem probing: ${ condaPath } ` ) ;
364
386
return conda ;
365
387
} catch ( ex ) {
Original file line number Diff line number Diff line change @@ -245,6 +245,22 @@ suite('Conda and its environments are located correctly', () => {
245
245
await expectConda ( '/bin/conda' ) ;
246
246
} ) ;
247
247
248
+ test ( 'Use conda.bat when possible over conda.exe on windows' , async ( ) => {
249
+ osType = platform . OSType . Windows ;
250
+
251
+ getPythonSetting . withArgs ( 'condaPath' ) . returns ( 'bin/conda' ) ;
252
+ files = {
253
+ bin : {
254
+ conda : JSON . stringify ( condaInfo ( '4.8.0' ) ) ,
255
+ } ,
256
+ condabin : {
257
+ 'conda.bat' : JSON . stringify ( condaInfo ( '4.8.0' ) ) ,
258
+ } ,
259
+ } ;
260
+
261
+ await expectConda ( '/condabin/conda.bat' ) ;
262
+ } ) ;
263
+
248
264
suite ( 'Must find conda in well-known locations' , ( ) => {
249
265
const condaDirNames = [ 'Anaconda' , 'anaconda' , 'Miniconda' , 'miniconda' ] ;
250
266
You can’t perform that action at this time.
0 commit comments