Skip to content

Commit d2f238b

Browse files
committed
fix #42
1 parent b866a5f commit d2f238b

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,14 @@
468468
"default": "python",
469469
"description": "Path to Python, you can use a custom version of Python by modifying this setting to include the full path."
470470
},
471+
"python.sortImports.args": {
472+
"type": "array",
473+
"description": "Arguments passed in. Each argument is a separate item in the array.",
474+
"default": [],
475+
"items": {
476+
"type": "string"
477+
}
478+
},
471479
"python.linting.enabled": {
472480
"type": "boolean",
473481
"default": true,

src/client/common/configSettings.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ export interface IPythonSettings {
1414
autoComplete: IAutoCompeteSettings;
1515
terminal: ITerminalSettings;
1616
jupyter: JupyterSettings;
17+
sortImports: ISortImportSettings;
1718
}
19+
20+
export interface ISortImportSettings {
21+
args: string[];
22+
}
23+
1824
export interface IUnitTestSettings {
1925
nosetestsEnabled: boolean;
2026
nosetestPath: string;
@@ -113,11 +119,17 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
113119
}
114120
else {
115121
this.linting = lintingSettings;
116-
if (IS_TEST_EXECUTION && !this.linting) {
117-
this.linting = {} as ILintingSettings;
118-
}
122+
}
123+
let sortImportSettings = systemVariables.resolveAny(pythonSettings.get<ISortImportSettings>('sortImports'));
124+
if (this.sortImports) {
125+
Object.assign<ISortImportSettings, ISortImportSettings>(this.sortImports, sortImportSettings);
126+
}
127+
else {
128+
this.sortImports = sortImportSettings;
119129
}
120130
// Support for travis
131+
this.sortImports = this.sortImports ? this.sortImports : { args: [] };
132+
// Support for travis
121133
this.linting = this.linting ? this.linting : {
122134
enabled: false,
123135
flake8Args: [], flake8Enabled: false, flake8Path: 'flake',
@@ -182,6 +194,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
182194
}
183195
}
184196
this.emit('change');
197+
185198
// Support for travis
186199
this.unitTest = this.unitTest ? this.unitTest : {
187200
nosetestArgs: [], nosetestPath: 'nosetest', nosetestsEnabled: false,
@@ -228,6 +241,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
228241
public unitTest: IUnitTestSettings;
229242
public terminal: ITerminalSettings;
230243
public jupyter: JupyterSettings;
244+
public sortImports: ISortImportSettings;
231245
}
232246

233247
function getAbsolutePath(pathToCheck: string, rootDir: string): string {

src/client/providers/importSortProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ 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-
child_process.exec(`${pythonPath} "${importScript}" "${filePath}" --diff`, (error, stdout, stderr) => {
25+
const args = settings.PythonSettings.getInstance().sortImports.args.join(' ');
26+
child_process.exec(`${pythonPath} "${importScript}" "${filePath}" --diff ${args}`, (error, stdout, stderr) => {
2627
if (tmpFileCreated) {
2728
fs.unlink(filePath);
2829
}

0 commit comments

Comments
 (0)