GeezerVison is showing github.com — correctly show variables after jupyter restart (#5336) · iserko/vscode-python@f4f9f96
File treeExpand file treeCollapse file tree Open diff view settings datascience-ui/history-react
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +Variables not cleared after a kernel restart |
Collapse file Copy file name to clipboardExpand all lines: package.json +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1240 | 1240 | }, | 1241 | 1241 | "python.dataScience.variableExplorerExclude": { | 1242 | 1242 | "type": "string", | 1243 | | - "default": "module;builtin_function_or_method", | | 1243 | + "default": "module;function;builtin_function_or_method", | 1244 | 1244 | "description": "Types to exclude from showing in the Python Interactive variable explorer", | 1245 | 1245 | "scope": "resource" | 1246 | 1246 | }, | |
Collapse file Copy file name to clipboardExpand all lines: pythonFiles/datascience/getJupyterVariableList.py +7-5Lines changed: 7 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | # Tested on 2.7 and 3.6 | 3 | 3 | from sys import getsizeof as _VSCODE_getsizeof | 4 | 4 | import json as _VSCODE_json | 5 | | -from IPython import get_ipython | | 5 | +from IPython import get_ipython as _VSCODE_get_ipython | 6 | 6 |
| 7 | 7 | # _VSCode_supportsDataExplorer will contain our list of data explorer supported types | 8 | 8 | _VSCode_supportsDataExplorer = "['list', 'Series', 'dict', 'ndarray', 'DataFrame']" | 9 | 9 |
| 10 | 10 | # who_ls is a Jupyter line magic to fetch currently defined vars | 11 | | -_VSCode_JupyterVars = get_ipython().run_line_magic('who_ls', '') | | 11 | +_VSCode_JupyterVars = _VSCODE_get_ipython().run_line_magic('who_ls', '') | 12 | 12 |
| 13 | 13 | _VSCode_output = [] | 14 | | -for var in _VSCode_JupyterVars: | | 14 | +for _VSCode_var in _VSCode_JupyterVars: | 15 | 15 | try: | 16 | | - _VSCode_type = type(eval(var)) | 17 | | - _VSCode_output.append({'name': var, 'type': _VSCode_type.__name__, 'size': _VSCODE_getsizeof(var), 'supportsDataExplorer': _VSCode_type.__name__ in _VSCode_supportsDataExplorer }) | | 16 | + _VSCode_type = type(eval(_VSCode_var)) | | 17 | + _VSCode_output.append({'name': _VSCode_var, 'type': _VSCode_type.__name__, 'size': _VSCODE_getsizeof(_VSCode_var), 'supportsDataExplorer': _VSCode_type.__name__ in _VSCode_supportsDataExplorer }) | 18 | 18 | del _VSCode_type | | 19 | + del _VSCode_var | 19 | 20 | except: | 20 | 21 | pass | 21 | 22 |
| 22 | 23 | print(_VSCODE_json.dumps(_VSCode_output)) | 23 | 24 |
| | 25 | +del _VSCODE_get_ipython | 24 | 26 | del _VSCode_output | 25 | 27 | del _VSCode_supportsDataExplorer | 26 | 28 | del _VSCode_JupyterVars | |
Collapse file Copy file name to clipboardExpand all lines: src/client/datascience/history/history.ts +8-6Lines changed: 8 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -44,6 +44,7 @@ import { | 44 | 44 | IJupyterExecution, | 45 | 45 | IJupyterVariable, | 46 | 46 | IJupyterVariables, | | 47 | + IJupyterVariablesResponse, | 47 | 48 | INotebookExporter, | 48 | 49 | INotebookServer, | 49 | 50 | InterruptResult, | @@ -918,26 +919,27 @@ export class History extends WebViewHost<IHistoryMapping> implements IHistory { | 918 | 919 | } | 919 | 920 | } | 920 | 921 |
| 921 | | - private requestVariables = async (executionCount: number): Promise<void> => { | | 922 | + private requestVariables = async (requestExecutionCount: number): Promise<void> => { | 922 | 923 | // Request our new list of variables | 923 | | - let vars: IJupyterVariable[] = await this.jupyterVariables.getVariables(); | | 924 | + const vars: IJupyterVariable[] = await this.jupyterVariables.getVariables(); | | 925 | + const variablesResponse: IJupyterVariablesResponse = {executionCount: requestExecutionCount, variables: vars }; | 924 | 926 |
| 925 | 927 | // Tag all of our jupyter variables with the execution count of the request | 926 | | - vars.forEach((value: IJupyterVariable) => { | 927 | | - value.executionCount = executionCount; | | 928 | + variablesResponse.variables.forEach((value: IJupyterVariable) => { | | 929 | + value.executionCount = requestExecutionCount; | 928 | 930 | }); | 929 | 931 |
| 930 | 932 | const settings = this.configuration.getSettings(); | 931 | 933 | const excludeString = settings.datascience.variableExplorerExclude; | 932 | 934 |
| 933 | 935 | if (excludeString) { | 934 | 936 | const excludeArray = excludeString.split(';'); | 935 | | - vars = vars.filter((value) => { | | 937 | + variablesResponse.variables = variablesResponse.variables.filter((value) => { | 936 | 938 | return excludeArray.indexOf(value.type) === -1; | 937 | 939 | }); | 938 | 940 | } | 939 | 941 |
| 940 | | - this.postMessage(HistoryMessages.GetVariablesResponse, vars).ignoreErrors(); | | 942 | + this.postMessage(HistoryMessages.GetVariablesResponse, variablesResponse).ignoreErrors(); | 941 | 943 | } | 942 | 944 |
| 943 | 945 | // tslint:disable-next-line: no-any | |
Collapse file Copy file name to clipboardExpand all lines: src/client/datascience/history/historyTypes.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | // Licensed under the MIT License. | 3 | 3 | 'use strict'; | 4 | 4 | import { CssMessages, IGetCssRequest, IGetCssResponse, SharedMessages } from '../constants'; | 5 | | -import { ICell, IHistoryInfo, IJupyterVariable } from '../types'; | | 5 | +import { ICell, IHistoryInfo, IJupyterVariable, IJupyterVariablesResponse } from '../types'; | 6 | 6 |
| 7 | 7 | export namespace HistoryMessages { | 8 | 8 | export const StartCell = 'start_cell'; | @@ -97,7 +97,7 @@ export class IHistoryMapping { | 97 | 97 | public [HistoryMessages.Activate] : never | undefined; | 98 | 98 | public [HistoryMessages.ShowDataViewer]: string; | 99 | 99 | public [HistoryMessages.GetVariablesRequest]: number; | 100 | | - public [HistoryMessages.GetVariablesResponse]: IJupyterVariable[]; | | 100 | + public [HistoryMessages.GetVariablesResponse]: IJupyterVariablesResponse; | 101 | 101 | public [HistoryMessages.GetVariableValueRequest]: IJupyterVariable; | 102 | 102 | public [HistoryMessages.GetVariableValueResponse]: IJupyterVariable; | 103 | 103 | public [CssMessages.GetCssRequest] : IGetCssRequest; | |
Collapse file Copy file name to clipboardExpand all lines: src/client/datascience/types.ts +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -281,6 +281,12 @@ export interface IJupyterVariables { | 281 | 281 | getDataFrameRows(targetVariable: IJupyterVariable, start: number, end: number) : Promise<JSONObject>; | 282 | 282 | } | 283 | 283 |
| | 284 | +// Wrapper to hold an execution count for our variable requests | | 285 | +export interface IJupyterVariablesResponse { | | 286 | + executionCount: number; | | 287 | + variables: IJupyterVariable[]; | | 288 | +} | | 289 | + | 284 | 290 | export const IDataViewerProvider = Symbol('IDataViewerProvider'); | 285 | 291 | export interface IDataViewerProvider { | 286 | 292 | create(variable: string) : Promise<IDataViewer>; | |
Collapse file Copy file name to clipboardExpand all lines: src/datascience-ui/history-react/MainPanel.tsx +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,7 +9,7 @@ import * as React from 'react'; | 9 | 9 | import { CellMatcher } from '../../client/datascience/cellMatcher'; | 10 | 10 | import { generateMarkdownFromCodeLines } from '../../client/datascience/common'; | 11 | 11 | import { HistoryMessages, IHistoryMapping } from '../../client/datascience/history/historyTypes'; | 12 | | -import { CellState, ICell, IHistoryInfo, IJupyterVariable } from '../../client/datascience/types'; | | 12 | +import { CellState, ICell, IHistoryInfo, IJupyterVariable, IJupyterVariablesResponse } from '../../client/datascience/types'; | 13 | 13 | import { IMessageHandler, PostOffice } from '../react-common/postOffice'; | 14 | 14 | import { getSettings, updateSettings } from '../react-common/settingsReactSide'; | 15 | 15 | import { StyleInjector } from '../react-common/styleInjector'; | @@ -784,16 +784,16 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState> | 784 | 784 | // tslint:disable-next-line:no-any | 785 | 785 | private getVariablesResponse = (payload?: any) => { | 786 | 786 | if (payload) { | 787 | | - const variables = payload as IJupyterVariable[]; | | 787 | + const variablesResponse = payload as IJupyterVariablesResponse; | 788 | 788 |
| 789 | 789 | // Check to see if we have moved to a new execution count only send our update if we are on the same count as the request | 790 | | - if (variables.length > 0 && variables[0].executionCount !== undefined && variables[0].executionCount === this.currentExecutionCount) { | | 790 | + if (variablesResponse.executionCount === this.currentExecutionCount) { | 791 | 791 | if (this.variableExplorerRef.current) { | 792 | | - this.variableExplorerRef.current.newVariablesData(variables); | | 792 | + this.variableExplorerRef.current.newVariablesData(variablesResponse.variables); | 793 | 793 | } | 794 | 794 |
| 795 | 795 | // Now put out a request for all of the sub values for the variables | 796 | | - variables.forEach(this.refreshVariable); | | 796 | + variablesResponse.variables.forEach(this.refreshVariable); | 797 | 797 | } | 798 | 798 | } | 799 | 799 | } | |
|