|
1 |
| -import { inject, injectable, named, optional } from 'inversify'; |
| 1 | +import { |
| 2 | + inject, injectable, |
| 3 | + named, optional |
| 4 | +} from 'inversify'; |
2 | 5 | import * as path from 'path';
|
3 | 6 | import { parse, SemVer } from 'semver';
|
4 | 7 | import { compareVersion } from '../../../../utils/version';
|
5 | 8 | import { warn } from '../../../common/logger';
|
6 |
| -import { IFileSystem, IPlatformService } from '../../../common/platform/types'; |
| 9 | +import { |
| 10 | + IFileSystem, IPlatformService |
| 11 | +} from '../../../common/platform/types'; |
7 | 12 | import { IProcessServiceFactory } from '../../../common/process/types';
|
8 |
| -import { IConfigurationService, ILogger, IPersistentStateFactory } from '../../../common/types'; |
| 13 | +import { |
| 14 | + IConfigurationService, ILogger, |
| 15 | + IPersistentStateFactory |
| 16 | +} from '../../../common/types'; |
9 | 17 | import { IServiceContainer } from '../../../ioc/types';
|
10 |
| -import { CondaInfo, ICondaService, IInterpreterLocatorService, InterpreterType, PythonInterpreter, WINDOWS_REGISTRY_SERVICE } from '../../contracts'; |
| 18 | +import { |
| 19 | + CondaInfo, ICondaService, IInterpreterLocatorService, |
| 20 | + InterpreterType, PythonInterpreter, |
| 21 | + WINDOWS_REGISTRY_SERVICE |
| 22 | +} from '../../contracts'; |
11 | 23 | import { CondaHelper } from './condaHelper';
|
12 | 24 |
|
13 | 25 | // tslint:disable-next-line:no-require-imports no-var-requires
|
14 | 26 | const untildify: (value: string) => string = require('untildify');
|
15 | 27 |
|
16 | 28 | // This glob pattern will match all of the following:
|
17 | 29 | // ~/anaconda/bin/conda, ~/anaconda3/bin/conda, ~/miniconda/bin/conda, ~/miniconda3/bin/conda
|
18 |
| -export const CondaLocationsGlob = '~/*conda*/bin/conda'; |
19 |
| -export const CondaLocationsGlobWin = `${[ |
| 30 | +export const CondaLocationsGlob = untildify('~/*conda*/bin/conda'); |
| 31 | + |
| 32 | +// ...and for windows, the known default install locations: |
| 33 | +const condaGlobPathsForWindows = [ |
20 | 34 | '/ProgramData/Miniconda*/Scripts/conda.exe',
|
21 | 35 | '/ProgramData/Anaconda*/Scripts/conda.exe',
|
22 |
| - untildify('~/AppData/Local/Continuum/miniconda*/Scripts/conda.exe'), |
23 |
| - untildify('~/AppData/Local/Continuum/miniconda*/Scripts/conda.exe')].join(',')}`; |
| 36 | + untildify('~/Miniconda*/Scripts/conda.exe'), |
| 37 | + untildify('~/Anaconda*/Scripts/conda.exe'), |
| 38 | + untildify('~/AppData/Local/Continuum/Miniconda*/Scripts/conda.exe'), |
| 39 | + untildify('~/AppData/Local/Continuum/Anaconda*/Scripts/conda.exe')]; |
| 40 | + |
| 41 | +// format for glob processing: |
| 42 | +export const CondaLocationsGlobWin = `{${condaGlobPathsForWindows.join(',')}}`; |
24 | 43 |
|
25 | 44 | /**
|
26 | 45 | * A wrapper around a conda installation.
|
@@ -272,15 +291,20 @@ export class CondaService implements ICondaService {
|
272 | 291 |
|
273 | 292 | /**
|
274 | 293 | * Return the path to the "conda file", if there is one (in known locations).
|
| 294 | + * Note: For now we simply return the first one found. |
275 | 295 | */
|
276 | 296 | private async getCondaFileFromKnownLocations(): Promise<string> {
|
277 | 297 | const fileSystem = this.serviceContainer.get<IFileSystem>(IFileSystem);
|
278 | 298 | const globPattern = this.platform.isWindows ? CondaLocationsGlobWin : CondaLocationsGlob;
|
279 |
| - const condaFiles = await fileSystem.search(untildify(globPattern)) |
280 |
| - .catch<string[]>(() => []); |
281 |
| - |
| 299 | + const condaFiles = await fileSystem.search(globPattern) |
| 300 | + .catch<string[]>((failReason) => { |
| 301 | + warn( |
| 302 | + 'Default conda location search failed.', |
| 303 | + `Searching for default install locations for conda results in error: ${failReason}` |
| 304 | + ); |
| 305 | + return []; |
| 306 | + }); |
282 | 307 | const validCondaFiles = condaFiles.filter(condaPath => condaPath.length > 0);
|
283 | 308 | return validCondaFiles.length === 0 ? 'conda' : validCondaFiles[0];
|
284 | 309 | }
|
285 |
| - |
286 | 310 | }
|
0 commit comments