Ejemplo n.º 1
0
import aiopluggy, asyncio

hookspec = aiopluggy.HookspecMarker("myproject")
hookimpl = aiopluggy.HookimplMarker("myproject")


class MySpec(object):
    """A hook specification namespace.
    """
    @hookspec
    def myhook(self, arg1, arg2):
        """My special little hook that you can customize.
        """


class Plugin_1(object):
    """A hook implementation namespace.
    """
    @hookimpl.asyncio
    async def myhook(self, arg1, arg2):
        print("inside Plugin_1.myhook()")
        return arg1 + arg2


class Plugin_2(object):
    """A 2nd hook implementation namespace.
    """
    @hookimpl
    def myhook(self, arg1, arg2):
        print("inside Plugin_2.myhook()")
        return arg1 - arg2
Ejemplo n.º 2
0
import pkg_resources
import yaml
import logging
import typing as T
from uuid import uuid4

from aiohttp import helpers, web
import aiohttp
import aiopluggy

_hookimpl = aiopluggy.HookimplMarker('datacatalog')
_logger = logging.getLogger(__name__)

_BASE_URL = None
_AUTHORIZATION = None


@_hookimpl
def initialize_sync(app):
    # language=rst
    """ Initialize the plugin.

    -  validates the configuration loaded by `app`;
    -  initializes `_BASE_URL` and `_AUTHORIZATION`;
    -  registers a new endpoint ``/files`` in the HTTP service.

    """
    # validate configuration
    with pkg_resources.resource_stream(__name__, 'config_schema.yml') as s:
        schema = yaml.load(s)
    app.config.validate(schema)