Skip to content

Commit

Permalink
Cherry pick fix for hasInterpreters and update change log (#12198)
Browse files Browse the repository at this point in the history
* Double-check for interpreters when running diagnostics (#12158)

* Get interpreters if hasInterpreters returns false
* Undo ignoreErrors()
* Add unit tests
* Fixed tests
* Newline

* Fix merge issues.

* Update change log

Co-authored-by: Kim-Adeline Miguel <51720070+kimadeline@users.noreply.github.com>
  • Loading branch information
karthiknadig and kimadeline committed Jun 8, 2020
1 parent 18316da commit 94bc061
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Fixes

1. Double-check for interpreters when running diagnostics before displaying the "Python is not installed" message.
([#11870](https://github.com/Microsoft/vscode-python/issues/11870))
1. Ensure user cannot belong to all experiments in an experiment group.
([#11943](https://github.com/Microsoft/vscode-python/issues/11943))
1. Ensure extension features are started when in `Deprecate PythonPath` experiment and opening a file without any folder opened.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ export class InvalidPythonInterpreterService extends BaseDiagnosticsService {
}

const interpreterService = this.serviceContainer.get<IInterpreterService>(IInterpreterService);
const hasInterpreters = await interpreterService.hasInterpreters;
// hasInterpreters being false can mean one of 2 things:
// 1. getInterpreters hasn't returned any interpreters;
// 2. getInterpreters hasn't run yet.
// We want to make sure that false comes from 1, so we're adding this fix until we refactor interpreter discovery.
// Also see https://github.com/microsoft/vscode-python/issues/3023.
const hasInterpreters =
(await interpreterService.hasInterpreters) ||
(await interpreterService.getInterpreters(resource)).length > 0;

if (!hasInterpreters) {
return [new InvalidPythonInterpreterDiagnostic(DiagnosticCodes.NoPythonInterpretersDiagnostic, resource)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ import { CommandsWithoutArgs } from '../../../../client/common/application/comma
import { IPlatformService } from '../../../../client/common/platform/types';
import { IConfigurationService, IDisposableRegistry, IPythonSettings } from '../../../../client/common/types';
import { noop } from '../../../../client/common/utils/misc';
import { IInterpreterHelper, IInterpreterService, InterpreterType } from '../../../../client/interpreter/contracts';
import {
IInterpreterHelper,
IInterpreterService,
InterpreterType,
PythonInterpreter
} from '../../../../client/interpreter/contracts';
import { IServiceContainer } from '../../../../client/ioc/types';

suite('Application Diagnostics - Checks Python Interpreter', () => {
Expand Down Expand Up @@ -129,7 +134,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
expect(diagnostics).to.be.deep.equal([]);
settings.verifyAll();
});
test('Should return diagnostics if there are no interpreters', async () => {
test('Should return diagnostics if there are no interpreters after double-checking', async () => {
settings
.setup((s) => s.disableInstallationChecks)
.returns(() => false)
Expand All @@ -138,6 +143,10 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
.setup((i) => i.hasInterpreters)
.returns(() => Promise.resolve(false))
.verifiable(typemoq.Times.once());
interpreterService
.setup((i) => i.getInterpreters(undefined))
.returns(() => Promise.resolve([]))
.verifiable(typemoq.Times.once());

const diagnostics = await diagnosticService.diagnose(undefined);
expect(diagnostics).to.be.deep.equal(
Expand All @@ -147,6 +156,34 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
settings.verifyAll();
interpreterService.verifyAll();
});
test('Should return empty diagnostics if there are interpreters after double-checking', async () => {
const interpreter: PythonInterpreter = { type: InterpreterType.Unknown } as any;

settings
.setup((s) => s.disableInstallationChecks)
.returns(() => false)
.verifiable(typemoq.Times.once());
interpreterService
.setup((i) => i.hasInterpreters)
.returns(() => Promise.resolve(false))
.verifiable(typemoq.Times.once());
interpreterService
.setup((i) => i.getInterpreters(undefined))
.returns(() => Promise.resolve([interpreter]))
.verifiable(typemoq.Times.once());
interpreterService
.setup((i) => i.getActiveInterpreter(typemoq.It.isAny()))
.returns(() => {
return Promise.resolve(interpreter);
})
.verifiable(typemoq.Times.once());

const diagnostics = await diagnosticService.diagnose(undefined);

expect(diagnostics).to.be.deep.equal([], 'not the same');
settings.verifyAll();
interpreterService.verifyAll();
});
test('Should return invalid diagnostics if there are interpreters but no current interpreter', async () => {
settings
.setup((s) => s.disableInstallationChecks)
Expand Down

0 comments on commit 94bc061

Please sign in to comment.