Repository navigation
Correctly handle interpreter changes for Interactive and Notebook #8385
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
Ian Huff (IanMatthewHuff)
merged 2 commits into
microsoft:master
from
IanMatthewHuff:dev/ianhu/pythonSwitchEditor
Nov 5, 2019
Merged
Changes from all commits
Commits
Show all changes
2 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 @@ | ||
| Correctly restart jupyter sessions when the active interpreter is changed. |
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
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 |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import * as fs from 'fs-extra'; | |
| import { injectable } from 'inversify'; | ||
| import * as os from 'os'; | ||
| import * as path from 'path'; | ||
| import { SemVer } from 'semver'; | ||
| import { Readable, Writable } from 'stream'; | ||
| import { anything, instance, mock, when } from 'ts-mockito'; | ||
| import * as TypeMoq from 'typemoq'; | ||
|
|
@@ -23,6 +24,7 @@ import { IFileSystem } from '../../client/common/platform/types'; | |
| import { IProcessServiceFactory, IPythonExecutionFactory, Output } from '../../client/common/process/types'; | ||
| import { createDeferred, waitForPromise } from '../../client/common/utils/async'; | ||
| import { noop } from '../../client/common/utils/misc'; | ||
| import { Architecture } from '../../client/common/utils/platform'; | ||
| import { concatMultilineStringInput } from '../../client/datascience/common'; | ||
| import { Identifiers } from '../../client/datascience/constants'; | ||
| import { JupyterExecutionFactory } from '../../client/datascience/jupyter/jupyterExecutionFactory'; | ||
|
|
@@ -42,13 +44,15 @@ import { | |
| import { | ||
| IInterpreterService, | ||
| IKnownSearchPathsForInterpreters, | ||
| InterpreterType, | ||
| PythonInterpreter | ||
| } from '../../client/interpreter/contracts'; | ||
| import { generateTestState, ICellViewModel } from '../../datascience-ui/interactive-common/mainState'; | ||
| import { asyncDump } from '../common/asyncDump'; | ||
| import { sleep } from '../core'; | ||
| import { DataScienceIocContainer } from './dataScienceIocContainer'; | ||
| import { getConnectionInfo, getIPConnectionInfo, getNotebookCapableInterpreter } from './jupyterHelpers'; | ||
| import { SupportedCommands } from './mockJupyterManager'; | ||
| import { MockPythonService } from './mockPythonService'; | ||
|
|
||
| // tslint:disable:no-any no-multiline-string max-func-body-length no-console max-classes-per-file trailing-comma | ||
|
|
@@ -519,6 +523,38 @@ suite('DataScience notebook tests', () => { | |
| } | ||
| }); | ||
|
|
||
| runTest('Change Interpreter', async () => { | ||
| const isRollingBuild = process.env ? process.env.VSCODE_PYTHON_ROLLING !== undefined : false; | ||
|
|
||
| // Real Jupyter doesn't help this test at all and is tricky to set up for it, so just skip it | ||
| if (!isRollingBuild) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you think this is wrong I can look into it, but I don't think that real python actually buys us anything for this test, and I think that it would be difficult to set up. Particularly with lockdown tomorrow. |
||
| const server = await createNotebook(true); | ||
|
|
||
| // Create again, we should get the same server from the cache | ||
| const server2 = await createNotebook(true); | ||
| assert.equal(server, server2, 'With no settings changed we should return the cached server'); | ||
|
|
||
| // Create a new mock interpreter with a different path | ||
| const newPython: PythonInterpreter = { | ||
| path: '/foo/bar/baz/python.exe', | ||
| version: new SemVer('3.6.6-final'), | ||
| sysVersion: '1.0.0.0', | ||
| sysPrefix: 'Python', | ||
| type: InterpreterType.Unknown, | ||
| architecture: Architecture.x64, | ||
| }; | ||
|
|
||
| // Add interpreter into mock jupyter service and set it as active | ||
| ioc.addInterpreter(newPython, SupportedCommands.all); | ||
|
|
||
| // Create a new notebook, we should not be the same anymore | ||
| const server3 = await createNotebook(true); | ||
| assert.notEqual(server, server3, 'With interpreter changed we should return a new server'); | ||
| } else { | ||
| console.log(`Skipping Change Interpreter test in non-mocked Jupyter case`); | ||
| } | ||
| }); | ||
|
|
||
| runTest('Restart kernel', async () => { | ||
| addMockData(`a=1${os.EOL}a`, 1); | ||
| addMockData(`a+=1${os.EOL}a`, 2); | ||
|
|
||
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.
So this was the fix for the immediate server loading issue. But as it turns out, interpreter switching was just totally broken. It would look like it was loading, but just pick the same cached server even when you swapped interpreters.