diff --git a/package.json b/package.json index 8c5d5e3c7237..d9819185aa6c 100644 --- a/package.json +++ b/package.json @@ -794,6 +794,11 @@ "default": "", "description": "Path to directory containing the Jedi library (this path will contain the 'Jedi' sub directory)." }, + "python.sortImports.path": { + "type": "string", + "description": "Path to isort script, default using inner version", + "default": "" + }, "python.sortImports.args": { "type": "array", "description": "Arguments passed in. Each argument is a separate item in the array.", @@ -1261,4 +1266,4 @@ "vscode": "^1.0.0", "webpack": "^1.13.2" } -} +} \ No newline at end of file diff --git a/src/client/common/configSettings.ts b/src/client/common/configSettings.ts index 7f91c712a589..19115bfe3197 100644 --- a/src/client/common/configSettings.ts +++ b/src/client/common/configSettings.ts @@ -23,6 +23,7 @@ export interface IPythonSettings { } export interface ISortImportSettings { + path: string; args: string[]; } @@ -156,7 +157,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings { this.sortImports = sortImportSettings; } // Support for travis - this.sortImports = this.sortImports ? this.sortImports : { args: [] }; + this.sortImports = this.sortImports ? this.sortImports : { path: '', args: [] }; // Support for travis this.linting = this.linting ? this.linting : { enabled: false, diff --git a/src/client/providers/importSortProvider.ts b/src/client/providers/importSortProvider.ts index a72e56a85342..46889e33d26c 100644 --- a/src/client/providers/importSortProvider.ts +++ b/src/client/providers/importSortProvider.ts @@ -22,8 +22,15 @@ export class PythonImportSortProvider { let filePromise = tmpFileCreated ? getTempFileWithDocumentContents(document) : Promise.resolve(document.fileName); filePromise.then(filePath => { const pythonPath = settings.PythonSettings.getInstance().pythonPath; + const isort = settings.PythonSettings.getInstance().sortImports.path; const args = settings.PythonSettings.getInstance().sortImports.args.join(' '); - child_process.exec(`${pythonPath} "${importScript}" "${filePath}" --diff ${args}`, (error, stdout, stderr) => { + let isort_cmd = ''; + if (typeof isort === 'string' && isort.length > 0) { + isort_cmd = `${isort} "${filePath}" --diff ${args}`; + } else { + isort_cmd = `${pythonPath} "${importScript}" "${filePath}" --diff ${args}`; + } + child_process.exec(isort_cmd, (error, stdout, stderr) => { if (tmpFileCreated) { fs.unlink(filePath); }