paths.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python
  2. #
  3. # Copyright (C) 2015 YouCompleteMe contributors.
  4. #
  5. # This file is part of YouCompleteMe.
  6. #
  7. # YouCompleteMe is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # YouCompleteMe is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
  19. import os
  20. import vim
  21. import functools
  22. from ycmd import utils
  23. DIR_OF_CURRENT_SCRIPT = os.path.dirname( os.path.abspath( __file__ ) )
  24. WIN_PYTHON27_PATH = 'C:\python27\python.exe'
  25. WIN_PYTHON26_PATH = 'C:\python26\python.exe'
  26. def Memoize( obj ):
  27. cache = obj.cache = {}
  28. @functools.wraps( obj )
  29. def memoizer( *args, **kwargs ):
  30. key = str( args ) + str( kwargs )
  31. if key not in cache:
  32. cache[ key ] = obj( *args, **kwargs )
  33. return cache[ key ]
  34. return memoizer
  35. @Memoize
  36. def PathToPythonInterpreter():
  37. user_path_to_python = vim.eval( 'g:ycm_path_to_python_interpreter' )
  38. if user_path_to_python:
  39. return user_path_to_python
  40. # We check for 'python2' before 'python' because some OS's (I'm looking at
  41. # you Arch Linux) have made the... interesting decision to point
  42. # /usr/bin/python to python3.
  43. python_names = [ 'python2', 'python' ]
  44. path_to_python = utils.PathToFirstExistingExecutable( python_names )
  45. if path_to_python:
  46. return path_to_python
  47. # On Windows, Python may not be on the PATH at all, so we check some common
  48. # install locations.
  49. if utils.OnWindows():
  50. if os.path.exists( WIN_PYTHON27_PATH ):
  51. return WIN_PYTHON27_PATH
  52. elif os.path.exists( WIN_PYTHON26_PATH ):
  53. return WIN_PYTHON26_PATH
  54. raise RuntimeError( 'Python 2.7/2.6 not installed!' )
  55. def PathToServerScript():
  56. return os.path.join( DIR_OF_CURRENT_SCRIPT, '..', '..', 'third_party',
  57. 'ycmd', 'ycmd' )
  58. def PathToCheckCoreVersion():
  59. return os.path.join( DIR_OF_CURRENT_SCRIPT, '..', '..', 'third_party',
  60. 'ycmd', 'check_core_version.py' )