Esempio n. 1
0
def test_with_callbacks_immediately_executed(pm: PluginManager) -> None:
    class Hooks:
        @hookspec(historic=True)
        def he_method1(self, arg):
            pass

    pm.add_hookspecs(Hooks)

    class Plugin1:
        @hookimpl
        def he_method1(self, arg):
            return arg * 10

    class Plugin2:
        @hookimpl
        def he_method1(self, arg):
            return arg * 20

    class Plugin3:
        @hookimpl
        def he_method1(self, arg):
            return arg * 30

    out = []
    pm.register(Plugin1())
    pm.register(Plugin2())

    he_method1 = pm.hook.he_method1
    he_method1.call_historic(lambda res: out.append(res), dict(arg=1))
    assert out == [20, 10]
    pm.register(Plugin3())
    assert out == [20, 10, 30]
Esempio n. 2
0
def test_warning_on_call_vs_hookspec_arg_mismatch():
    """Verify that is a hook is called with less arguments then defined in the
    spec that a warning is emitted.
    """
    class Spec:
        @hookspec
        def myhook(self, arg1, arg2):
            pass

    class Plugin:
        @hookimpl
        def myhook(self, arg1):
            pass

    pm = PluginManager(hookspec.project_name)
    pm.register(Plugin())
    pm.add_hookspecs(Spec())

    with warnings.catch_warnings(record=True) as warns:
        warnings.simplefilter('always')

        # calling should trigger a warning
        pm.hook.myhook(arg1=1)

        assert len(warns) == 1
        warning = warns[-1]
        assert issubclass(warning.category, Warning)
        assert "Argument(s) ('arg2',)" in str(warning.message)
Esempio n. 3
0
def test_register_historic(pm: PluginManager) -> None:
    class Hooks:
        @hookspec(historic=True)
        def he_method1(self, arg):
            pass

    pm.add_hookspecs(Hooks)

    pm.hook.he_method1.call_historic(kwargs=dict(arg=1))
    out = []

    class Plugin:
        @hookimpl
        def he_method1(self, arg):
            out.append(arg)

    pm.register(Plugin())
    assert out == [1]

    class Plugin2:
        @hookimpl
        def he_method1(self, arg):
            out.append(arg * 10)

    pm.register(Plugin2())
    assert out == [1, 10]
    pm.hook.he_method1.call_historic(kwargs=dict(arg=12))
    assert out == [1, 10, 120, 12]
Esempio n. 4
0
def test_not_all_arguments_are_provided_issues_a_warning(
        pm: PluginManager) -> None:
    """Calling a hook without providing all arguments specified in
    the hook spec issues a warning."""
    class Spec:
        @hookspec
        def hello(self, arg1, arg2):
            pass

        @hookspec(historic=True)
        def herstory(self, arg1, arg2):
            pass

    pm.add_hookspecs(Spec)

    with pytest.warns(UserWarning,
                      match=r"'arg1', 'arg2'.*cannot be found.*$"):
        pm.hook.hello()
    with pytest.warns(UserWarning, match=r"'arg2'.*cannot be found.*$"):
        pm.hook.hello(arg1=1)
    with pytest.warns(UserWarning, match=r"'arg1'.*cannot be found.*$"):
        pm.hook.hello(arg2=2)

    with pytest.warns(UserWarning,
                      match=r"'arg1', 'arg2'.*cannot be found.*$"):
        pm.hook.hello.call_extra([], kwargs=dict())

    with pytest.warns(UserWarning,
                      match=r"'arg1', 'arg2'.*cannot be found.*$"):
        pm.hook.herstory.call_historic(kwargs=dict())
Esempio n. 5
0
def test_firstresult_force_result(pm: PluginManager) -> None:
    """Verify forcing a result in a wrapper."""
    class Api:
        @hookspec(firstresult=True)
        def hello(self, arg):
            "api hook 1"

    pm.add_hookspecs(Api)

    class Plugin1:
        @hookimpl
        def hello(self, arg):
            return arg + 1

    class Plugin2:
        @hookimpl(hookwrapper=True)
        def hello(self, arg):
            assert arg == 3
            outcome = yield
            assert outcome.get_result() == 4
            outcome.force_result(0)

    class Plugin3:
        @hookimpl
        def hello(self, arg):
            return None

    pm.register(Plugin1())
    pm.register(Plugin2())  # wrapper
    pm.register(Plugin3())  # ignored since returns None
    res = pm.hook.hello(arg=3)
    assert res == 0  # this result is forced and not a list
Esempio n. 6
0
def test_hookrelay_registration_by_specname_raises(pm: PluginManager) -> None:
    """Verify using specname still raises the types of errors during registration as it
    would have without using specname."""
    class Api:
        @hookspec
        def hello(self, arg: object) -> None:
            "api hook 1"

    pm.add_hookspecs(Api)

    # make sure a bad signature still raises an error when using specname
    class Plugin:
        @hookimpl(specname="hello")
        def foo(self, arg: int, too, many, args) -> int:
            return arg + 1

    with pytest.raises(PluginValidationError):
        pm.register(Plugin())

    # make sure check_pending still fails if specname doesn't have a
    # corresponding spec.  EVEN if the function name matches one.
    class Plugin2:
        @hookimpl(specname="bar")
        def hello(self, arg: int) -> int:
            return arg + 1

    pm.register(Plugin2())
    with pytest.raises(PluginValidationError):
        pm.check_pending()
Esempio n. 7
0
def test_historic_with_subset_hook_caller(pm: PluginManager) -> None:
    class Hooks:
        @hookspec(historic=True)
        def he_method1(self, arg):
            ...

    pm.add_hookspecs(Hooks)

    out = []

    class Plugin:
        @hookimpl
        def he_method1(self, arg):
            out.append(arg)

    plugin = Plugin()
    pm.register(plugin)

    class Plugin2:
        @hookimpl
        def he_method1(self, arg):
            out.append(arg * 10)

    shc = pm.subset_hook_caller("he_method1", remove_plugins=[plugin])
    shc.call_historic(kwargs=dict(arg=1))

    pm.register(Plugin2())
    assert out == [10]

    pm.register(Plugin())
    assert out == [10, 1]
def get_pluggin_manager(load_entrypoints=True):
    pm = PluginManager('banana', implprefix='banana_')
    pm.add_hookspecs(hookspecs)
    if load_entrypoints:
        pm.load_setuptools_entrypoints('banana')
    pm.check_pending()
    return pm
Esempio n. 9
0
def test_warning_on_call_vs_hookspec_arg_mismatch():
    """Verify that is a hook is called with less arguments then defined in the
    spec that a warning is emitted.
    """
    class Spec:
        @hookspec
        def myhook(self, arg1, arg2):
            pass

    class Plugin:
        @hookimpl
        def myhook(self, arg1):
            pass

    pm = PluginManager(hookspec.project_name)
    pm.register(Plugin())
    pm.add_hookspecs(Spec())

    with warnings.catch_warnings(record=True) as warns:
        warnings.simplefilter('always')

        # calling should trigger a warning
        pm.hook.myhook(arg1=1)

        assert len(warns) == 1
        warning = warns[-1]
        assert issubclass(warning.category, Warning)
        assert "Argument(s) ('arg2',)" in str(warning.message)
Esempio n. 10
0
def get_pluginmanager(load_entry_points=True):
    pm = PluginManager("devpipasswdreset", implprefix="devpipasswdreset_")
    pm.add_hookspecs(hookspecs)
    if load_entry_points:
        pm.load_setuptools_entrypoints("devpi_passwd_reset")
    pm.check_pending()
    return pm
Esempio n. 11
0
File: main.py Progetto: vartec/devpi
def get_pluginmanager(load_entry_points=True):
    pm = PluginManager("devpiclient", implprefix="devpiclient_")
    pm.add_hookspecs(hookspecs)
    if load_entry_points:
        pm.load_setuptools_entrypoints("devpi_client")
    pm.check_pending()
    return pm
Esempio n. 12
0
def get_pluginmanager():
    pm = PluginManager("devpiserver", implprefix="devpiserver_")
    pm.add_hookspecs(hookspecs)
    # XXX load internal plugins here
    pm.load_setuptools_entrypoints("devpi_server")
    pm.check_pending()
    return pm
Esempio n. 13
0
def test_get_hookimpls(pm: PluginManager) -> None:
    class Hooks:
        @hookspec
        def he_method1(self, arg):
            pass

    pm.add_hookspecs(Hooks)
    assert pm.hook.he_method1.get_hookimpls() == []

    class Plugin1:
        @hookimpl
        def he_method1(self, arg):
            pass

    class Plugin2:
        @hookimpl
        def he_method1(self, arg):
            pass

    class PluginNo:
        pass

    plugin1, plugin2, plugin3 = Plugin1(), Plugin2(), PluginNo()
    pm.register(plugin1)
    pm.register(plugin2)
    pm.register(plugin3)

    hookimpls = pm.hook.he_method1.get_hookimpls()
    hook_plugins = [item.plugin for item in hookimpls]
    assert hook_plugins == [plugin1, plugin2]
Esempio n. 14
0
class WebView(object):
    def __init__(self, driver, timeout, pm=None):
        self.driver = driver
        self.driver_adapter = IDriver(driver)
        self.timeout = timeout
        self.pm = pm
        if self.pm is None:
            self.pm = PluginManager("pypom", implprefix="pypom_")
            self.pm.add_hookspecs(hooks)
            self.pm.load_setuptools_entrypoints("pypom.plugin")
            self.pm.check_pending()
        self.wait = self.driver_adapter.wait_factory(self.timeout)

    @property
    def selenium(self):
        """Backwards compatibility attribute"""
        warn("use driver instead", DeprecationWarning, stacklevel=2)
        return self.driver

    def find_element(self, strategy, locator):
        return self.driver_adapter.find_element(strategy, locator)

    def find_elements(self, strategy, locator):
        """Finds elements on the page.

        :param strategy: Location strategy to use. See :py:class:`~selenium.webdriver.common.by.By` or :py:attr:`~pypom.splinter_driver.ALLOWED_STRATEGIES`.
        :param locator: Location of target elements.
        :type strategy: str
        :type locator: str
        :return: List of :py:class:`~selenium.webdriver.remote.webelement.WebElement` or :py:class:`~splinter.element_list.ElementList`
        :rtype: list

        """
        return self.driver_adapter.find_elements(strategy, locator)

    def is_element_present(self, strategy, locator):
        """Checks whether an element is present.

        :param strategy: Location strategy to use. See :py:class:`~selenium.webdriver.common.by.By` or :py:attr:`~pypom.splinter_driver.ALLOWED_STRATEGIES`.
        :param locator: Location of target element.
        :type strategy: str
        :type locator: str
        :return: ``True`` if element is present, else ``False``.
        :rtype: bool

        """
        return self.driver_adapter.is_element_present(strategy, locator)

    def is_element_displayed(self, strategy, locator):
        """Checks whether an element is displayed.

        :param strategy: Location strategy to use. See :py:class:`~selenium.webdriver.common.by.By` or :py:attr:`~pypom.splinter_driver.ALLOWED_STRATEGIES`.
        :param locator: Location of target element.
        :type strategy: str
        :type locator: str
        :return: ``True`` if element is displayed, else ``False``.
        :rtype: bool

        """
        return self.driver_adapter.is_element_displayed(strategy, locator)
Esempio n. 15
0
def test_opt_in_args(pm: PluginManager) -> None:
    """Verify that two hookimpls with mutex args can serve
    under the same spec.
    """
    class Api:
        @hookspec
        def hello(self, arg1, arg2, common_arg):
            "api hook 1"

    class Plugin1:
        @hookimpl
        def hello(self, arg1, common_arg):
            return arg1 + common_arg

    class Plugin2:
        @hookimpl
        def hello(self, arg2, common_arg):
            return arg2 + common_arg

    pm.add_hookspecs(Api)
    pm.register(Plugin1())
    pm.register(Plugin2())

    results = pm.hook.hello(arg1=1, arg2=2, common_arg=0)
    assert results == [2, 1]
Esempio n. 16
0
def test_hookrelay_registry(pm: PluginManager) -> None:
    """Verify hook caller instances are registered by name onto the relay
    and can be likewise unregistered."""
    class Api:
        @hookspec
        def hello(self, arg: object) -> None:
            "api hook 1"

    pm.add_hookspecs(Api)
    hook = pm.hook
    assert hasattr(hook, "hello")
    assert repr(hook.hello).find("hello") != -1

    class Plugin:
        @hookimpl
        def hello(self, arg):
            return arg + 1

    plugin = Plugin()
    pm.register(plugin)
    out = hook.hello(arg=3)
    assert out == [4]
    assert not hasattr(hook, "world")
    pm.unregister(plugin)
    assert hook.hello(arg=3) == []
Esempio n. 17
0
def hc(pm: PluginManager) -> _HookCaller:
    class Hooks:
        @hookspec
        def he_method1(self, arg: object) -> None:
            pass

    pm.add_hookspecs(Hooks)
    return pm.hook.he_method1
Esempio n. 18
0
def get_pluginmanager(load_entrypoints=True):
    pm = PluginManager("devpiserver", implprefix="devpiserver_")
    pm.add_hookspecs(hookspecs)
    # XXX load internal plugins here
    if load_entrypoints:
        pm.load_setuptools_entrypoints("devpi_server")
    pm.check_pending()
    return pm
Esempio n. 19
0
def _create_hook_manager() -> PluginManager:
    """Create a new PluginManager instance and register Kedro's hook specs."""
    manager = PluginManager(HOOK_NAMESPACE)
    manager.add_hookspecs(NodeSpecs)
    manager.add_hookspecs(PipelineSpecs)
    manager.add_hookspecs(DataCatalogSpecs)
    manager.add_hookspecs(RegistrationSpecs)
    manager.add_hookspecs(DatasetSpecs)
    return manager
Esempio n. 20
0
def get_plugin_manager() -> PluginManager:
    """
    Get a plugin manager that the entry points and the default implementation are already loaded.
    """
    manager = PluginManager("preacher")
    manager.add_hookspecs(hookspec)
    manager.load_setuptools_entrypoints("preacher")

    return manager
Esempio n. 21
0
def get_pluginmanager(config, load_entry_points=True):
    pm = PluginManager("devpiweb")
    # support old plugins, but emit deprecation warnings
    pm._implprefix = "devpiweb_"
    pm.add_hookspecs(hookspecs)
    if load_entry_points:
        pm.load_setuptools_entrypoints("devpi_web")
    pm.check_pending()
    return pm
Esempio n. 22
0
def get_pluginmanager(load_entrypoints=True):
    pm = PluginManager("devpiserver")
    # support old plugins, but emit deprecation warnings
    pm._implprefix = "devpiserver_"
    pm.add_hookspecs(hookspecs)
    # XXX load internal plugins here
    if load_entrypoints:
        pm.load_setuptools_entrypoints("devpi_server")
    pm.check_pending()
    return pm
Esempio n. 23
0
def he_pm(request, pm: PluginManager) -> PluginManager:
    hookspec = HookspecMarker("example")

    class Hooks:
        @hookspec
        def he_method1(self, arg: int) -> int:
            return arg + 1

    pm.add_hookspecs(request.param(Hooks))
    return pm
Esempio n. 24
0
    def _load_spec(self, event_dispatcher: pluggy.PluginManager) -> None:
        """
        Load all hookspec modules
        """

        # INFO - G.M - 2019-11-28 - get all submodules recursively,
        # find those with with hookspec suffix, import them and add them
        # to valid hookspec
        for hookspec_module_path in self.get_all_hookspec_module_path():
            module = importlib.import_module(hookspec_module_path)
            event_dispatcher.add_hookspecs(module)
Esempio n. 25
0
def test_only_kwargs(pm: PluginManager) -> None:
    class Api:
        @hookspec
        def hello(self, arg):
            "api hook 1"

    pm.add_hookspecs(Api)
    with pytest.raises(TypeError) as exc:
        pm.hook.hello(3)  # type: ignore[call-arg]

    message = "__call__() takes 1 positional argument but 2 were given"
    assert message in str(exc.value)
Esempio n. 26
0
def test_firstresult_no_plugin(pm: PluginManager) -> None:
    """If no implementations/plugins have been registered for a firstresult
    hook the multi-call loop should return a None value.
    """
    class Api:
        @hookspec(firstresult=True)
        def hello(self, arg):
            "api hook 1"

    pm.add_hookspecs(Api)
    res = pm.hook.hello(arg=3)
    assert res is None
Esempio n. 27
0
class SimplePluginManager(object):
    """
    A PluginManager class for simple, non-scanning related plugins.
    """

    def __init__(self, project_name, entrypoint, plugin_base_class):
        """
        Initialize this plugin manager for the fully qualified Python module
        name `module_qname` with plugins loaded from the setuptools `entrypoint`
        that must subclass `plugin_base_class`.
        """
        self.manager = PluggyPluginManager(project_name=project_name)
        self.entrypoint = entrypoint
        self.plugin_base_class = plugin_base_class
        self.manager.add_hookspecs(sys.modules[project_name])

        # set to True once this manager is initialized by running its setup()
        self.initialized = False

        # mapping of {plugin.name: plugin_class} for all the loaded plugins of
        # this manager
        self.plugin_classes = OrderedDict()

    def setup(self):
        """
        Load and validate available plugins for this PluginManager from its
        assigned `entrypoint`. Raise an Exception if a plugin is not valid such
        that when it does not subcclass the manager `plugin_base_class`.
        Must be called once to initialize the plugins if this manager.

        Return a list of all plugin classes for this manager.
        """
        if self.initialized:
            return self.plugin_classes.values()

        entrypoint = self.entrypoint
        self.manager.load_setuptools_entrypoints(entrypoint)

        plugin_classes = []
        for name, plugin_class in self.manager.list_name_plugin():
            if not issubclass(plugin_class, self.plugin_base_class):
                plugin_base_class = self.plugin_base_class
                raise Exception(
                    'Invalid plugin: %(name)r: %(plugin_class)r '
                    'must extend %(plugin_base_class)r.' % locals())

            plugin_class.name = name
            plugin_classes.append(plugin_class)

        self.plugin_classes = OrderedDict([(cls.name, cls) for cls in plugin_classes])
        self.initialized = True
        return self.plugin_classes.values()
Esempio n. 28
0
def test_call_extra(pm: PluginManager) -> None:
    class Hooks:
        @hookspec
        def he_method1(self, arg):
            pass

    pm.add_hookspecs(Hooks)

    def he_method1(arg):
        return arg * 10

    out = pm.hook.he_method1.call_extra([he_method1], dict(arg=1))
    assert out == [10]
Esempio n. 29
0
def test_subset_hook_caller(pm: PluginManager) -> None:
    class Hooks:
        @hookspec
        def he_method1(self, arg):
            pass

    pm.add_hookspecs(Hooks)

    out = []

    class Plugin1:
        @hookimpl
        def he_method1(self, arg):
            out.append(arg)

    class Plugin2:
        @hookimpl
        def he_method1(self, arg):
            out.append(arg * 10)

    class PluginNo:
        pass

    plugin1, plugin2, plugin3 = Plugin1(), Plugin2(), PluginNo()
    pm.register(plugin1)
    pm.register(plugin2)
    pm.register(plugin3)
    pm.hook.he_method1(arg=1)
    assert out == [10, 1]
    out[:] = []

    hc = pm.subset_hook_caller("he_method1", [plugin1])
    hc(arg=2)
    assert out == [20]
    out[:] = []

    hc = pm.subset_hook_caller("he_method1", [plugin2])
    hc(arg=2)
    assert out == [2]
    out[:] = []

    pm.unregister(plugin1)
    hc(arg=2)
    assert out == []
    out[:] = []

    pm.hook.he_method1(arg=1)
    assert out == [10]

    assert repr(hc) == "<_SubsetHookCaller 'he_method1'>"
Esempio n. 30
0
def test_get_hookcallers(pm: PluginManager) -> None:
    class Hooks:
        @hookspec
        def he_method1(self):
            ...

        @hookspec
        def he_method2(self):
            ...

    pm.add_hookspecs(Hooks)

    class Plugin1:
        @hookimpl
        def he_method1(self):
            ...

        @hookimpl
        def he_method2(self):
            ...

    class Plugin2:
        @hookimpl
        def he_method1(self):
            ...

    class Plugin3:
        @hookimpl
        def he_method2(self):
            ...

    plugin1 = Plugin1()
    pm.register(plugin1)
    plugin2 = Plugin2()
    pm.register(plugin2)
    plugin3 = Plugin3()
    pm.register(plugin3)

    hookcallers1 = pm.get_hookcallers(plugin1)
    assert hookcallers1 is not None
    assert len(hookcallers1) == 2
    hookcallers2 = pm.get_hookcallers(plugin2)
    assert hookcallers2 is not None
    assert len(hookcallers2) == 1
    hookcallers3 = pm.get_hookcallers(plugin3)
    assert hookcallers3 is not None
    assert len(hookcallers3) == 1
    assert hookcallers1 == hookcallers2 + hookcallers3

    assert pm.get_hookcallers(object()) is None
Esempio n. 31
0
def get_pluginmanager(config, load_entry_points=True):
    # lookup cached value
    pm = getattr(config, 'devpiweb_pluginmanager', None)
    if pm is not None:
        return pm
    pm = PluginManager("devpiweb")
    # support old plugins, but emit deprecation warnings
    pm._implprefix = "devpiweb_"
    pm.add_hookspecs(hookspecs)
    if load_entry_points:
        pm.load_setuptools_entrypoints("devpi_web")
    pm.check_pending()
    # cache the expensive setup
    config.devpiweb_pluginmanager = pm
    return pm
Esempio n. 32
0
def create_app():
    pm = PluginManager('fp')
    pm.add_hookspecs(hooks)
    pm.register(impl)
    pm.load_setuptools_entrypoints('flaskplug')

    app = Flask(__name__)
    for bp in pm.hook.fp_load_blueprints():
        if isinstance(bp, dict):
            app.register_blueprint(**bp)
        elif isinstance(bp, tuple):
            app.register_blueprint(bp[0], **bp[1])
        else:
            app.register_blueprint(bp)

    return app
Esempio n. 33
0
def test_argmismatch(pm: PluginManager) -> None:
    class Api:
        @hookspec
        def hello(self, arg):
            "api hook 1"

    pm.add_hookspecs(Api)

    class Plugin:
        @hookimpl
        def hello(self, argwrong):
            pass

    with pytest.raises(PluginValidationError) as exc:
        pm.register(Plugin())

    assert "argwrong" in str(exc.value)
Esempio n. 34
0
def test_call_with_too_few_args(pm: PluginManager) -> None:
    class Hooks:
        @hookspec
        def he_method1(self, arg):
            pass

    pm.add_hookspecs(Hooks)

    class Plugin1:
        @hookimpl
        def he_method1(self, arg):
            0 / 0

    pm.register(Plugin1())
    with pytest.raises(HookCallError):
        with pytest.warns(UserWarning):
            pm.hook.he_method1()
Esempio n. 35
0
    def test_prefix_hookimpl(self):
        pm = PluginManager(hookspec.project_name, "hello_")

        class HookSpec:
            @hookspec
            def hello_myhook(self, arg1):
                """ add to arg1 """

        pm.add_hookspecs(HookSpec)

        class Plugin:
            def hello_myhook(self, arg1):
                return arg1 + 1

        pm.register(Plugin())
        pm.register(Plugin())
        results = pm.hook.hello_myhook(arg1=17)
        assert results == [18, 18]
Esempio n. 36
0
def test_prefix_hookimpl(include_hookspec):
    with pytest.deprecated_call():
        pm = PluginManager(hookspec.project_name, "hello_")

    if include_hookspec:

        class HookSpec(object):
            @hookspec
            def hello_myhook(self, arg1):
                """ add to arg1 """

        pm.add_hookspecs(HookSpec)

    class Plugin(object):
        def hello_myhook(self, arg1):
            return arg1 + 1

    with pytest.deprecated_call():
        pm.register(Plugin())
        pm.register(Plugin())
    results = pm.hook.hello_myhook(arg1=17)
    assert results == [18, 18]
Esempio n. 37
0
def test_warn_when_deprecated_specified(recwarn):
    warning = DeprecationWarning("foo is deprecated")

    class Spec(object):
        @hookspec(warn_on_impl=warning)
        def foo(self):
            pass

    class Plugin(object):
        @hookimpl
        def foo(self):
            pass

    pm = PluginManager(hookspec.project_name)
    pm.add_hookspecs(Spec)

    with pytest.warns(DeprecationWarning) as records:
        pm.register(Plugin())
    (record,) = records
    assert record.message is warning
    assert record.filename == Plugin.foo.__code__.co_filename
    assert record.lineno == Plugin.foo.__code__.co_firstlineno
Esempio n. 38
0
from pluggy import PluginManager
from . import hookspec, PROJECT_NAME


# TODO: move to main?

manager = PluginManager(PROJECT_NAME)
manager.add_hookspecs(hookspec)
manager.load_setuptools_entrypoints('gumby.plugin')
Esempio n. 39
0
post_scan_impl = HookimplMarker('post_scan')


@post_scan_spec
def post_scan_handler(active_scans, results):
    """
    Process the scanned files and yield the modified results.
    Parameters:
     - `active_scans`: a list of scanners names requested in the current run.
     - `results`: an iterable of scan results for each file or directory.
    """
    pass


post_scan_plugins = PluginManager('post_scan')
post_scan_plugins.add_hookspecs(sys.modules[__name__])


def initialize():
    """
    NOTE: this defines the entry points for use in setup.py
    """
    post_scan_plugins.load_setuptools_entrypoints('scancode_post_scan')


def get_post_scan_plugins():
    """
    Return an ordered mapping of
        "command line option name" --> "plugin callable"
    for all the post_scan plugins. The mapping is sorted by option name.
    This is the main API for other code to access post_scan plugins.
Esempio n. 40
0
    Parameters:
     - `file_count`: the number of files and directories scanned.
     - `version`: ScanCode version
     - `notice`: ScanCode notice
     - `scanned_files`: an iterable of scan results for each file
     - `options`: a mapping of key by command line option to a flag True
        if this option was enabled.
     - `input`: the original input path scanned.
     - `output_file`: an opened, file-like object to write the output to.
     - `_echo`: a funtion to echo strings to stderr. This will be removedd in the future.
    """
    pass


output_plugins = PluginManager('scan_output_writer')
output_plugins.add_hookspecs(sys.modules[__name__])


def initialize():
    """
    NOTE: this defines the entry points for use in setup.py
    """
    output_plugins.load_setuptools_entrypoints('scancode_output_writers')


def get_format_plugins():
    """
    Return an ordered mapping of format name --> plugin callable for all
    the output plugins. The mapping is ordered by sorted key.
    This is the main API for other code to access format plugins.
    """