Skip to content

Commit b376060

Browse files
authored
Merge pull request #539 from shengyfu/master
Enable pyspark development in vscode
2 parents 6a5cf63 + 43e6810 commit b376060

4 files changed

Lines changed: 63 additions & 2 deletions

File tree

package.json

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@
121121
"title": "Select Workspace Interpreter",
122122
"category": "Python"
123123
},
124+
{
125+
"command": "python.updateSparkLibrary",
126+
"title": "Update Workspace PySpark Libraries",
127+
"category": "Python"
128+
},
124129
{
125130
"command": "python.refactorExtractVariable",
126131
"title": "Extract Variable",
@@ -402,7 +407,21 @@
402407
"stopOnEntry": true,
403408
"pythonPath": "${config.python.pythonPath}",
404409
"program": "${file}",
405-
"cwd": "null",
410+
"cwd": "${workspaceRoot}",
411+
"debugOptions": [
412+
"WaitOnAbnormalExit",
413+
"WaitOnNormalExit",
414+
"RedirectOutput"
415+
]
416+
},
417+
{
418+
"name": "PySpark",
419+
"type": "python",
420+
"request": "launch",
421+
"stopOnEntry": true,
422+
"pythonPath": "${config.python.pysparkPath}",
423+
"program": "${file}",
424+
"cwd": "${workspaceRoot}",
406425
"debugOptions": [
407426
"WaitOnAbnormalExit",
408427
"WaitOnNormalExit",
@@ -548,6 +567,11 @@
548567
"default": "python",
549568
"description": "Path to Python, you can use a custom version of Python by modifying this setting to include the full path."
550569
},
570+
"python.pysparkPath": {
571+
"type": "string",
572+
"default": "${env.SPARK_HOME}/bin/spark-submit",
573+
"description": "Path to spark-submit executable, you can use a custom version of Spark by modifying this setting to include the full path."
574+
},
551575
"python.jediPath": {
552576
"type": "string",
553577
"default": "",

src/client/common/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export namespace Commands {
2121
export const Tests_Select_And_Debug_Method = 'python.selectAndDebugTestMethod';
2222
export const Refactor_Extract_Variable = 'python.refactorExtractVariable';
2323
export const Refaactor_Extract_Method = 'python.refactorExtractMethod';
24+
export const Update_SparkLibrary = 'python.updateSparkLibrary';
2425
export const Build_Workspace_Symbols = 'python.buildWorkspaceSymbols';
25-
2626
export namespace Jupyter {
2727
export const Get_All_KernelSpecs_For_Language = 'jupyter:getAllKernelSpecsForLanguage';
2828
export const Get_All_KernelSpecs = 'jupyter:getAllKernelSpecs';

src/client/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ import { activateExecInTerminalProvider } from './providers/execInTerminalProvid
2020
import * as tests from './unittests/main';
2121
import * as jup from './jupyter/main';
2222
import { HelpProvider } from './helpProvider';
23+
import { activateUpdateSparkLibraryProvider } from './providers/updateSparkLibraryProvider';
2324
import { activateFormatOnSaveProvider } from './providers/formatOnSaveProvider';
2425
import { WorkspaceSymbols } from './workspaceSymbols/main';
2526
import { BlockFormatProviders } from './typeFormatters/blockFormatProvider';
2627
import * as os from 'os';
2728

29+
2830
const PYTHON: vscode.DocumentFilter = { language: 'python', scheme: 'file' };
2931
let unitTestOutChannel: vscode.OutputChannel;
3032
let formatOutChannel: vscode.OutputChannel;
@@ -51,6 +53,7 @@ export function activate(context: vscode.ExtensionContext) {
5153
sortImports.activate(context, formatOutChannel);
5254
context.subscriptions.push(activateSetInterpreterProvider());
5355
context.subscriptions.push(...activateExecInTerminalProvider());
56+
context.subscriptions.push(activateUpdateSparkLibraryProvider());
5457
activateSimplePythonRefactorProvider(context, formatOutChannel);
5558
context.subscriptions.push(activateFormatOnSaveProvider(PYTHON, settings.PythonSettings.getInstance(), formatOutChannel, vscode.workspace.rootPath));
5659

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"use strict";
2+
import { Commands } from '../common/constants';
3+
import * as vscode from "vscode";
4+
import * as path from 'path';
5+
import { IS_WINDOWS } from '../common/utils';
6+
7+
export function activateUpdateSparkLibraryProvider(): vscode.Disposable {
8+
console.log('Register command python.updateSparkLibrary');
9+
return vscode.commands.registerCommand(Commands.Update_SparkLibrary, updateSparkLibrary);
10+
}
11+
12+
function updateSparkLibrary() {
13+
const pythonConfig = vscode.workspace.getConfiguration('python');
14+
const extraLibPath = 'autoComplete.extraPaths';
15+
let sparkHomePath = '${env.SPARK_HOME}';
16+
pythonConfig.update(extraLibPath, [path.join(sparkHomePath, 'python'),
17+
path.join(sparkHomePath, 'python/pyspark')]).then(() => {
18+
//Done
19+
}, reason => {
20+
vscode.window.showErrorMessage(`Failed to update ${extraLibPath}. Error: ${reason.message}`);
21+
console.error(reason);
22+
});
23+
if (IS_WINDOWS) {
24+
const pysparkPath = 'pysparkPath';
25+
console.log('Overriding ' + pysparkPath);
26+
pythonConfig.update(pysparkPath, path.join(sparkHomePath, 'bin', 'spark-submit.cmd')).then(() => {
27+
//Done
28+
}, reason => {
29+
vscode.window.showErrorMessage(`Failed to update ${pysparkPath}. Error: ${reason.message}`);
30+
console.error(reason);
31+
});
32+
}
33+
vscode.window.showInformationMessage(`Make sure you have SPARK_HOME environment variable set to the root path of the local spark installation!`);
34+
}

0 commit comments

Comments
 (0)