Skip to content

Commit 0d419f0

Browse files
viewstar000DonJayamanne
authored andcommitted
add config : python.sortImports.path (#632)
* add config : python.sortImports.path * ensure isort length is > 0
1 parent b7b7383 commit 0d419f0

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,11 @@
794794
"default": "",
795795
"description": "Path to directory containing the Jedi library (this path will contain the 'Jedi' sub directory)."
796796
},
797+
"python.sortImports.path": {
798+
"type": "string",
799+
"description": "Path to isort script, default using inner version",
800+
"default": ""
801+
},
797802
"python.sortImports.args": {
798803
"type": "array",
799804
"description": "Arguments passed in. Each argument is a separate item in the array.",
@@ -1261,4 +1266,4 @@
12611266
"vscode": "^1.0.0",
12621267
"webpack": "^1.13.2"
12631268
}
1264-
}
1269+
}

src/client/common/configSettings.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface IPythonSettings {
2323
}
2424

2525
export interface ISortImportSettings {
26+
path: string;
2627
args: string[];
2728
}
2829

@@ -156,7 +157,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
156157
this.sortImports = sortImportSettings;
157158
}
158159
// Support for travis
159-
this.sortImports = this.sortImports ? this.sortImports : { args: [] };
160+
this.sortImports = this.sortImports ? this.sortImports : { path: '', args: [] };
160161
// Support for travis
161162
this.linting = this.linting ? this.linting : {
162163
enabled: false,

src/client/providers/importSortProvider.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,15 @@ export class PythonImportSortProvider {
2222
let filePromise = tmpFileCreated ? getTempFileWithDocumentContents(document) : Promise.resolve(document.fileName);
2323
filePromise.then(filePath => {
2424
const pythonPath = settings.PythonSettings.getInstance().pythonPath;
25+
const isort = settings.PythonSettings.getInstance().sortImports.path;
2526
const args = settings.PythonSettings.getInstance().sortImports.args.join(' ');
26-
child_process.exec(`${pythonPath} "${importScript}" "${filePath}" --diff ${args}`, (error, stdout, stderr) => {
27+
let isort_cmd = '';
28+
if (typeof isort === 'string' && isort.length > 0) {
29+
isort_cmd = `${isort} "${filePath}" --diff ${args}`;
30+
} else {
31+
isort_cmd = `${pythonPath} "${importScript}" "${filePath}" --diff ${args}`;
32+
}
33+
child_process.exec(isort_cmd, (error, stdout, stderr) => {
2734
if (tmpFileCreated) {
2835
fs.unlink(filePath);
2936
}

0 commit comments

Comments
 (0)