Beispiel #1
0
 def load_kinds(self, context):
     # Load kinds from runtimepath
     loaded_paths = [x.path for x in self._kinds.values()]
     for path, name in find_rplugins(context, 'kind', loaded_paths):
         module = importlib.machinery.SourceFileLoader(
             'denite.kind.' + name, path).load_module()
         kind = module.Kind(self._vim)
         kind.path = path
         self._kinds[name] = kind
Beispiel #2
0
 def load_kinds(self, context):
     # Load kinds from runtimepath
     loaded_paths = [x.path for x in self._kinds.values()]
     for path, name in find_rplugins(context, 'kind', loaded_paths):
         module = importlib.machinery.SourceFileLoader(
             'denite.kind.' + name, path).load_module()
         kind = module.Kind(self._vim)
         kind.path = path
         self._kinds[name] = kind
Beispiel #3
0
def test_find_rplugins_kind(iglob):
    iglob.side_effect = _iglob_side_effect

    context = {'runtimepath': '/a,/b'}
    source = 'kind'
    prefix = os.path.normpath('rplugin/python3/denite/%s' % source)
    loaded_paths = [
        os.path.normpath(x % prefix) for x in (
            '/a/%s/loaded.py',
            '/a/%s/bar/loaded.py',
            '/a/%s/bar/hoge/loaded.py',
            '/b/%s/loaded.py',
            '/b/%s/bar/loaded.py',
            '/b/%s/bar/hoge/loaded.py',
        )
    ]

    it = util.find_rplugins(context, source, loaded_paths)
    iglob.assert_not_called()

    assert next(it) == ('/a/%s/base.py' % prefix, 'base')
    assert next(it) == ('/a/%s/foo.py' % prefix, 'foo')
    assert next(it) == ('/a/%s/bar/__init__.py' % prefix, 'bar')
    assert next(it) == ('/a/%s/bar/base.py' % prefix, 'bar.base')
    assert next(it) == ('/a/%s/bar/foo.py' % prefix, 'bar.foo')
    assert next(it) == ('/a/%s/bar/hoge/__init__.py' % prefix, 'bar.hoge')
    assert next(it) == ('/a/%s/bar/hoge/base.py' % prefix, 'bar.hoge.base')
    assert next(it) == ('/a/%s/bar/hoge/foo.py' % prefix, 'bar.hoge.foo')
    iglob.assert_called_once_with(
        os.path.normpath('/a/%s/**/*.py' % prefix),
        recursive=True,
    )
    iglob.reset_mock()

    assert next(it) == ('/b/%s/base.py' % prefix, 'base')
    assert next(it) == ('/b/%s/foo.py' % prefix, 'foo')
    assert next(it) == ('/b/%s/bar/__init__.py' % prefix, 'bar')
    assert next(it) == ('/b/%s/bar/base.py' % prefix, 'bar.base')
    assert next(it) == ('/b/%s/bar/foo.py' % prefix, 'bar.foo')
    assert next(it) == ('/b/%s/bar/hoge/__init__.py' % prefix, 'bar.hoge')
    assert next(it) == ('/b/%s/bar/hoge/base.py' % prefix, 'bar.hoge.base')
    assert next(it) == ('/b/%s/bar/hoge/foo.py' % prefix, 'bar.hoge.foo')
    iglob.assert_called_once_with(
        os.path.normpath('/b/%s/**/*.py' % prefix),
        recursive=True,
    )
    iglob.reset_mock()

    with pytest.raises(StopIteration):
        next(it)
    iglob.assert_not_called()
Beispiel #4
0
    def load_filters(self, context):
        # Load filters from runtimepath
        loaded_paths = [x.path for x in self._filters.values()]
        for path, name in find_rplugins(context, 'filter', loaded_paths):
            module = importlib.machinery.SourceFileLoader(
                'denite.filter.' + name, path).load_module()
            f = module.Filter(self._vim)
            f.path = path
            self._filters[name] = f

            if name in self._custom['alias_filter']:
                # Load alias
                for alias in self._custom['alias_filter'][name]:
                    self._filters[alias] = module.Filter(self._vim)
                    self._filters[alias].name = alias
                    self._filters[alias].path = path
Beispiel #5
0
    def load_filters(self, context):
        # Load filters from runtimepath
        loaded_paths = [x.path for x in self._filters.values()]
        for path, name in find_rplugins(context, 'filter', loaded_paths):
            module = importlib.machinery.SourceFileLoader(
                'denite.filter.' + name, path).load_module()
            f = module.Filter(self._vim)
            f.path = path
            self._filters[name] = f

            if name in self._custom['alias_filter']:
                # Load alias
                for alias in self._custom['alias_filter'][name]:
                    self._filters[alias] = module.Filter(self._vim)
                    self._filters[alias].name = alias
                    self._filters[alias].path = path
Beispiel #6
0
def test_find_rplugins_kind(walk):
    walk.side_effect = _walk_side_effect

    context = {'runtimepath': '/a,/b'}
    source = 'kind'
    prefix = str(Path('rplugin/python3/denite/%s' % source))
    loaded_paths = [
        str(Path(x % prefix)) for x in (
            '/a/%s/loaded.py',
            '/a/%s/bar/loaded.py',
            '/a/%s/bar/hoge/loaded.py',
            '/b/%s/loaded.py',
            '/b/%s/bar/loaded.py',
            '/b/%s/bar/hoge/loaded.py',
        )
    ]

    it = util.find_rplugins(context, source, loaded_paths)
    walk.assert_not_called()

    assert next(it) == ('/a/%s/foo.py' % prefix, 'foo')
    assert next(it) == ('/a/%s/base.py' % prefix, 'base')
    assert next(it) == ('/a/%s/bar/__init__.py' % prefix, 'bar')
    assert next(it) == ('/a/%s/bar/foo.py' % prefix, 'bar.foo')
    assert next(it) == ('/a/%s/bar/base.py' % prefix, 'bar.base')
    assert next(it) == ('/a/%s/bar/hoge/__init__.py' % prefix, 'bar.hoge')
    assert next(it) == ('/a/%s/bar/hoge/foo.py' % prefix, 'bar.hoge.foo')
    assert next(it) == ('/a/%s/bar/hoge/base.py' % prefix, 'bar.hoge.base')
    walk.assert_called_once_with(str(Path('/a/%s' % prefix)), )
    walk.reset_mock()

    assert next(it) == ('/b/%s/foo.py' % prefix, 'foo')
    assert next(it) == ('/b/%s/base.py' % prefix, 'base')
    assert next(it) == ('/b/%s/bar/__init__.py' % prefix, 'bar')
    assert next(it) == ('/b/%s/bar/foo.py' % prefix, 'bar.foo')
    assert next(it) == ('/b/%s/bar/base.py' % prefix, 'bar.base')
    assert next(it) == ('/b/%s/bar/hoge/__init__.py' % prefix, 'bar.hoge')
    assert next(it) == ('/b/%s/bar/hoge/foo.py' % prefix, 'bar.hoge.foo')
    assert next(it) == ('/b/%s/bar/hoge/base.py' % prefix, 'bar.hoge.base')
    walk.assert_called_once_with(str(Path('/b/%s' % prefix)), )
    walk.reset_mock()

    with pytest.raises(StopIteration):
        next(it)
    walk.assert_not_called()
Beispiel #7
0
def test_find_rplugins_kind(walk):
    walk.side_effect = _walk_side_effect

    context = { 'runtimepath': '/a,/b' }
    source = 'kind'
    prefix = os.path.normpath('rplugin/python3/denite/%s' % source)
    loaded_paths = [os.path.normpath(x % prefix) for x in (
        '/a/%s/loaded.py', '/a/%s/bar/loaded.py', '/a/%s/bar/hoge/loaded.py',
        '/b/%s/loaded.py', '/b/%s/bar/loaded.py', '/b/%s/bar/hoge/loaded.py',
    )]

    it = util.find_rplugins(context, source, loaded_paths)
    walk.assert_not_called()

    assert next(it) == ('/a/%s/foo.py' % prefix, 'foo')
    assert next(it) == ('/a/%s/base.py' % prefix, 'base')
    assert next(it) == ('/a/%s/bar/__init__.py' % prefix, 'bar')
    assert next(it) == ('/a/%s/bar/foo.py' % prefix, 'bar.foo')
    assert next(it) == ('/a/%s/bar/base.py' % prefix, 'bar.base')
    assert next(it) == ('/a/%s/bar/hoge/__init__.py' % prefix, 'bar.hoge')
    assert next(it) == ('/a/%s/bar/hoge/foo.py' % prefix, 'bar.hoge.foo')
    assert next(it) == ('/a/%s/bar/hoge/base.py' % prefix, 'bar.hoge.base')
    walk.assert_called_once_with(
        os.path.normpath('/a/%s' % prefix),
    )
    walk.reset_mock()

    assert next(it) == ('/b/%s/foo.py' % prefix, 'foo')
    assert next(it) == ('/b/%s/base.py' % prefix, 'base')
    assert next(it) == ('/b/%s/bar/__init__.py' % prefix, 'bar')
    assert next(it) == ('/b/%s/bar/foo.py' % prefix, 'bar.foo')
    assert next(it) == ('/b/%s/bar/base.py' % prefix, 'bar.base')
    assert next(it) == ('/b/%s/bar/hoge/__init__.py' % prefix, 'bar.hoge')
    assert next(it) == ('/b/%s/bar/hoge/foo.py' % prefix, 'bar.hoge.foo')
    assert next(it) == ('/b/%s/bar/hoge/base.py' % prefix, 'bar.hoge.base')
    walk.assert_called_once_with(
        os.path.normpath('/b/%s' % prefix),
    )
    walk.reset_mock()

    with pytest.raises(StopIteration):
        next(it)
    walk.assert_not_called()
Beispiel #8
0
    def load_sources(self, context):
        # Load sources from runtimepath
        loaded_paths = [x.path for x in self._sources.values()]
        for path, name in find_rplugins(context, 'source', loaded_paths):
            module = importlib.machinery.SourceFileLoader(
                'denite.source.' + name, path).load_module()
            source = module.Source(self._vim)
            self._sources[source.name] = source
            source.path = path
            syntax_name = 'deniteSource_' + source.name.replace('/', '_')
            if not source.syntax_name:
                source.syntax_name = syntax_name

            if source.name in self._custom['alias_source']:
                # Load alias
                for alias in self._custom['alias_source'][source.name]:
                    self._sources[alias] = module.Source(self._vim)
                    self._sources[alias].name = alias
                    self._sources[alias].path = path
                    self._sources[alias].syntax_name = syntax_name
Beispiel #9
0
    def load_sources(self, context):
        # Load sources from runtimepath
        loaded_paths = [x.path for x in self._sources.values()]
        for path, name in find_rplugins(context, 'source', loaded_paths):
            module = importlib.machinery.SourceFileLoader(
                'denite.source.' + name, path).load_module()
            source = module.Source(self._vim)
            self._sources[source.name] = source
            source.path = path
            syntax_name = 'deniteSource_' + source.name.replace('/', '_')
            if not source.syntax_name:
                source.syntax_name = syntax_name

            if source.name in self._custom['alias_source']:
                # Load alias
                for alias in self._custom['alias_source'][source.name]:
                    self._sources[alias] = module.Source(self._vim)
                    self._sources[alias].name = alias
                    self._sources[alias].path = path
                    self._sources[alias].syntax_name = syntax_name