diff --git a/python/ycm/paths.py b/python/ycm/paths.py index a5d19061..51c3f575 100644 --- a/python/ycm/paths.py +++ b/python/ycm/paths.py @@ -63,6 +63,10 @@ def PathToPythonInterpreter(): raise RuntimeError( "Path in 'g:ycm_server_python_interpreter' option " "does not point to a valid Python 2.6+ or 3.3+." ) + python_interpreter = _PathToPythonUsedDuringBuild() + if IsPythonVersionCorrect( python_interpreter ): + return python_interpreter + # On UNIX platforms, we use sys.executable as the Python interpreter path. # We cannot use sys.executable on Windows because for unknown reasons, it # returns the Vim executable. Instead, we use sys.exec_prefix to deduce the @@ -90,9 +94,20 @@ def PathToPythonInterpreter(): "option." ) +def _PathToPythonUsedDuringBuild(): + from ycmd import utils + + try: + filepath = os.path.join( DIR_OF_YCMD, 'PYTHON_USED_DURING_BUILDING' ) + return utils.ReadFile( filepath ).strip() + # We need to check for IOError for Python2 and OSError for Python3 + except ( IOError, OSError ): + return None + + def EndsWithPython( path ): """Check if given path ends with a python 2.6+ or 3.3+ name.""" - return PYTHON_BINARY_REGEX.search( path ) is not None + return path and PYTHON_BINARY_REGEX.search( path ) is not None def IsPythonVersionCorrect( path ): diff --git a/python/ycm/tests/paths_test.py b/python/ycm/tests/paths_test.py index d9ccc915..e390f4f3 100644 --- a/python/ycm/tests/paths_test.py +++ b/python/ycm/tests/paths_test.py @@ -66,6 +66,8 @@ def EndsWithPython_Python3Paths_test(): def EndsWithPython_BadPaths_test(): not_python_paths = [ + None, + '', '/opt/local/bin/vim', r'C:\Program Files\Vim\vim74\gvim.exe', '/usr/bin/python2.5', diff --git a/third_party/ycmd b/third_party/ycmd index 09f21644..89e558f7 160000 --- a/third_party/ycmd +++ b/third_party/ycmd @@ -1 +1 @@ -Subproject commit 09f216441f99c02d51f9460e006683c5fe83669e +Subproject commit 89e558f7d49b6d9672477c0d1b4df41d33f1c2e7