diff --git a/python/ycm/paths.py b/python/ycm/paths.py index c715154f7f..e3a8a98254 100644 --- a/python/ycm/paths.py +++ b/python/ycm/paths.py @@ -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 memoizer( *args, **kwargs ): @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' ) diff --git a/python/ycm/tests/paths_test.py b/python/ycm/tests/paths_test.py index 4c2458e6e7..6ff5f434e8 100644 --- a/python/ycm/tests/paths_test.py +++ b/python/ycm/tests/paths_test.py @@ -1,4 +1,4 @@ -# Copyright (C) 2016 YouCompleteMe contributors +# Copyright (C) 2016-2017 YouCompleteMe contributors # # This file is part of YouCompleteMe. # @@ -26,15 +26,15 @@ MockVimModule() from nose.tools import ok_ -from ycm.paths import EndsWithPython +from ycm.paths import _EndsWithPython def EndsWithPython_Good( path ): - ok_( EndsWithPython( path ) ) + ok_( _EndsWithPython( path ) ) def EndsWithPython_Bad( path ): - ok_( not EndsWithPython( path ) ) + ok_( not _EndsWithPython( path ) ) def EndsWithPython_Python2Paths_test(): @@ -50,7 +50,6 @@ def EndsWithPython_Python2Paths_test(): yield EndsWithPython_Good, path - def EndsWithPython_Python3Paths_test(): python_paths = [ 'python3',