Skip to content

Commit f1a335b

Browse files
committed
removed python2Path setting #220
1 parent 7fca46a commit f1a335b

3 files changed

Lines changed: 21 additions & 25 deletions

File tree

package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,6 @@
275275
"default": "python",
276276
"description": "Path to Python, you can use a custom version of Python by modifying this setting to include the full path."
277277
},
278-
"python.python2Path": {
279-
"type": "string",
280-
"default": "python",
281-
"description": "Path to Python 2.x used for Refactoring. Refactoring only works when using Python 2.x"
282-
},
283278
"python.linting.enabled": {
284279
"type": "boolean",
285280
"default": true,

src/client/common/configSettings.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {EventEmitter} from 'events';
66

77
export interface IPythonSettings {
88
pythonPath: string;
9-
python2Path: string;
109
devOptions: any[];
1110
linting: ILintingSettings;
1211
formatting: IFormattingSettings;
@@ -82,11 +81,10 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
8281
}
8382
public static getInstance(): PythonSettings {
8483
return PythonSettings.pythonSettings;
85-
}
84+
}
8685
private initializeSettings() {
8786
let pythonSettings = vscode.workspace.getConfiguration('python');
8887
this.pythonPath = systemVariables.resolveAny(pythonSettings.get<string>('pythonPath'));
89-
this.python2Path = systemVariables.resolveAny(pythonSettings.get<string>('python2Path'));
9088
this.devOptions = systemVariables.resolveAny(pythonSettings.get<any[]>('devOptions'));
9189
this.devOptions = Array.isArray(this.devOptions) ? this.devOptions : [];
9290
let lintingSettings = systemVariables.resolveAny(pythonSettings.get<ILintingSettings>('linting'));
@@ -124,7 +122,6 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
124122
}
125123

126124
public pythonPath: string;
127-
public python2Path: string;
128125
public devOptions: any[];
129126
public linting: ILintingSettings;
130127
public formatting: IFormattingSettings;

src/client/refactor/proxy.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {ExtractResult} from './contracts';
88
import {execPythonFile} from '../common/utils';
99
import {IPythonSettings} from '../common/configSettings';
1010

11-
const ROPE_PYTHON_VERSION = 'Refactor requires Python 2.x. Set \'python.pythonRopePath\' in Settings.json';
11+
const ROPE_PYTHON_VERSION = 'Currently code refactoring is only supported in Python 2.x';
1212
const ERROR_PREFIX = '$ERROR';
1313

1414
export class RefactorProxy extends vscode.Disposable {
@@ -62,31 +62,35 @@ export class RefactorProxy extends vscode.Disposable {
6262
return Promise.resolve(RefactorProxy.pythonPath);
6363
}
6464

65-
if (this.pythonSettings.pythonPath === this.pythonSettings.python2Path) {
66-
// First try what ever path we have in pythonRopePath
67-
return this.checkIfPythonVersionIs3(this.pythonSettings.python2Path).then(() => {
68-
return this.pythonSettings.python2Path;
65+
// First try what ever path we have in pythonRopePath
66+
let promiseReult = this.checkIfPythonVersionIs2(this.pythonSettings.pythonPath).then(() => {
67+
return this.pythonSettings.pythonPath;
68+
});
69+
70+
if (this.pythonSettings.pythonPath !== 'python') {
71+
promiseReult = promiseReult.catch(() => {
72+
// Now try to use the default 'python' executable (if any)
73+
return this.checkIfPythonVersionIs2('python').then(() => {
74+
return 'python';
75+
});
6976
});
7077
}
7178

72-
// First try what ever path we have in pythonRopePath
73-
return this.checkIfPythonVersionIs3(this.pythonSettings.python2Path).then(() => {
74-
return this.pythonSettings.python2Path;
75-
}).catch(() => {
76-
// Now the path in pythonPath
77-
return this.checkIfPythonVersionIs3(this.pythonSettings.pythonPath).then(() => {
78-
return this.pythonSettings.pythonPath;
79+
return promiseReult.catch(() => {
80+
// Now try to find 'python2.7' (this seems to work on a Mac)
81+
return this.checkIfPythonVersionIs2('python2.7').then(() => {
82+
return 'python2.7';
7983
});
8084
});
8185
}
8286

83-
private checkIfPythonVersionIs3(pythonPath: string): Promise<boolean> {
87+
private checkIfPythonVersionIs2(pythonPath: string): Promise<boolean> {
8488
return new Promise<boolean>((resolve, reject) => {
8589
child_process.execFile(pythonPath, ['-c', 'import sys;print(sys.version)'], null, (error, stdout, stderr) => {
86-
if (stdout.indexOf('3.') === 0) {
87-
reject(new Error(ROPE_PYTHON_VERSION));
90+
if (stdout.indexOf('2.') === 0) {
91+
return resolve(true);
8892
}
89-
resolve(true);
93+
reject(new Error(ROPE_PYTHON_VERSION));
9094
});
9195
});
9296
}

0 commit comments

Comments
 (0)