forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Search for interpreters in all paths found in PATH variable #2575
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
Merged
DonJayamanne
merged 3 commits into
microsoft:master
from
DonJayamanne:issue2398SearchPaths
Sep 13, 2018
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 @@ | ||
Search for python interpreters in all paths found in the `PATH`/`Path` environment variable. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,105 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
'use strict'; | ||
|
||
// tslint:disable:max-func-body-length no-any | ||
|
||
import { expect } from 'chai'; | ||
import * as path from 'path'; | ||
import * as TypeMoq from 'typemoq'; | ||
import { IPlatformService } from '../../client/common/platform/types'; | ||
import { ICurrentProcess, IPathUtils } from '../../client/common/types'; | ||
import { IKnownSearchPathsForInterpreters } from '../../client/interpreter/contracts'; | ||
import { KnownSearchPathsForInterpreters } from '../../client/interpreter/locators/services/KnownPathsService'; | ||
import { IServiceContainer } from '../../client/ioc/types'; | ||
|
||
suite('Interpreters Known Paths', () => { | ||
let serviceContainer: TypeMoq.IMock<IServiceContainer>; | ||
let currentProcess: TypeMoq.IMock<ICurrentProcess>; | ||
let platformService: TypeMoq.IMock<IPlatformService>; | ||
let pathUtils: TypeMoq.IMock<IPathUtils>; | ||
let knownSearchPaths: IKnownSearchPathsForInterpreters; | ||
|
||
setup(async () => { | ||
serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>(); | ||
currentProcess = TypeMoq.Mock.ofType<ICurrentProcess>(); | ||
platformService = TypeMoq.Mock.ofType<IPlatformService>(); | ||
pathUtils = TypeMoq.Mock.ofType<IPathUtils>(); | ||
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(ICurrentProcess), TypeMoq.It.isAny())).returns(() => currentProcess.object); | ||
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IPlatformService), TypeMoq.It.isAny())).returns(() => platformService.object); | ||
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IPathUtils), TypeMoq.It.isAny())).returns(() => pathUtils.object); | ||
|
||
knownSearchPaths = new KnownSearchPathsForInterpreters(serviceContainer.object); | ||
}); | ||
|
||
test('Ensure known list of paths are returned', async () => { | ||
const pathDelimiter = 'X'; | ||
const pathsInPATHVar = [path.join('a', 'b', 'c'), '', path.join('1', '2'), '3']; | ||
pathUtils.setup(p => p.delimiter).returns(() => pathDelimiter); | ||
platformService.setup(p => p.isWindows).returns(() => true); | ||
platformService.setup(p => p.pathVariableName).returns(() => 'PATH'); | ||
currentProcess.setup(p => p.env).returns(() => { | ||
return { PATH: pathsInPATHVar.join(pathDelimiter) }; | ||
}); | ||
|
||
const expectedPaths = [...pathsInPATHVar].filter(item => item.length > 0); | ||
|
||
const paths = knownSearchPaths.getSearchPaths(); | ||
|
||
expect(paths).to.deep.equal(expectedPaths); | ||
}); | ||
|
||
test('Ensure known list of paths are returned on non-windows', async () => { | ||
const homeDir = '/users/peter Smith'; | ||
const pathDelimiter = 'X'; | ||
pathUtils.setup(p => p.delimiter).returns(() => pathDelimiter); | ||
pathUtils.setup(p => p.home).returns(() => homeDir); | ||
platformService.setup(p => p.isWindows).returns(() => false); | ||
platformService.setup(p => p.pathVariableName).returns(() => 'PATH'); | ||
currentProcess.setup(p => p.env).returns(() => { | ||
return { PATH: '' }; | ||
}); | ||
|
||
const expectedPaths: string[] = []; | ||
['/usr/local/bin', '/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/sbin'] | ||
.forEach(p => { | ||
expectedPaths.push(p); | ||
expectedPaths.push(path.join(homeDir, p)); | ||
}); | ||
|
||
expectedPaths.push(path.join(homeDir, 'anaconda', 'bin')); | ||
expectedPaths.push(path.join(homeDir, 'python', 'bin')); | ||
|
||
const paths = knownSearchPaths.getSearchPaths(); | ||
|
||
expect(paths).to.deep.equal(expectedPaths); | ||
}); | ||
|
||
test('Ensure PATH variable and known list of paths are merged on non-windows', async () => { | ||
const homeDir = '/users/peter Smith'; | ||
const pathDelimiter = 'X'; | ||
const pathsInPATHVar = [path.join('a', 'b', 'c'), '', path.join('1', '2'), '3']; | ||
pathUtils.setup(p => p.delimiter).returns(() => pathDelimiter); | ||
pathUtils.setup(p => p.home).returns(() => homeDir); | ||
platformService.setup(p => p.isWindows).returns(() => false); | ||
platformService.setup(p => p.pathVariableName).returns(() => 'PATH'); | ||
currentProcess.setup(p => p.env).returns(() => { | ||
return { PATH: pathsInPATHVar.join(pathDelimiter) }; | ||
}); | ||
|
||
const expectedPaths = [...pathsInPATHVar].filter(item => item.length > 0); | ||
['/usr/local/bin', '/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/sbin'] | ||
.forEach(p => { | ||
expectedPaths.push(p); | ||
expectedPaths.push(path.join(homeDir, p)); | ||
}); | ||
|
||
expectedPaths.push(path.join(homeDir, 'anaconda', 'bin')); | ||
expectedPaths.push(path.join(homeDir, 'python', 'bin')); | ||
|
||
const paths = knownSearchPaths.getSearchPaths(); | ||
|
||
expect(paths).to.deep.equal(expectedPaths); | ||
}); | ||
}); |
This file contains hidden or 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
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.
This is interesting. We know that Anaconda does something 'bespoke' and so we inject it into the search paths.
This is one of the reasons we might want to have the specific
IInterpreter
classes that you and I discussed the other day - you could simply query each known (registered)IInterpreter
forgetKnownSearchPaths
or something like that.Another one that comes to mind is
pyenv
, who's prescribed behaviour is to shove all the installed versions under$HOME/.pyenv
...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.
But its a chicken or the egg...
IInterpreter is the interpreter object that represents the interpreter info. Where do we get that object from. I.e. where do we get the python interpreter info from to begin with.