|
@@ -1,4 +1,4 @@
|
|
|
-# Copyright (C) 2015 YouCompleteMe contributors.
|
|
|
+# Copyright (C) 2015-2017 YouCompleteMe contributors.
|
|
|
#
|
|
|
# This file is part of YouCompleteMe.
|
|
|
#
|
|
@@ -51,19 +51,20 @@ def Memoize( obj ):
|
|
|
|
|
|
@Memoize
|
|
|
def PathToPythonInterpreter():
|
|
|
+ # Not calling the Python interpreter to check its version as it significantly
|
|
|
+ # impacts startup time.
|
|
|
from ycmd import utils
|
|
|
|
|
|
python_interpreter = vim.eval( 'g:ycm_server_python_interpreter' )
|
|
|
-
|
|
|
if python_interpreter:
|
|
|
- if IsPythonVersionCorrect( python_interpreter ):
|
|
|
+ if _EndsWithPython( python_interpreter ):
|
|
|
return python_interpreter
|
|
|
|
|
|
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 ):
|
|
|
+ if _EndsWithPython( python_interpreter ):
|
|
|
return python_interpreter
|
|
|
|
|
|
# On UNIX platforms, we use sys.executable as the Python interpreter path.
|
|
@@ -72,8 +73,7 @@ def PathToPythonInterpreter():
|
|
|
# interpreter path.
|
|
|
python_interpreter = ( WIN_PYTHON_PATH if utils.OnWindows() else
|
|
|
sys.executable )
|
|
|
-
|
|
|
- if IsPythonVersionCorrect( python_interpreter ):
|
|
|
+ if _EndsWithPython( python_interpreter ):
|
|
|
return python_interpreter
|
|
|
|
|
|
# As a last resort, we search python in the PATH. We prefer Python 2 over 3
|
|
@@ -84,8 +84,7 @@ def PathToPythonInterpreter():
|
|
|
python_interpreter = utils.PathToFirstExistingExecutable( [ 'python2',
|
|
|
'python',
|
|
|
'python3' ] )
|
|
|
-
|
|
|
- if IsPythonVersionCorrect( python_interpreter ):
|
|
|
+ if python_interpreter:
|
|
|
return python_interpreter
|
|
|
|
|
|
raise RuntimeError( "Cannot find Python 2.6+ or 3.3+. You can set its path "
|
|
@@ -104,34 +103,10 @@ def _PathToPythonUsedDuringBuild():
|
|
|
return None
|
|
|
|
|
|
|
|
|
-def EndsWithPython( path ):
|
|
|
+def _EndsWithPython( path ):
|
|
|
"""Check if given path ends with a python 2.6+ or 3.3+ name."""
|
|
|
return path and PYTHON_BINARY_REGEX.search( path ) is not None
|
|
|
|
|
|
|
|
|
-def IsPythonVersionCorrect( path ):
|
|
|
- """Check if given path is the Python interpreter version 2.6+ or 3.3+."""
|
|
|
- from ycmd import utils
|
|
|
-
|
|
|
- if not EndsWithPython( path ):
|
|
|
- return False
|
|
|
-
|
|
|
- command = [ path,
|
|
|
- # Disable site customize. Faster, and less likely to encounter
|
|
|
- # issues with disconnected mounts (nfs, fuse, etc.)
|
|
|
- '-S',
|
|
|
- '-c',
|
|
|
- "import sys;"
|
|
|
- "major, minor = sys.version_info[ :2 ];"
|
|
|
- "good_python = ( major == 2 and minor >= 6 ) "
|
|
|
- "or ( major == 3 and minor >= 3 ) or major > 3;"
|
|
|
- # If this looks weird, remember that:
|
|
|
- # int( True ) == 1
|
|
|
- # int( False ) == 0
|
|
|
- "sys.exit( not good_python )" ]
|
|
|
-
|
|
|
- return utils.SafePopen( command ).wait() == 0
|
|
|
-
|
|
|
-
|
|
|
def PathToServerScript():
|
|
|
return os.path.join( DIR_OF_YCMD, 'ycmd' )
|