Skip to content

Clarify that self.generator_info is None by default #4132

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

Open
wants to merge 1 commit into
base: release/2.17
Choose a base branch
from
Open
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 reference/conanfile/attributes/consumers.inc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ generator_info
.. include:: ../../common/experimental_warning.inc

Generators to be passed to the dependant recipes.
Should be only filled in the ``package_info()`` method.
Should be only filled in the ``package_info()`` method, ``None`` by default.

.. seealso::

Expand Down
7 changes: 4 additions & 3 deletions reference/conanfile/methods/package_info.rst
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ generator_info


``tool_requires`` in the build context can inject generators into the recipe,
by adding them to the ``generator_info`` list inside the ``package_info`` method.
by adding them to the ``generator_info`` attribute inside the ``package_info`` method.
This is useful to inject custom generators into the recipe, that will be used by the consumers of the package,
just as if they were declared in their ``generators`` attribute.

Expand All @@ -320,9 +320,10 @@ just as if they were declared in their ``generators`` attribute.
self.output.info(f"Calling custom generator for {conanfile}")

def package_info(self):
self.generator_info.append(MyGenerator)
self.generator_info = [MyGenerator]

Note that this only propagates from the immediate, direct ``tool_requires`` of a recipe.
Note that this only propagates from the immediate, direct ``tool_requires`` of a recipe,
and that by default ``self.generator_info`` is ``None``.


.. note::
Expand Down
7 changes: 4 additions & 3 deletions reference/extensions/custom_generators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ Generators from tool_requires
A direct dependency tool requires can also be used to provide custom generators.
The following example shows how to create a custom generator that generates a file with the
dependencies of the package, just like the example above, but using a ``tool_require`` instead of a ``python_require``
to inject the generator into the recipe, by adding them to the ``self.generator_info`` list inside the ``package_info`` method.
to inject the generator into the recipe, by adding them to the ``self.generator_info`` attribute inside the ``package_info`` method.
Note that this attribute is ``None`` by default, so you need to set it explicitly to a list of generators.

.. code-block:: python
:caption: mygenerator/conanfile.py
Expand Down Expand Up @@ -140,7 +141,7 @@ inject the generator into the recipe.

.. note::

Note that built-in generators can also be injected using tool_requires,
by adding them by name: ``self.generator_info.append("CMakeDeps")``.
Built-in generators can also be injected using tool_requires,
by adding them by name: ``self.generator_info = ["CMakeDeps"]``.
``tool_require``ing this package will inject the ``CMakeDeps`` generator into the recipe
just as if it was declared in its ``generators`` attribute.