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

Renamed Plugins to Hooks #919

Merged
merged 1 commit into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ This section provides an introduction to extension capabilities of Conan:
:maxdepth: 2

extending/python_requires
extending/plugins
extending/hooks
58 changes: 29 additions & 29 deletions extending/plugins.rst → extending/hooks.rst
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
.. _plugins:
.. _hooks:

Plugins [EXPERIMENTAL]
Hooks [EXPERIMENTAL]
======================

.. warning::

This is an **experimental** feature subject to breaking changes in future releases.

The Conan plugins is a feature intended to extend the Conan functionalities and let users customize the client behavior at determined
The Conan hooks is a feature intended to extend the Conan functionalities and let users customize the client behavior at determined
points.

Plugin structure
Hook structure
----------------

Plugins are Python files containing **pre** and **post** functions that will be executed prior and after a determined task performed by the
Hooks are Python files containing **pre** and **post** functions that will be executed prior and after a determined task performed by the
Conan client. Those tasks could be Conan commands, recipe interactions such as exporting or packaging or interactions with the remotes.

Here you can see an example of a simple plugin:
Here you can see an example of a simple hook:

.. code-block:: python
:caption: *example_plugin.py*
:caption: *example_hook.py*

from conans import tools

Expand Down Expand Up @@ -53,15 +53,15 @@ Here you can see an example of a simple plugin:
output.error("%s Source files does not come from and immutable place. Checkout to a "
"commit/tag or download a compressed source file for %s" % (test, str(reference)))

This plugin is only checking the recipe content prior to the recipe being exported and prior to downloading the sources. Basically the
This hook is only checking the recipe content prior to the recipe being exported and prior to downloading the sources. Basically the
``pre_export()`` function is checking the attributes of the ``conanfile`` object to see if there is an URL, a license and a description and
warning the user with a message through the ``output``. This is done **before** the recipe is exported to the local cache.

The ``pre_source()`` function checks if the recipe contains a ``source()`` method (this time it is using the conanfile content instead of
the ``conanfile`` object) and in that case it checks if the download of the sources are likely coming from immutable places (a compressed
file or a determined :command:`git checkout`). This is done **before** the **source()** method of the recipe is called.

Any kind of Python scripting can be executed. You can create global functions and call them from different plugin functions, import from a
Any kind of Python scripting can be executed. You can create global functions and call them from different hook functions, import from a
relative module and warn, error or even raise to abort the Conan client execution.

As you can see each function receives some parameters but not all of them are available for all functions as this may change depending on
Expand All @@ -70,16 +70,16 @@ the context of the commands being executed such as the recipe being in the local
.. important::

A detailed description of the functions allowed and its parameters as well as their execution can be found in it dedicated reference
section: :ref:`plugins_reference`.
section: :ref:`hooks_reference`.

Other useful task where a plugin may come handy are the upload and download actions. There are **pre** and **post** functions for every
Other useful task where a hook may come handy are the upload and download actions. There are **pre** and **post** functions for every
download/upload as a whole and for fine download tasks such as recipe and package downloads/uploads.

For example they can be used to sign the packages (including a file with the signature) when the package is created and and checking that
signature everytime they are downloaded.

.. code-block:: python
:caption: *signing_plugin.py*
:caption: *signing_hook.py*

import os
from conans import tools
Expand All @@ -101,11 +101,11 @@ signature everytime they are downloaded.
Importing from a module
-----------------------

The plugin interface should always be placed inside a Python file with the name of the plugin and stored in the *plugins* folder. However,
The hook interface should always be placed inside a Python file with the name of the hook and stored in the *hooks* folder. However,
you can use functionalities from imported modules if you have them installed in your system or if they are installed with Conan:

.. code-block:: python
:caption: example_plugin.py
:caption: example_hook.py

import requests
from conans import tools
Expand All @@ -119,11 +119,11 @@ You can also import functionalities from a relative module:

.. code-block:: text

plugins
hooks
├── custom_module
│   ├── custom.py
│   └── __init__.py
└── my_plugin.py
└── my_hook.py

Inside the *custom.py* from my *custom_module* there is:

Expand All @@ -132,7 +132,7 @@ Inside the *custom.py* from my *custom_module* there is:
def my_printer(output):
output.info("my_printer(): CUSTOM MODULE")

And it can be used in plugin importing the module:
And it can be used in hook importing the module:

.. code-block:: python

Expand All @@ -145,42 +145,42 @@ And it can be used in plugin importing the module:
Storage, activation and sharing
-------------------------------

Plugins are Python files stored under *~/.conan/plugins* folder and **their file name should be the same used for activation** (without the
Hooks are Python files stored under *~/.conan/hooks* folder and **their file name should be the same used for activation** (without the
*.py* extension).

The activation of the plugins is done in the *conan.conf* section named ``[plugins]``. The plugin names listed under this section will be
The activation of the hooks is done in the *conan.conf* section named ``[hooks]``. The hook names listed under this section will be
considered activated.

.. code-block:: text
:caption: *conan.conf*

...
[plugins]
[hooks]
attribute_checker
conan-center

They can be easily activated and deactivated from the command line using the :command:`conan config set` command:

.. code-block:: bash

$ conan config set plugins.attribute_checker # Activates 'attribute_checker'
$ conan config set hooks.attribute_checker # Activates 'attribute_checker'

$ conan config rm plugins.attribute_checker # Deactivates 'attribute_checker'
$ conan config rm hooks.attribute_checker # Deactivates 'attribute_checker'

There is also an environment variable ``CONAN_PLUGINS`` to list the active plugins. Plugins listed in *conan.conf* will be loaded into
this variable and values in the environment variable will be used to load the plugins.
There is also an environment variable ``CONAN_HOOKS`` to list the active hooks. Hooks listed in *conan.conf* will be loaded into
this variable and values in the environment variable will be used to load the hooks.

Plugins are considered part of the Conan client configuration and can be shared as usual with the :ref:`conan_config_install` command.
Hooks are considered part of the Conan client configuration and can be shared as usual with the :ref:`conan_config_install` command.

Official Plugins
Official Hooks
----------------

There is a simple *attribute_checker* plugin ready to be used in Conan. You can take it as a starting point to create your own ones.
There is a simple *attribute_checker* hook ready to be used in Conan. You can take it as a starting point to create your own ones.

attribute_checker
+++++++++++++++++

This plugin is shipped together with the Conan client and its functionality is warning when recipes do not contain some metadata attributes.
This hook is shipped together with the Conan client and its functionality is warning when recipes do not contain some metadata attributes.

.. code-block:: python
:caption: *attribute_checker.py*
Expand All @@ -193,4 +193,4 @@ This plugin is shipped together with the Conan client and its functionality is w
output.warn("Conanfile doesn't have '%s'. It is recommended to add it as attribute"
% field)

This plugin comes activated by default.
This hook comes activated by default.
2 changes: 1 addition & 1 deletion reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ Contents:
reference/tools
reference/config_files
reference/env_vars
reference/plugins
reference/hooks
4 changes: 2 additions & 2 deletions reference/commands/consumer/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ The configuration may contain all or a subset of the allowed configuration files
replaced. The only exception is the **conan.conf** file for which only the variables declared will be installed,
leaving the other variables unchanged.

This means for example that **profiles** and **plugins** files will be overwritten if already present, but no profile or
plugin file that the user has in the local machine will be deleted.
This means for example that **profiles** and **hooks** files will be overwritten if already present, but no profile or
hook file that the user has in the local machine will be deleted.

All the configuration files will be copied to the conan home directory.
These are the special files and the rules applied to merge them:
Expand Down
2 changes: 1 addition & 1 deletion reference/config_files/conan.conf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The typical location of the **conan.conf** file is the directory ``~/.conan/``:
# You can skip the proxy for the matching (fnmatch) urls (comma-separated)
# no_proxy_match = *bintray.com*, https://myserver.*

[plugins] # environment CONAN_PLUGINS
[hooks] # environment CONAN_HOOKS
attribute_checker

# Default settings now declared in the default profile
Expand Down
4 changes: 2 additions & 2 deletions reference/env_vars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,12 @@ For example: For a remote named "conan-center":

SET CONAN_PASSWORD_CONAN_CENTER=Mypassword

CONAN_PLUGINS
CONAN_HOOKS
-------------

**Defaulted to**: Not defined

Can be set to a comma separated list with the names of the plugins that will be executed when running a Conan command.
Can be set to a comma separated list with the names of the hooks that will be executed when running a Conan command.

.. _conan_print_run_commands:

Expand Down
24 changes: 12 additions & 12 deletions reference/plugins.rst → reference/hooks.rst
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
.. _plugins_reference:
.. _hooks_reference:

Plugins [EXPERIMENTAL]
Hooks [EXPERIMENTAL]
======================

.. warning::

This is an **experimental** feature subject to breaking changes in future releases.

The Conan plugins are Python functions that are intended to extend the Conan functionalities and let users customize the client behavior at
The Conan hooks are Python functions that are intended to extend the Conan functionalities and let users customize the client behavior at
determined execution points.

Plugin interface
Hook interface
----------------

Here you can see a complete example of all the plugin functions available and the different parameters for each of them depending on the
Here you can see a complete example of all the hook functions available and the different parameters for each of them depending on the
context:

.. code-block:: python
Expand Down Expand Up @@ -132,7 +132,7 @@ context:
output.info("package_id=%s" % package_id)
output.info("remote.name=%s" % remote.name)

Functions of the plugins are intended to be self-descriptive regarding to the execution of them. For example, the ``pre_package()`` function
Functions of the hooks are intended to be self-descriptive regarding to the execution of them. For example, the ``pre_package()`` function
is called just before the ``package()`` method of the recipe is executed.

For download/upload functions, the ``pre_download()``/``pre_upload()`` function is executed first in an
Expand All @@ -150,8 +150,8 @@ Function parameters

Here you can find the description for each parameter:

- **output**: :ref:`Output object<conanfile_output>` to print formatted messages during execution with the name of the plugin and the
function executed, e.g., ``[PLUGIN - complete_plugin] post_download_package(): This is the remote name: default``.
- **output**: :ref:`Output object<conanfile_output>` to print formatted messages during execution with the name of the hook and the
function executed, e.g., ``[HOOK - complete_hook] post_download_package(): This is the remote name: default``.

- **conanfile**: It is a regular ``ConanFile`` object loaded from the recipe that received the Conan command. It has its normal attributes
and dynamic objects such as ``build_folder``, ``package_folder``...
Expand All @@ -166,8 +166,8 @@ Here you can find the description for each parameter:
- **remote**: Named tuple with attributes ``name``, ``url`` and ``verify_ssl``.

+-------------------------------------+---------------------------------------------------------------------------------------------------------------+
| | Availability of parameters for | **Plugin Functions*** |
| | each Plugin function depending on +--------------+--------------+-------------+---------------+------------------------+--------------------------+
| | Availability of parameters for | **Hook Functions*** |
| | each Hook function depending on +--------------+--------------+-------------+---------------+------------------------+--------------------------+
| | the context | ``export()`` | ``source()`` | ``build()`` | ``package()`` | | ``upload()`` | | ``download()`` |
| | | | | | | ``upload_recipe()`` | | ``download_recipe()`` |
| | | | | | | ``upload_package()`` | | ``download_package()`` |
Expand All @@ -183,7 +183,7 @@ Here you can find the description for each parameter:
| | ``remote`` | No | No | No | No | Yes | Yes |
+----------------+--------------------+--------------+--------------+-------------+---------------+------------------------+--------------------------+

\*Plugin functions are indicated without ``pre`` and ``post`` prefixes for simplicity.
\*Hook functions are indicated without ``pre`` and ``post`` prefixes for simplicity.

Table legend:
- **Yes**: Availability in ``pre`` and ``post`` functions in any context.
Expand All @@ -205,5 +205,5 @@ living in the local cache or in user space). However, they can be checked with t

.. important::

Plugin functions should have a ``**kwargs`` parameter to keep compatibility of new parameters that may be introduced in future versions
Hook functions should have a ``**kwargs`` parameter to keep compatibility of new parameters that may be introduced in future versions
of Conan.