Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify purpose of specname #477

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,15 @@ To override the default behavior, a *hookimpl* may also be matched to a
the ``specname`` option. Continuing the example above, the *hookimpl* function
does not need to be named ``setup_project``, but if the argument
``specname="setup_project"`` is provided to the ``hookimpl`` decorator, it will
be matched and checked against the ``setup_project`` hookspec:
be matched and checked against the ``setup_project`` hookspec.

This is useful for registering multiple implementations of the same plugin in
the same Python file, for example:

.. code-block:: python

@hookimpl(specname="setup_project")
def any_plugin_function(config, args):
def setup_1(config, args):
"""This hook is used to process the initial config
and possibly input arguments.
"""
Expand All @@ -305,6 +308,14 @@ be matched and checked against the ``setup_project`` hookspec:

return config


@hookimpl(specname="setup_project")
def setup_2(config, args):
"""Perform additional setup steps"""
# ...
return config


.. _callorder:

Call time order
Expand Down
Loading