From 450403044bdcaf5a79b7f9c85a8392faaa968921 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Thu, 14 Nov 2013 10:50:05 -0800 Subject: [PATCH] Adding new g:ycm_path_to_python_interpreter option Fixes #663 --- README.md | 14 ++++++++++++++ plugin/youcompleteme.vim | 3 +++ python/ycm/utils.py | 33 +++++++++++++++++++++------------ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index bb573878..81f5f41f 100644 --- a/README.md +++ b/README.md @@ -887,6 +887,20 @@ Default: `[]` let g:ycm_extra_conf_vim_data = [] +### The `g:ycm_path_to_python_interpreter` option + +YCM will by default search for an appropriate Python interpreter on your system. +You can use this option to override that behavior and force the use of a +specific interpreter of your choosing. + +NOTE: This interpreter is only used for the `ycmd` server. The YCM client +running inside Vim always uses the Python interpreter that's embedded inside +Vim. + +Default: `''` + + let g:ycm_path_to_python_interpreter = '' + ### The `g:ycm_server_use_vim_stdout` option By default, the `ycmd` completion server writes logs to logfiles. When this diff --git a/plugin/youcompleteme.vim b/plugin/youcompleteme.vim index 6bf51377..e8849cc6 100644 --- a/plugin/youcompleteme.vim +++ b/plugin/youcompleteme.vim @@ -116,6 +116,9 @@ let g:ycm_server_idle_suicide_seconds = let g:ycm_extra_conf_vim_data = \ get( g:, 'ycm_extra_conf_vim_data', [] ) +let g:ycm_path_to_python_interpreter = + \ get( g:, 'path_to_python_interpreter', '' ) + " On-demand loading. Let's use the autoload folder and not slow down vim's " startup procedure. diff --git a/python/ycm/utils.py b/python/ycm/utils.py index 5384c62d..124f98fd 100644 --- a/python/ycm/utils.py +++ b/python/ycm/utils.py @@ -79,7 +79,28 @@ def GetUnusedLocalhostPort(): return port +def Memoize( obj ): + cache = obj.cache = {} + + @functools.wraps( obj ) + def memoizer( *args, **kwargs ): + key = str( args ) + str( kwargs ) + if key not in cache: + cache[ key ] = obj( *args, **kwargs ) + return cache[ key ] + return memoizer + + +@Memoize def PathToPythonInterpreter(): + if not RunningInsideVim(): + return sys.executable + + import vim # NOQA + user_path_to_python = vim.eval( 'g:ycm_path_to_python_interpreter' ) + if user_path_to_python: + return user_path_to_python + # We check for 'python2' before 'python' because some OS's (I'm looking at you # Arch Linux) have made the... interesting decision to point /usr/bin/python # to python3. @@ -138,18 +159,6 @@ def AddThirdPartyFoldersToSysPath(): sys.path.insert( 0, os.path.realpath( os.path.join( path_to_third_party, folder ) ) ) -def Memoize( obj ): - cache = obj.cache = {} - - @functools.wraps( obj ) - def memoizer( *args, **kwargs ): - key = str( args ) + str( kwargs ) - if key not in cache: - cache[ key ] = obj( *args, **kwargs ) - return cache[ key ] - return memoizer - - def ForceSemanticCompletion( request_data ): return ( 'force_semantic' in request_data and bool( request_data[ 'force_semantic' ] ) )