forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #22 to Detect anaconda from known locations #221
Merged
Merged
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ecc1ca9
Fix Microsoft/vscode#37627 (#1368)
octref 7c5778c
Version 0.7.0 of extension (#1381)
DonJayamanne 9d1bf82
Update README.md
DonJayamanne ffba179
Update README.md
DonJayamanne 905c713
sync fork with upstream
DonJayamanne acc2109
fix readme
DonJayamanne c25d364
look for conda file in known locations
DonJayamanne 5e962a9
gulp changes to watch strict linting
DonJayamanne d470523
Merge branch 'master' of https://github.com/Microsoft/vscode-python
DonJayamanne d392e8b
merged upstream
DonJayamanne bf0e8e1
fix code review comments
DonJayamanne d25d8a7
Merge branch 'master' into DetectAnaconda
DonJayamanne 4a1dc58
Merge branch 'master' into DetectAnaconda
DonJayamanne 92f775f
Merge remote-tracking branch 'upstream/master'
DonJayamanne 32a6e53
Merge remote-tracking branch 'upstream/master'
DonJayamanne ff00734
merged master
DonJayamanne a4efe1e
inject windows flag into services
DonJayamanne d22be97
Merge branch 'master' into DetectAnaconda
DonJayamanne 3cc3e3b
Merge branch 'master' into DetectAnaconda
DonJayamanne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
'use strict'; | ||
import * as child_process from 'child_process'; | ||
import * as fs from 'fs-extra'; | ||
import * as path from 'path'; | ||
import { IS_WINDOWS } from '../../../common/utils'; | ||
import { VersionUtils } from '../../../common/versionUtils'; | ||
import { ICondaLocatorService, IInterpreterLocatorService, PythonInterpreter } from '../../contracts'; | ||
// tslint:disable-next-line:no-require-imports no-var-requires | ||
const untildify: (value: string) => string = require('untildify'); | ||
|
||
const KNOWN_CONDA_LOCATIONS = ['~/anaconda/bin/conda', '~/miniconda/bin/conda', | ||
'~/anaconda2/bin/conda', '~/miniconda2/bin/conda', | ||
'~/anaconda3/bin/conda', '~/miniconda3/bin/conda']; | ||
|
||
export class CondaLocatorService implements ICondaLocatorService { | ||
constructor(private isWindows: boolean, private registryLookupForConda?: IInterpreterLocatorService) { | ||
} | ||
// tslint:disable-next-line:no-empty | ||
public dispose() { } | ||
public async getCondaFile(): Promise<string> { | ||
const isAvailable = await this.isCondaInCurrentPath(); | ||
if (isAvailable) { | ||
return 'conda'; | ||
} | ||
if (this.isWindows && this.registryLookupForConda) { | ||
return this.registryLookupForConda.getInterpreters() | ||
.then(interpreters => interpreters.filter(this.isCondaEnvironment)) | ||
.then(condaInterpreters => this.getLatestVersion(condaInterpreters)) | ||
.then(condaInterpreter => { | ||
return condaInterpreter ? path.join(path.dirname(condaInterpreter.path), 'conda.exe') : 'conda'; | ||
}) | ||
.then(async condaPath => { | ||
return fs.pathExists(condaPath).then(exists => exists ? condaPath : 'conda'); | ||
}); | ||
} | ||
return this.getCondaFileFromKnownLocations(); | ||
} | ||
public isCondaEnvironment(interpreter: PythonInterpreter) { | ||
return (interpreter.displayName ? interpreter.displayName : '').toUpperCase().indexOf('ANACONDA') >= 0 || | ||
(interpreter.companyDisplayName ? interpreter.companyDisplayName : '').toUpperCase().indexOf('CONTINUUM') >= 0; | ||
} | ||
public getLatestVersion(interpreters: PythonInterpreter[]) { | ||
const sortedInterpreters = interpreters.filter(interpreter => interpreter.version && interpreter.version.length > 0); | ||
// tslint:disable-next-line:no-non-null-assertion | ||
sortedInterpreters.sort((a, b) => VersionUtils.compareVersion(a.version!, b.version!)); | ||
if (sortedInterpreters.length > 0) { | ||
return sortedInterpreters[sortedInterpreters.length - 1]; | ||
} | ||
} | ||
public async isCondaInCurrentPath() { | ||
return new Promise<boolean>((resolve, reject) => { | ||
child_process.execFile('conda', ['--version'], (_, stdout) => { | ||
if (stdout && stdout.length > 0) { | ||
resolve(true); | ||
} else { | ||
resolve(false); | ||
} | ||
}); | ||
}); | ||
} | ||
private async getCondaFileFromKnownLocations(): Promise<string> { | ||
const condaFiles = await Promise.all(KNOWN_CONDA_LOCATIONS | ||
.map(untildify) | ||
.map(async (condaPath: string) => fs.pathExists(condaPath).then(exists => exists ? condaPath : ''))); | ||
|
||
const validCondaFiles = condaFiles.filter(condaPath => condaPath.length > 0); | ||
return validCondaFiles.length === 0 ? 'conda' : validCondaFiles[0]; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't assuming
conda.exe
a Windows-specific thing?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably change the condition. Currently its implied with the existence of
registryLookupForConda
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed