How to use the peru.plugin.plugin_fetch function in peru

To help you get started, we’ve selected a few peru examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github buildinspace / peru / tests / test_plugins.py View on Github external
def test_plugin_fetch(context, type, fields, dest):
    handle = TestDisplayHandle()
    run_task(plugin.plugin_fetch(context, type, fields, dest, handle))
    return handle.getvalue()
github buildinspace / peru / peru / module.py View on Github external
key = compute_key({
            'type': self.type,
            'plugin_fields': self.plugin_fields,
            'peru_file': self.peru_file,
        })
        # Use a lock to prevent the same module from being double fetched. The
        # lock is taken on the cache key, not the module itself, so two
        # different modules with identical fields will take the same lock and
        # avoid double fetching.
        cache_key_lock = runtime.cache_key_locks[key]
        with (yield from cache_key_lock):
            if key in runtime.cache.keyval:
                return runtime.cache.keyval[key]
            with runtime.tmp_dir() as tmp_dir:
                yield from plugin_fetch(
                    runtime.get_plugin_context(), self.type,
                    self.plugin_fields, tmp_dir,
                    runtime.display.get_handle(self.name))
                tree = runtime.cache.import_tree(tmp_dir)
            runtime.cache.keyval[key] = tree
        return tree
github buildinspace / peru / peru / module.py View on Github external
'peru_file': self.peru_file,
        })
        # Use a lock to prevent the same module from being double fetched. The
        # lock is taken on the cache key, not the module itself, so two
        # different modules with identical fields will take the same lock and
        # avoid double fetching.
        cache_key_lock = runtime.cache_key_locks[key]
        async with cache_key_lock:
            # Skip reading the cache if --no-cache is set. This is the only
            # place in the code we check that flag. Deterministic operations
            # like tree merging still get read from cache, because there's no
            # reason to redo them.
            if key in runtime.cache.keyval and not runtime.no_cache:
                return runtime.cache.keyval[key]
            with runtime.tmp_dir() as tmp_dir:
                await plugin_fetch(runtime.get_plugin_context(), self.type,
                                   self.plugin_fields, tmp_dir,
                                   runtime.display.get_handle(self.name))
                tree = await runtime.cache.import_tree(tmp_dir)
            # Note that we still *write* to cache even when --no-cache is True.
            # That way we avoid confusing results on subsequent syncs.
            runtime.cache.keyval[key] = tree
        return tree