diff --git a/ycmd/completers/python/jedi_completer.py b/ycmd/completers/python/jedi_completer.py index e7e3b7d7c5..7ae2db49c7 100644 --- a/ycmd/completers/python/jedi_completer.py +++ b/ycmd/completers/python/jedi_completer.py @@ -34,7 +34,8 @@ HMAC_SECRET_LENGTH = 16 -PYTHON_EXECUTABLE_PATH = sys.executable +BINARY_NOT_FOUND_MESSAGE = ( 'The python interpreted specified was not found. ' + + 'Did you specified it correctly?' ) LOG_FILENAME_FORMAT = os.path.join( utils.PathToTempDir(), u'jedihttp_{port}_{std}.log' ) PATH_TO_JEDIHTTP = os.path.join( os.path.abspath( os.path.dirname( __file__ ) ), @@ -71,9 +72,27 @@ def __init__( self, user_options ): self._logfile_stderr = None self._keep_logfiles = user_options[ 'server_keep_logfiles' ] self._hmac_secret = '' + self._binary_path = sys.executable + + user_binary = user_options.get( 'python_binary_path' ) + self._UpdatePythonBinary( user_binary ) + self._StartServer() + def _UpdatePythonBinary( self, binary ): + if binary: + if not self._CheckBinaryExists( binary ): + self._logger.error( BINARY_NOT_FOUND_MESSAGE ) + raise RuntimeError( BINARY_NOT_FOUND_MESSAGE ) + self._binary_path = binary + + + def _CheckBinaryExists( self, binary ): + """This method is here to help tesing""" + return os.path.isfile( binary ) + + def SupportedFiletypes( self ): """ Just python """ return [ 'python' ] @@ -104,9 +123,11 @@ def ServerIsRunning( self ): return False - def RestartServer( self, request_data ): + def RestartServer( self, request_data, binary = None ): """ Restart the JediHTTP Server. """ with self._server_lock: + if binary: + self._UpdatePythonBinary( binary ) self._StopServer() self._StartServer() @@ -131,7 +152,7 @@ def _StartServer( self ): self._GenerateHmacSecret() with hmaclib.TemporaryHmacSecretFile( self._hmac_secret ) as hmac_file: - command = [ PYTHON_EXECUTABLE_PATH, + command = [ self._binary_path, PATH_TO_JEDIHTTP, '--port', str( self._jedihttp_port ), '--hmac-file-secret', hmac_file.name ] @@ -242,7 +263,7 @@ def GetSubcommandsMap( self ): 'StopServer' : ( lambda self, request_data, args: self.Shutdown() ), 'RestartServer' : ( lambda self, request_data, args: - self.RestartServer() ) + self.RestartServer( request_data, *args ) ) } @@ -325,8 +346,10 @@ def DebugInfo( self, request_data ): with self._server_lock: if self.ServerIsRunning(): return ( 'JediHTTP running at 127.0.0.1:{0}\n' - ' stdout log: {1}\n' - ' stderr log: {2}' ).format( self._jedihttp_port, + ' python binary: {1}\n' + ' stdout log: {2}\n' + ' stderr log: {3}' ).format( self._jedihttp_port, + self._binary_path, self._logfile_stdout, self._logfile_stderr ) diff --git a/ycmd/default_settings.json b/ycmd/default_settings.json index 6e483b69e0..76713525ae 100644 --- a/ycmd/default_settings.json +++ b/ycmd/default_settings.json @@ -40,5 +40,6 @@ "server_keep_logfiles": 0, "gocode_binary_path": "", "rust_src_path": "", - "racerd_binary_path": "" + "racerd_binary_path": "", + "python_binary_path": "" }