Skip to content

Commit b15a1df

Browse files
author
Kartik Raj
authored
Improve how to notify the user they don't have Python installed when installing the Python extension for the first time (#19379)
* Improve how to notify the user they don't have Python installed when installing the Python extension for the first time * Code reviews * Ensure create a python file automatically selects the language for the file as python * Hide tiles by default for Mac and Linux * Remove built-in new python file command
1 parent 810588b commit b15a1df

File tree

19 files changed

+378
-170
lines changed

19 files changed

+378
-170
lines changed

package.json

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"onDebugInitialConfigurations",
6464
"onLanguage:python",
6565
"onDebugResolve:python",
66-
"onCommand:python.createNewFile",
6766
"onCommand:python.execInTerminal",
6867
"onCommand:python.debugInTerminal",
6968
"onCommand:python.sortImports",
@@ -106,13 +105,23 @@
106105
"when": "workspacePlatform != webworker",
107106
"steps": [
108107
{
109-
"id": "python.installPythonWin",
108+
"id": "python.createPythonFile",
109+
"title": "Create a Python file",
110+
"description": "[Open](command:toSide:workbench.action.files.openFile) or [create](command:toSide:workbench.action.files.newUntitledFile?%7B%22languageId%22%3A%22python%22%7D) a Python file - make sure to save it as \".py\".\n[Create Python File](command:toSide:workbench.action.files.newUntitledFile?%7B%22languageId%22%3A%22python%22%7D)",
111+
"media": {
112+
"svg": "resources/walkthrough/open-folder.svg",
113+
"altText": "Open a Python file or a folder with a Python project."
114+
},
115+
"when": ""
116+
},
117+
{
118+
"id": "python.installPythonWin8",
110119
"title": "Install Python",
111-
"description": "The Python Extension requires Python to be installed. Install Python from the [Microsoft Store](https://aka.ms/AAd9rms).\n\n[Install Python](https://aka.ms/AAd9rms)\n",
120+
"description": "The Python Extension requires Python to be installed. Install Python [from python.org](https://www.python.org/downloads).\n\n[Install Python](https://www.python.org/downloads)\n",
112121
"media": {
113-
"markdown": "resources/walkthrough/install-python-windows.md"
122+
"markdown": "resources/walkthrough/install-python-windows-8.md"
114123
},
115-
"when": "workspacePlatform == windows"
124+
"when": "workspacePlatform == windows && showInstallPythonTile"
116125
},
117126
{
118127
"id": "python.installPythonMac",
@@ -121,7 +130,7 @@
121130
"media": {
122131
"markdown": "resources/walkthrough/install-python-macos.md"
123132
},
124-
"when": "workspacePlatform == mac",
133+
"when": "workspacePlatform == mac && showInstallPythonTile",
125134
"command": "workbench.action.terminal.new"
126135
},
127136
{
@@ -131,19 +140,9 @@
131140
"media": {
132141
"markdown": "resources/walkthrough/install-python-linux.md"
133142
},
134-
"when": "workspacePlatform == linux",
143+
"when": "workspacePlatform == linux && showInstallPythonTile",
135144
"command": "workbench.action.terminal.new"
136145
},
137-
{
138-
"id": "python.createPythonFile",
139-
"title": "Create a Python file",
140-
"description": "[Open](command:toSide:workbench.action.files.openFile) or [create](command:toSide:python.createNewFile) a Python file - make sure to save it as \".py\".\n[Create Python File](command:toSide:python.createNewFile)",
141-
"media": {
142-
"svg": "resources/walkthrough/open-folder.svg",
143-
"altText": "Open a Python file or a folder with a Python project."
144-
},
145-
"when": ""
146-
},
147146
{
148147
"id": "python.selectInterpreter",
149148
"title": "Select a Python Interpreter",
@@ -247,12 +246,6 @@
247246
}
248247
],
249248
"commands": [
250-
{
251-
"title": "%python.command.python.createNewFile.title%",
252-
"shortTitle": "%python.menu.createNewFile.title%",
253-
"category": "Python",
254-
"command": "python.createNewFile"
255-
},
256249
{
257250
"category": "Python",
258251
"command": "python.analysis.restartLanguageServer",
@@ -1709,13 +1702,6 @@
17091702
"when": "resourceLangId == python && !virtualWorkspace && shellExecutionSupported"
17101703
}
17111704
],
1712-
"file/newFile": [
1713-
{
1714-
"command": "python.createNewFile",
1715-
"group": "file",
1716-
"when": "!virtualWorkspace"
1717-
}
1718-
],
17191705
"view/title": [
17201706
{
17211707
"command": "testing.reRunFailTests",

package.nls.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"python.command.python.sortImports.title": "Sort Imports",
33
"python.command.python.startREPL.title": "Start REPL",
44
"python.command.python.createTerminal.title": "Create Terminal",
5-
"python.command.python.createNewFile.title": "New Python File",
65
"python.command.python.execInTerminal.title": "Run Python File in Terminal",
76
"python.command.python.debugInTerminal.title": "Debug Python File",
87
"python.command.python.execInTerminalIcon.title": "Run Python File",
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
## Install Python on Windows
2-
3-
If you don't have Python installed on your Windows machine, you can install it from the [Microsoft Store](https://aka.ms/AAd9rms).
4-
5-
To verify it's installed, create a new terminal (<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>`</kbd>) and try running the following command:
6-
7-
```
8-
python --version
9-
```
10-
11-
You should see something similar to the following:
12-
```
13-
Python 3.9.5
14-
```
1+
## Install Python on Windows
2+
3+
If you don't have Python installed on your Windows machine, you can install it [from python.org](https://www.python.org/downloads).
4+
5+
To verify it's installed, create a new terminal (<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>`</kbd>) and try running the following command:
6+
7+
```
8+
python --version
9+
```
10+
11+
You should see something similar to the following:
12+
```
13+
Python 3.9.5
14+
```
15+
For additional information about using Python on Windows, see [Using Python on Windows at Python.org](https://docs.python.org/3.10/using/windows.html).

src/client/common/application/commands.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type CommandsWithoutArgs = keyof ICommandNameWithoutArgumentTypeMapping;
1616
* @interface ICommandNameWithoutArgumentTypeMapping
1717
*/
1818
interface ICommandNameWithoutArgumentTypeMapping {
19+
[Commands.InstallPython]: [];
1920
[Commands.ClearWorkspaceInterpreter]: [];
2021
[Commands.Set_Interpreter]: [];
2122
[Commands.Set_ShebangInterpreter]: [];
@@ -40,7 +41,6 @@ interface ICommandNameWithoutArgumentTypeMapping {
4041
[Commands.PickLocalProcess]: [];
4142
[Commands.ClearStorage]: [];
4243
[Commands.ReportIssue]: [];
43-
[Commands.CreateNewFile]: [];
4444
[Commands.RefreshTensorBoard]: [];
4545
[LSCommands.RestartLS]: [];
4646
}
@@ -57,6 +57,7 @@ export type AllCommands = keyof ICommandNameArgumentTypeMapping;
5757
export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgumentTypeMapping {
5858
['vscode.openWith']: [Uri, string];
5959
['workbench.action.quickOpen']: [string];
60+
['workbench.action.openWalkthrough']: [string | { category: string; step: string }, boolean | undefined];
6061
['workbench.extensions.installExtension']: [
6162
Uri | 'ms-python.python',
6263
(

src/client/common/application/commands/createFileCommand.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/client/common/application/contextKeys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
export enum ExtensionContextKey {
5+
showInstallPythonTile = 'showInstallPythonTile',
56
HasFailedTests = 'hasFailedTests',
67
RefreshingTests = 'refreshingTests',
78
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
export enum PythonWelcome {
5+
name = 'pythonWelcome',
6+
windowsInstallId = 'python.installPythonWin8',
7+
linuxInstallId = 'python.installPythonLinux',
8+
macOSInstallId = 'python.installPythonMac',
9+
}

src/client/common/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export namespace Commands {
4545
export const ViewOutput = 'python.viewOutput';
4646
export const Start_REPL = 'python.startREPL';
4747
export const Create_Terminal = 'python.createTerminal';
48-
export const CreateNewFile = 'python.createNewFile';
4948
export const Set_Linter = 'python.setLinter';
5049
export const Enable_Linter = 'python.enableLinting';
5150
export const Run_Linter = 'python.runLinting';
@@ -57,6 +56,7 @@ export namespace Commands {
5756
export const LaunchTensorBoard = 'python.launchTensorBoard';
5857
export const RefreshTensorBoard = 'python.refreshTensorBoard';
5958
export const ReportIssue = 'python.reportIssue';
59+
export const InstallPython = 'python.installPython';
6060
}
6161

6262
// Look at https://microsoft.github.io/vscode-codicons/dist/codicon.html for other Octicon icon ids
@@ -72,6 +72,7 @@ export namespace Octicons {
7272
export const Star = '$(star-full)';
7373
export const Gear = '$(gear)';
7474
export const Warning = '$(warning)';
75+
export const Error = '$(error)';
7576
}
7677

7778
export const DEFAULT_INTERPRETER_SETTING = 'python';

src/client/common/serviceRegistry.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { ClipboardService } from './application/clipboard';
3030
import { CommandManager } from './application/commandManager';
3131
import { ReloadVSCodeCommandHandler } from './application/commands/reloadCommand';
3232
import { ReportIssueCommandHandler } from './application/commands/reportIssueCommand';
33-
import { CreatePythonFileCommandHandler } from './application/commands/createFileCommand';
3433
import { DebugService } from './application/debugService';
3534
import { DebugSessionTelemetry } from './application/debugSessionTelemetry';
3635
import { DocumentManager } from './application/documentManager';
@@ -177,10 +176,6 @@ export function registerTypes(serviceManager: IServiceManager): void {
177176
IExtensionSingleActivationService,
178177
ReportIssueCommandHandler,
179178
);
180-
serviceManager.addSingleton<IExtensionSingleActivationService>(
181-
IExtensionSingleActivationService,
182-
CreatePythonFileCommandHandler,
183-
);
184179
serviceManager.addSingleton<IExtensionSingleActivationService>(
185180
IExtensionSingleActivationService,
186181
DebugSessionTelemetry,

src/client/common/utils/localize.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ export namespace Interpreters {
280280
}
281281

282282
export namespace InterpreterQuickPickList {
283+
export const noPythonInstalled = localize(
284+
'InterpreterQuickPickList.noPythonInstalled',
285+
'Python is not installed, please download and install it',
286+
);
287+
export const clickForInstructions = localize(
288+
'InterpreterQuickPickList.clickForInstructions',
289+
'Click for instructions...',
290+
);
283291
export const globalGroupName = localize('InterpreterQuickPickList.globalGroupName', 'Global');
284292
export const workspaceGroupName = localize('InterpreterQuickPickList.workspaceGroupName', 'Workspace');
285293
export const enterPath = {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
import { inject, injectable } from 'inversify';
7+
import { IExtensionSingleActivationService } from '../../../../activation/types';
8+
import { ExtensionContextKey } from '../../../../common/application/contextKeys';
9+
import { ICommandManager, IContextKeyManager } from '../../../../common/application/types';
10+
import { PythonWelcome } from '../../../../common/application/walkThroughs';
11+
import { Commands, PVSC_EXTENSION_ID } from '../../../../common/constants';
12+
import { IBrowserService, IDisposableRegistry } from '../../../../common/types';
13+
import { IPlatformService } from '../../../../common/platform/types';
14+
15+
@injectable()
16+
export class InstallPythonCommand implements IExtensionSingleActivationService {
17+
public readonly supportedWorkspaceTypes = { untrustedWorkspace: false, virtualWorkspace: false };
18+
19+
constructor(
20+
@inject(ICommandManager) private readonly commandManager: ICommandManager,
21+
@inject(IContextKeyManager) private readonly contextManager: IContextKeyManager,
22+
@inject(IBrowserService) private readonly browserService: IBrowserService,
23+
@inject(IPlatformService) private readonly platformService: IPlatformService,
24+
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry,
25+
) {}
26+
27+
public async activate(): Promise<void> {
28+
this.disposables.push(this.commandManager.registerCommand(Commands.InstallPython, () => this._installPython()));
29+
}
30+
31+
public async _installPython(): Promise<void> {
32+
if (this.platformService.isWindows) {
33+
const version = await this.platformService.getVersion();
34+
if (version.major > 8) {
35+
// OS is not Windows 8, ms-windows-store URIs are available:
36+
// https://docs.microsoft.com/en-us/windows/uwp/launch-resume/launch-store-app
37+
this.browserService.launch('ms-windows-store://pdp/?ProductId=9PJPW5LDXLZ5');
38+
return;
39+
}
40+
}
41+
this.showInstallPythonTile();
42+
}
43+
44+
private showInstallPythonTile() {
45+
this.contextManager.setContext(ExtensionContextKey.showInstallPythonTile, true);
46+
let step: string;
47+
if (this.platformService.isWindows) {
48+
step = PythonWelcome.windowsInstallId;
49+
} else if (this.platformService.isLinux) {
50+
step = PythonWelcome.linuxInstallId;
51+
} else {
52+
step = PythonWelcome.macOSInstallId;
53+
}
54+
this.commandManager.executeCommand(
55+
'workbench.action.openWalkthrough',
56+
{
57+
category: `${PVSC_EXTENSION_ID}#${PythonWelcome.name}`,
58+
step: `${PVSC_EXTENSION_ID}#${PythonWelcome.name}#${step}`,
59+
},
60+
false,
61+
);
62+
}
63+
}

0 commit comments

Comments
 (0)