From be66c706734c4e8ca45a75d1eb526a37b64c85fa Mon Sep 17 00:00:00 2001 From: viewstar000 Date: Wed, 11 Jan 2017 12:27:00 +0800 Subject: [PATCH 1/2] add config : python.sortImports.path --- package.json | 5 +++++ src/client/common/configSettings.ts | 3 ++- src/client/providers/importSortProvider.ts | 9 ++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2853193b6203..be02d4b9ee2a 100644 --- a/package.json +++ b/package.json @@ -593,6 +593,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.", 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..3a1ff84ef131 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 (isort) { + 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); } From f176f89e21601fa9ff93f216a3ca4775c43cff75 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 30 Jan 2017 23:44:39 +1100 Subject: [PATCH 2/2] ensure isort length is > 0 --- src/client/providers/importSortProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/providers/importSortProvider.ts b/src/client/providers/importSortProvider.ts index 3a1ff84ef131..46889e33d26c 100644 --- a/src/client/providers/importSortProvider.ts +++ b/src/client/providers/importSortProvider.ts @@ -25,7 +25,7 @@ export class PythonImportSortProvider { const isort = settings.PythonSettings.getInstance().sortImports.path; const args = settings.PythonSettings.getInstance().sortImports.args.join(' '); let isort_cmd = ''; - if (isort) { + if (typeof isort === 'string' && isort.length > 0) { isort_cmd = `${isort} "${filePath}" --diff ${args}`; } else { isort_cmd = `${pythonPath} "${importScript}" "${filePath}" --diff ${args}`;