Skip to content

Commit

Permalink
Make python binary specifiable by the user
Browse files Browse the repository at this point in the history
  • Loading branch information
vheon committed Jan 7, 2016
1 parent 3c10266 commit 97dacdc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
35 changes: 29 additions & 6 deletions ycmd/completers/python/jedi_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ ) ),
Expand Down Expand Up @@ -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' ]
Expand Down Expand Up @@ -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()

Expand All @@ -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 ]
Expand Down Expand Up @@ -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 ) )
}


Expand Down Expand Up @@ -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 )

Expand Down
3 changes: 2 additions & 1 deletion ycmd/default_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@
"server_keep_logfiles": 0,
"gocode_binary_path": "",
"rust_src_path": "",
"racerd_binary_path": ""
"racerd_binary_path": "",
"python_binary_path": ""
}

0 comments on commit 97dacdc

Please sign in to comment.