@@ -8,7 +8,7 @@ import {ExtractResult} from './contracts';
88import { execPythonFile } from '../common/utils' ;
99import { 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 ' ;
1212const ERROR_PREFIX = '$ERROR' ;
1313
1414export 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