Skip to content

Commit

Permalink
add config : python.sortImports.path (#632)
Browse files Browse the repository at this point in the history
* add config :  python.sortImports.path

* ensure isort length is > 0
  • Loading branch information
viewstar000 authored and DonJayamanne committed Jan 30, 2017
1 parent b7b7383 commit 0d419f0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -1261,4 +1266,4 @@
"vscode": "^1.0.0",
"webpack": "^1.13.2"
}
}
}
3 changes: 2 additions & 1 deletion src/client/common/configSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface IPythonSettings {
}

export interface ISortImportSettings {
path: string;
args: string[];
}

Expand Down Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion src/client/providers/importSortProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 0d419f0

Please sign in to comment.