From acecad774f1934c60f2801760467b20094c24fac Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Fri, 10 Jul 2020 15:10:12 -0700 Subject: [PATCH 1/7] Make trusted message visible on dark backgrounds (#12888) --- src/datascience-ui/interactive-common/trustMessage.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/datascience-ui/interactive-common/trustMessage.tsx b/src/datascience-ui/interactive-common/trustMessage.tsx index a5d55993082b..c97a97e6c6cb 100644 --- a/src/datascience-ui/interactive-common/trustMessage.tsx +++ b/src/datascience-ui/interactive-common/trustMessage.tsx @@ -22,7 +22,9 @@ export class TrustMessage extends React.PureComponent { }; const dynamicStyle: React.CSSProperties = { maxWidth: getMaxWidth(textSize), - color: this.props.isNotebookTrusted ? undefined : 'var(--vscode-editorError-foreground)', + color: this.props.isNotebookTrusted + ? 'var(--vscode-editor-foreground)' + : 'var(--vscode-editorError-foreground)', cursor: this.props.isNotebookTrusted ? undefined : 'pointer' }; From 8c3c0ebcca5c1093adac46d9ae8e1df3d442501a Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 13 Jul 2020 08:22:42 -0700 Subject: [PATCH 2/7] Disable Notebook icons when Notebook is not trusted (#12894) For #12893 --- news/3 Code Health/12893.md | 1 + package.json | 38 +++++-------------- src/client/common/application/commands.ts | 1 - src/client/datascience/constants.ts | 1 - .../interactive-ipynb/trustCommandHandler.ts | 2 - 5 files changed, 10 insertions(+), 33 deletions(-) create mode 100644 news/3 Code Health/12893.md diff --git a/news/3 Code Health/12893.md b/news/3 Code Health/12893.md new file mode 100644 index 000000000000..5a4d62330a56 --- /dev/null +++ b/news/3 Code Health/12893.md @@ -0,0 +1 @@ +Disable Notebook icons when Notebook is not trusted. diff --git a/package.json b/package.json index 1a7fdca8262e..36674cbae8dd 100644 --- a/package.json +++ b/package.json @@ -369,7 +369,8 @@ "icon": { "light": "resources/light/export_to_python.svg", "dark": "resources/dark/export_to_python.svg" - } + }, + "enablement": "notebookViewType == jupyter-notebook && python.datascience.isnotebooktrusted" }, { "command": "python.datascience.exportAsPythonScript", @@ -702,16 +703,7 @@ "light": "resources/light/un-trusted.svg", "dark": "resources/dark/un-trusted.svg" }, - "enablement": "notebookEditorFocused && !python.datascience.isnotebooktrusted && python.datascience.trustfeatureenabled" - }, - { - "command": "python.datascience.notebookeditor.trusted", - "title": "%DataScience.notebookIsTrusted%", - "category": "Python", - "icon": { - "light": "resources/light/trusted.svg", - "dark": "resources/dark/trusted.svg" - } + "enablement": "notebookViewType == jupyter-notebook && !python.datascience.isnotebooktrusted && python.datascience.trustfeatureenabled" }, { "command": "python.datascience.notebookeditor.runallcells", @@ -877,25 +869,19 @@ "command": "python.datascience.notebookeditor.restartkernel", "title": "%python.command.python.datascience.restartkernel.title%", "group": "navigation", - "when": "notebookEditorFocused" + "when": "notebookViewType == jupyter-notebook" }, { "command": "python.datascience.notebookeditor.trust", "title": "%DataScience.trustNotebookCommandTitle%", "group": "navigation@1", - "when": "notebookEditorFocused && !python.datascience.isnotebooktrusted && python.datascience.trustfeatureenabled" - }, - { - "command": "python.datascience.notebookeditor.trusted", - "title": "%DataScience.notebookIsTrusted%", - "group": "navigation@1", - "when": "notebookEditorFocused && python.datascience.isnotebooktrusted && python.datascience.trustfeatureenabled" + "when": "notebookViewType == jupyter-notebook && !python.datascience.isnotebooktrusted && python.datascience.trustfeatureenabled" }, { "command": "python.datascience.export", "title": "%DataScience.notebookExportAs%", "group": "navigation", - "when": "notebookEditorFocused" + "when": "notebookViewType == jupyter-notebook" } ], "explorer/context": [ @@ -940,19 +926,19 @@ "command": "python.datascience.exportAsPythonScript", "title": "%python.command.python.datascience.exportAsPythonScript.title%", "category": "Python", - "when": "python.datascience.isnativeactive && python.datascience.featureenabled" + "when": "python.datascience.isnativeactive && python.datascience.featureenabled && python.datascience.isnotebooktrusted" }, { "command": "python.datascience.exportToHTML", "title": "%python.command.python.datascience.exportToHTML.title%", "category": "Python", - "when": "python.datascience.isnativeactive && python.datascience.featureenabled" + "when": "python.datascience.isnativeactive && python.datascience.featureenabled && python.datascience.isnotebooktrusted" }, { "command": "python.datascience.exportToPDF", "title": "%python.command.python.datascience.exportToPDF.title%", "category": "Python", - "when": "python.datascience.isnativeactive && python.datascience.featureenabled" + "when": "python.datascience.isnativeactive && python.datascience.featureenabled && python.datascience.isnotebooktrusted" }, { "command": "python.switchOffInsidersChannel", @@ -1175,12 +1161,6 @@ "category": "Python", "when": "python.datascience.featureenabled && notebookEditorFocused && !python.datascience.isnotebooktrusted && python.datascience.trustfeatureenabled" }, - { - "command": "python.datascience.notebookeditor.trusted", - "title": "%DataScience.notebookIsTrusted%", - "category": "Python", - "when": "config.noExists" - }, { "command": "python.datascience.notebookeditor.runallcells", "title": "%python.command.python.datascience.notebookeditor.runallcells.title%", diff --git a/src/client/common/application/commands.ts b/src/client/common/application/commands.ts index dc310105fdb1..9e35df989c56 100644 --- a/src/client/common/application/commands.ts +++ b/src/client/common/application/commands.ts @@ -184,5 +184,4 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu [DSCommands.GatherQuality]: [string]; [DSCommands.EnableLoadingWidgetsFrom3rdPartySource]: [undefined | never]; [DSCommands.TrustNotebook]: [undefined | never | Uri]; - [DSCommands.TrustedNotebook]: [undefined | never]; } diff --git a/src/client/datascience/constants.ts b/src/client/datascience/constants.ts index 7d7b732a1e4c..5a371aa92ff5 100644 --- a/src/client/datascience/constants.ts +++ b/src/client/datascience/constants.ts @@ -91,7 +91,6 @@ export namespace Commands { export const OpenNotebookNonCustomEditor = 'python.datascience.notebookeditor.open'; export const GatherQuality = 'python.datascience.gatherquality'; export const TrustNotebook = 'python.datascience.notebookeditor.trust'; - export const TrustedNotebook = 'python.datascience.notebookeditor.trusted'; export const EnableLoadingWidgetsFrom3rdPartySource = 'python.datascience.enableLoadingWidgetScriptsFromThirdPartySource'; } diff --git a/src/client/datascience/interactive-ipynb/trustCommandHandler.ts b/src/client/datascience/interactive-ipynb/trustCommandHandler.ts index 09ee31f49e62..f7834234477f 100644 --- a/src/client/datascience/interactive-ipynb/trustCommandHandler.ts +++ b/src/client/datascience/interactive-ipynb/trustCommandHandler.ts @@ -13,7 +13,6 @@ import '../../common/extensions'; import { IDisposableRegistry, IExperimentService } from '../../common/types'; import { swallowExceptions } from '../../common/utils/decorators'; import { DataScience } from '../../common/utils/localize'; -import { noop } from '../../common/utils/misc'; import { Commands } from '../constants'; import { INotebookStorageProvider } from '../interactive-ipynb/notebookStorageProvider'; import { INotebookEditorProvider, ITrustService } from '../types'; @@ -39,7 +38,6 @@ export class TrustCommandHandler implements IExtensionSingleActivationService { const context = new ContextKey('python.datascience.trustfeatureenabled', this.commandManager); context.set(true).ignoreErrors(); this.disposables.push(this.commandManager.registerCommand(Commands.TrustNotebook, this.onTrustNotebook, this)); - this.disposables.push(this.commandManager.registerCommand(Commands.TrustedNotebook, noop)); } @swallowExceptions('Trusting notebook') private async onTrustNotebook(uri?: Uri) { From 80bae529959a8e07e504e96b584d2fe2aac00aa2 Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Mon, 13 Jul 2020 08:24:20 -0700 Subject: [PATCH 3/7] Don't forward trust changes to vscode (#12904) --- src/client/datascience/notebookStorage/notebookModel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/datascience/notebookStorage/notebookModel.ts b/src/client/datascience/notebookStorage/notebookModel.ts index 0bbe75705836..3b031870d81d 100644 --- a/src/client/datascience/notebookStorage/notebookModel.ts +++ b/src/client/datascience/notebookStorage/notebookModel.ts @@ -90,7 +90,7 @@ export class NativeEditorNotebookModel extends BaseNotebookModel { // Dirty state comes from undo. At least VS code will track it that way. However // skip file changes as we don't forward those to VS code - if (change.kind !== 'save' && change.kind !== 'saveAs') { + if (change.kind !== 'save' && change.kind !== 'saveAs' && change.kind !== 'updateTrust') { this.changeCount += 1; } From 5b7eb61780433d086e867a9fb4dac3d36ff87a1d Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Mon, 13 Jul 2020 08:30:48 -0700 Subject: [PATCH 4/7] Disable AddCellLine if notebook is untrusted (#12905) --- src/datascience-ui/native-editor/addCellLine.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/datascience-ui/native-editor/addCellLine.tsx b/src/datascience-ui/native-editor/addCellLine.tsx index 8f275cc072ce..f5513aafecc9 100644 --- a/src/datascience-ui/native-editor/addCellLine.tsx +++ b/src/datascience-ui/native-editor/addCellLine.tsx @@ -25,19 +25,23 @@ export class AddCellLine extends React.Component { const plus = this.props.includePlus ? ( ) : null; + const disabled = !this.props.isNotebookTrusted; + const innerFilter = disabled ? 'image-button-inner-disabled-filter' : ''; return (
); From 0a3893bdf2246f26d4cec89deda9f5c5186774e0 Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Mon, 13 Jul 2020 08:33:36 -0700 Subject: [PATCH 5/7] Log digest file name when updating trust (#12812) --- src/client/datascience/interactive-ipynb/digestStorage.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/client/datascience/interactive-ipynb/digestStorage.ts b/src/client/datascience/interactive-ipynb/digestStorage.ts index cba0fa78c91e..0db3feed5fa5 100644 --- a/src/client/datascience/interactive-ipynb/digestStorage.ts +++ b/src/client/datascience/interactive-ipynb/digestStorage.ts @@ -3,7 +3,7 @@ import { inject, injectable } from 'inversify'; import * as os from 'os'; import * as path from 'path'; import { Uri } from 'vscode'; -import { traceError } from '../../common/logger'; +import { traceError, traceInfo } from '../../common/logger'; import { isFileNotFoundError } from '../../common/platform/errors'; import { IFileSystem } from '../../common/platform/types'; import { IExtensionContext } from '../../common/types'; @@ -13,6 +13,7 @@ import { IDigestStorage } from '../types'; export class DigestStorage implements IDigestStorage { public readonly key: Promise; private digestDir: Promise; + private loggedFileLocations = new Set(); constructor( @inject(IFileSystem) private fs: IFileSystem, @@ -26,6 +27,10 @@ export class DigestStorage implements IDigestStorage { const fileLocation = await this.getFileLocation(uri); // Since the signature is a hex digest, the character 'z' is being used to delimit the start and end of a single digest await this.fs.appendFile(fileLocation, `z${signature}z\n`); + if (!this.loggedFileLocations.has(fileLocation)) { + traceInfo(`Wrote trust for ${uri.toString()} to ${fileLocation}`); + this.loggedFileLocations.add(fileLocation); + } } public async containsDigest(uri: Uri, signature: string) { From 1d8e5e6da160ff28acf2da9df0ccbc8874a80cd3 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 13 Jul 2020 10:13:34 -0700 Subject: [PATCH 6/7] Remove news entry --- news/3 Code Health/12893.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 news/3 Code Health/12893.md diff --git a/news/3 Code Health/12893.md b/news/3 Code Health/12893.md deleted file mode 100644 index 5a4d62330a56..000000000000 --- a/news/3 Code Health/12893.md +++ /dev/null @@ -1 +0,0 @@ -Disable Notebook icons when Notebook is not trusted. From 6804b977ca8323ddb6ef1d3d6495b2beb06fbaf8 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 13 Jul 2020 10:15:33 -0700 Subject: [PATCH 7/7] Update news entry --- CHANGELOG.md | 9 +++++++++ news/1 Enhancements/10496.md | 4 ---- news/3 Code Health/12554.md | 1 - news/3 Code Health/12844.md | 1 - 4 files changed, 9 insertions(+), 6 deletions(-) delete mode 100644 news/1 Enhancements/10496.md delete mode 100644 news/3 Code Health/12554.md delete mode 100644 news/3 Code Health/12844.md diff --git a/CHANGELOG.md b/CHANGELOG.md index dfd396dabe59..048f460119d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,11 @@ ([#12732](https://github.com/Microsoft/vscode-python/issues/12732)) 1. Show a prompt asking user to upgrade Code runner to new version to keep using it when in Deprecate PythonPath experiment. ([#12764](https://github.com/Microsoft/vscode-python/issues/12764)) +1. Opening notebooks in the preview Notebook editor for [Visual Studio Code Insiders](https://code.visualstudio.com/insiders/). + * Install Python extension in the latest [Visual Studio Code Insiders](https://code.visualstudio.com/insiders/). + * Wait for `Python Extension` to get activated (e.g. open a `Python` file). + * Right click on an `*.ipynb (Jupyter Notebook)` file and select `Open in preview Notebook Editor`. + ([#10496](https://github.com/Microsoft/vscode-python/issues/10496)) ### Fixes @@ -119,6 +124,10 @@ ([#12656](https://github.com/Microsoft/vscode-python/issues/12656)) 1. Add more telemetry for "Select Interpreter" command. ([#12722](https://github.com/Microsoft/vscode-python/issues/12722)) +1. Add tests for trusted notebooks. + ([#12554](https://github.com/Microsoft/vscode-python/issues/12554)) +1. Update categories in `package.json`. + ([#12844](https://github.com/Microsoft/vscode-python/issues/12844)) ### Thanks diff --git a/news/1 Enhancements/10496.md b/news/1 Enhancements/10496.md deleted file mode 100644 index e486012325cb..000000000000 --- a/news/1 Enhancements/10496.md +++ /dev/null @@ -1,4 +0,0 @@ -Opening notebooks in the preview Notebook editor for [Visual Studio Code Insiders](https://code.visualstudio.com/insiders/). -* Install Python extension in the latest [Visual Studio Code Insiders](https://code.visualstudio.com/insiders/). -* Wait for `Python Extension` to get activated (e.g. open a `Python` file). -* Right click on an `*.ipynb (Jupyter Notebook)` file and select `Open in preview Notebook Editor`. diff --git a/news/3 Code Health/12554.md b/news/3 Code Health/12554.md deleted file mode 100644 index 926f9f320057..000000000000 --- a/news/3 Code Health/12554.md +++ /dev/null @@ -1 +0,0 @@ -Add tests for trusted notebooks. diff --git a/news/3 Code Health/12844.md b/news/3 Code Health/12844.md deleted file mode 100644 index 004246586d91..000000000000 --- a/news/3 Code Health/12844.md +++ /dev/null @@ -1 +0,0 @@ -Update categories in `package.json`.