Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add config : python.sortImports.path #632

Merged
merged 3 commits into from
Jan 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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