File tree Expand file tree Collapse file tree
client/pythonEnvironments/common/environmentManagers
test/pythonEnvironments/common/environmentManagers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -354,12 +354,34 @@ export class Conda {
354354 . map ( ( line ) => path . join ( line , suffix ) ) ;
355355 }
356356
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+
357366 // Probe the candidates, and pick the first one that exists and does what we need.
358367 for await ( const condaPath of getCandidates ( ) ) {
359368 traceVerbose ( `Probing conda binary: ${ condaPath } ` ) ;
360- const conda = new Conda ( condaPath ) ;
369+ let conda = new Conda ( condaPath ) ;
361370 try {
362371 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+ }
363385 traceVerbose ( `Found conda via filesystem probing: ${ condaPath } ` ) ;
364386 return conda ;
365387 } catch ( ex ) {
Original file line number Diff line number Diff line change @@ -245,6 +245,22 @@ suite('Conda and its environments are located correctly', () => {
245245 await expectConda ( '/bin/conda' ) ;
246246 } ) ;
247247
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+
248264 suite ( 'Must find conda in well-known locations' , ( ) => {
249265 const condaDirNames = [ 'Anaconda' , 'anaconda' , 'Miniconda' , 'miniconda' ] ;
250266
You can’t perform that action at this time.
0 commit comments