Skip to content

Commit

Permalink
Ensure display name is set in statusbar for environments not detected (
Browse files Browse the repository at this point in the history
…#791)

if environment is a virtual env then suffix with envname
Fixes #690
  • Loading branch information
DonJayamanne authored Feb 15, 2018
1 parent 5ccb9cd commit 3f3f2a3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/client/interpreter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as utils from '../common/utils';
import { IServiceContainer } from '../ioc/types';
import { IPythonPathUpdaterServiceManager } from './configuration/types';
import { IInterpreterDisplay, IInterpreterHelper, IInterpreterLocatorService, IInterpreterService, IInterpreterVersionService, INTERPRETER_LOCATOR_SERVICE, InterpreterType, PythonInterpreter, WORKSPACE_VIRTUAL_ENV_SERVICE } from './contracts';
import { IVirtualEnvironmentManager } from './virtualEnvs/types';

@injectable()
export class InterpreterManager implements Disposable, IInterpreterService {
Expand Down Expand Up @@ -84,7 +85,12 @@ export class InterpreterManager implements Disposable, IInterpreterService {
}
const pythonExecutableName = path.basename(fullyQualifiedPath);
const versionInfo = await this.serviceContainer.get<IInterpreterVersionService>(IInterpreterVersionService).getVersion(fullyQualifiedPath, pythonExecutableName);
const virtualEnvManager = this.serviceContainer.get<IVirtualEnvironmentManager>(IVirtualEnvironmentManager);
const virtualEnvName = await virtualEnvManager.detect(fullyQualifiedPath).then(env => env ? env.name : '');
const dislayNameSuffix = virtualEnvName.length > 0 ? ` (${virtualEnvName})` : '';
const displayName = `${versionInfo}${dislayNameSuffix}`;
return {
displayName,
path: fullyQualifiedPath,
type: InterpreterType.Unknown,
version: versionInfo
Expand Down
22 changes: 21 additions & 1 deletion src/test/interpreters/display.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ suite('Interpreters Display', () => {
statusBar.verify(s => s.text = TypeMoq.It.isValue(activeInterpreter.displayName)!, TypeMoq.Times.once());
statusBar.verify(s => s.tooltip = TypeMoq.It.isValue(expectedTooltip)!, TypeMoq.Times.once());
});
test('If interpreter is not idenfied then tooltip should point to python Path', async () => {
test('If interpreter is not idenfied then tooltip should point to python Path and text containing the folder name', async () => {
const resource = Uri.file('x');
const pythonPath = path.join('user', 'development', 'env', 'bin', 'python');
const workspaceFolder = Uri.file('workspace');
Expand All @@ -114,10 +114,30 @@ suite('Interpreters Display', () => {
configurationService.setup(c => c.getSettings(TypeMoq.It.isAny())).returns(() => pythonSettings.object);
pythonSettings.setup(p => p.pythonPath).returns(() => pythonPath);
virtualEnvMgr.setup(v => v.detect(TypeMoq.It.isValue(pythonPath))).returns(() => Promise.resolve(undefined));
versionProvider.setup(v => v.getVersion(TypeMoq.It.isValue(pythonPath), TypeMoq.It.isAny())).returns((_path, defaultDisplayName) => Promise.resolve(defaultDisplayName));

await interpreterDisplay.refresh(resource);

statusBar.verify(s => s.tooltip = TypeMoq.It.isValue(pythonPath), TypeMoq.Times.once());
statusBar.verify(s => s.text = TypeMoq.It.isValue(`${path.basename(pythonPath)} [Environment]`), TypeMoq.Times.once());
});
test('If virtual environment interpreter is not idenfied then text should contain the type of virtual environment', async () => {
const resource = Uri.file('x');
const pythonPath = path.join('user', 'development', 'env', 'bin', 'python');
const workspaceFolder = Uri.file('workspace');
setupWorkspaceFolder(resource, workspaceFolder);
interpreterService.setup(i => i.getInterpreters(TypeMoq.It.isValue(workspaceFolder))).returns(() => Promise.resolve([]));
interpreterService.setup(i => i.getActiveInterpreter(TypeMoq.It.isValue(workspaceFolder))).returns(() => Promise.resolve(undefined));
configurationService.setup(c => c.getSettings(TypeMoq.It.isAny())).returns(() => pythonSettings.object);
pythonSettings.setup(p => p.pythonPath).returns(() => pythonPath);
// tslint:disable-next-line:no-any
virtualEnvMgr.setup(v => v.detect(TypeMoq.It.isValue(pythonPath))).returns(() => Promise.resolve({ name: 'Mock Name' } as any));
versionProvider.setup(v => v.getVersion(TypeMoq.It.isValue(pythonPath), TypeMoq.It.isAny())).returns((_path, defaultDisplayName) => Promise.resolve(defaultDisplayName));

await interpreterDisplay.refresh(resource);

statusBar.verify(s => s.tooltip = TypeMoq.It.isValue(pythonPath), TypeMoq.Times.once());
statusBar.verify(s => s.text = TypeMoq.It.isValue(`${path.basename(pythonPath)} [Environment] (Mock Name)`), TypeMoq.Times.once());
});
test('If interpreter file does not exist then update status bar accordingly', async () => {
const resource = Uri.file('x');
Expand Down

0 comments on commit 3f3f2a3

Please sign in to comment.