123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- from __future__ import unicode_literals
- from __future__ import print_function
- from __future__ import division
- from __future__ import absolute_import
- from builtins import *
- import os
- import sys
- import vim
- import re
- DIR_OF_CURRENT_SCRIPT = os.path.dirname( os.path.abspath( __file__ ) )
- DIR_OF_YCMD = os.path.join( DIR_OF_CURRENT_SCRIPT, '..', '..', 'third_party',
- 'ycmd' )
- WIN_PYTHON_PATH = os.path.join( sys.exec_prefix, 'python.exe' )
- PYTHON_BINARY_REGEX = re.compile(
- r'python((2(\.[67])?)|(3(\.[3-9])?))?(.exe)?$', re.IGNORECASE )
- def PathToPythonInterpreter():
-
-
- from ycmd import utils
- python_interpreter = vim.eval( 'g:ycm_server_python_interpreter' )
- if python_interpreter:
- python_interpreter = utils.FindExecutable( python_interpreter )
- if python_interpreter:
- return python_interpreter
- raise RuntimeError( "Path in 'g:ycm_server_python_interpreter' option "
- "does not point to a valid Python 2.7 or 3.4+." )
- python_interpreter = _PathToPythonUsedDuringBuild()
- if python_interpreter and utils.GetExecutable( python_interpreter ):
- return python_interpreter
-
-
-
-
- python_interpreter = ( WIN_PYTHON_PATH if utils.OnWindows() else
- sys.executable )
- if _EndsWithPython( python_interpreter ):
- return python_interpreter
-
-
-
-
-
- python_interpreter = utils.PathToFirstExistingExecutable( [ 'python2',
- 'python',
- 'python3' ] )
- if python_interpreter:
- return python_interpreter
- raise RuntimeError( "Cannot find Python 2.7 or 3.4+. "
- "Set the 'g:ycm_server_python_interpreter' option "
- "to a Python interpreter path." )
- def _PathToPythonUsedDuringBuild():
- from ycmd import utils
- try:
- filepath = os.path.join( DIR_OF_YCMD, 'PYTHON_USED_DURING_BUILDING' )
- return utils.ReadFile( filepath ).strip()
-
- except ( IOError, OSError ):
- return None
- def _EndsWithPython( path ):
- """Check if given path ends with a python 2.7 or 3.4+ name."""
- return path and PYTHON_BINARY_REGEX.search( path ) is not None
- def PathToServerScript():
- return os.path.join( DIR_OF_YCMD, 'ycmd' )
|