Esempio n. 1
0
def Load(module_file, force=False):
    """Load and return the module contained in a file.
  Using force = True the module will be loaded regardless
  of the criteria in _ShouldLoad.
  This will return None if the module was not allowed to be loaded."""

    if not module_file:
        return None

    if not force:
        with _module_for_module_file_lock:
            if module_file in _module_for_module_file:
                return _module_for_module_file[module_file]

        if not _ShouldLoad(module_file):
            Disable(module_file)
            return None

    # This has to be here because a long time ago, the ycm_extra_conf.py files
    # used to import clang_helpers.py from the cpp folder. This is not needed
    # anymore, but there are a lot of old ycm_extra_conf.py files that we don't
    # want to break.
    sys.path.insert(0, _PathToCppCompleterFolder())
    module = LoadPythonSource(_RandomName(), module_file)
    del sys.path[0]

    with _module_for_module_file_lock:
        _module_for_module_file[module_file] = module
    return module
Esempio n. 2
0
def Load( module_file, force = False ):
  """Load and return the module contained in a file.
  Using force = True the module will be loaded regardless
  of the criteria in _ShouldLoad.
  This will return None if the module was not allowed to be loaded."""

  if not module_file:
    return None

  with _module_for_module_file_lock:
    if module_file in _module_for_module_file:
      return _module_for_module_file[ module_file ]

  is_global = module_file == _GlobalYcmExtraConfFileLocation()
  if not force and not _ShouldLoad( module_file, is_global ):
    Disable( module_file )
    return None

  # This has to be here because a long time ago, the ycm_extra_conf.py files
  # used to import clang_helpers.py from the cpp folder. This is not needed
  # anymore, but there are a lot of old ycm_extra_conf.py files that we don't
  # want to break.
  sys.path.insert( 0, _PathToCppCompleterFolder() )

  # By default, the Python interpreter compiles source files into bytecode to
  # load them faster next time they are run. These *.pyc files are generated
  # along the source files prior to Python 3.2 or in a __pycache__ folder for
  # newer versions. We disable the generation of these files when loading
  # ycm_extra_conf.py files as users do not want them inside their projects.
  # The drawback is negligible since ycm_extra_conf.py files are generally small
  # files thus really fast to compile and only loaded once by editing session.
  old_dont_write_bytecode = sys.dont_write_bytecode
  sys.dont_write_bytecode = True
  try:
    module = LoadPythonSource( _RandomName(), module_file )
    module.is_global_ycm_extra_conf = is_global
  finally:
    sys.dont_write_bytecode = old_dont_write_bytecode

  del sys.path[ 0 ]

  with _module_for_module_file_lock:
    _module_for_module_file[ module_file ] = module
  return module
def Load(module_file, force=False):
    """Load and return the module contained in a file.
  Using force = True the module will be loaded regardless
  of the criteria in _ShouldLoad.
  This will return None if the module was not allowed to be loaded."""

    if not module_file:
        return None

    with _module_for_module_file_lock:
        if module_file in _module_for_module_file:
            return _module_for_module_file[module_file]

    is_global = module_file == _GlobalYcmExtraConfFileLocation()
    if not force and not _ShouldLoad(module_file, is_global):
        Disable(module_file)
        return None

    # This has to be here because a long time ago, the ycm_extra_conf.py files
    # used to import clang_helpers.py from the cpp folder. This is not needed
    # anymore, but there are a lot of old ycm_extra_conf.py files that we don't
    # want to break.
    sys.path.insert(0, _PathToCppCompleterFolder())

    # By default, the Python interpreter compiles source files into bytecode to
    # load them faster next time they are run. These *.pyc files are generated
    # along the source files prior to Python 3.2 or in a __pycache__ folder for
    # newer versions. We disable the generation of these files when loading
    # ycm_extra_conf.py files as users do not want them inside their projects.
    # The drawback is negligible since ycm_extra_conf.py files are generally small
    # files thus really fast to compile and only loaded once by editing session.
    old_dont_write_bytecode = sys.dont_write_bytecode
    sys.dont_write_bytecode = True
    try:
        module = LoadPythonSource(_RandomName(), module_file)
        module.is_global_ycm_extra_conf = is_global
    finally:
        sys.dont_write_bytecode = old_dont_write_bytecode

    del sys.path[0]

    with _module_for_module_file_lock:
        _module_for_module_file[module_file] = module
    return module
Esempio n. 4
0
  def _GetFiletypeCompleterForFiletype( self, filetype ):
    with self._filetype_completers_lock:
      try:
        return self._filetype_completers[ filetype ]
      except KeyError:
        pass

      module_path = PathToFiletypeCompleterPluginLoader( filetype )
      completer = None
      supported_filetypes = set( [ filetype ] )
      if os.path.exists( module_path ):
        module = LoadPythonSource( filetype, module_path )
        completer = module.GetCompleter( self._user_options )
        if completer:
          supported_filetypes.update( completer.SupportedFiletypes() )

      for supported_filetype in supported_filetypes:
        self._filetype_completers[ supported_filetype ] = completer
      return completer