Skip to content

Commit 22a2eef

Browse files
authored
fix custom generators (#3781)
1 parent db2c5f8 commit 22a2eef

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

reference/extensions/custom_generators.rst

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ One way of having your own custom generators in Conan is by using them as
1616
`python_requires` package:
1717

1818
.. code-block:: python
19+
:caption: mygenerator/conanfile.py
1920
2021
from conan import ConanFile
2122
from conan.tools.files import save
@@ -28,7 +29,7 @@ One way of having your own custom generators in Conan is by using them as
2829
def generate(self):
2930
deps_info = ""
3031
for dep, _ in self._conanfile.dependencies.items():
31-
deps_info = f"{dep.ref.name}, {dep.ref.version}"
32+
deps_info += f"{dep.ref.name}, {dep.ref.version}\n"
3233
save(self._conanfile, "deps.txt", deps_info)
3334
3435
@@ -38,9 +39,10 @@ One way of having your own custom generators in Conan is by using them as
3839
package_type = "python-require"
3940
4041
41-
And then use it in the generate method of your own packages like this:
42+
And then ``conan create mygenerator`` and use it in the generate method of your own packages like this:
4243

4344
.. code-block:: python
45+
:caption: pkg/conanfile.py
4446
4547
from conan import ConanFile
4648
@@ -50,12 +52,20 @@ And then use it in the generate method of your own packages like this:
5052
version = "1.0"
5153
5254
python_requires = "mygenerator/1.0"
53-
requires = "zlib/1.2.11"
55+
requires = "zlib/1.2.11", "bzip2/1.0.8"
5456
5557
def generate(self):
56-
mygenerator = self.python_requires["mygenerator"].module.MyGenerator()
58+
mygenerator = self.python_requires["mygenerator"].module.MyGenerator(self)
5759
mygenerator.generate()
5860
61+
Then, doing a ``conan install pkg`` on this ``pkg`` recipe, will create a ``deps.txt`` text file containing:
62+
63+
.. code-block:: text
64+
65+
zlib, 1.2.11
66+
bzip2, 1.0.8
67+
68+
5969
This has the advantage that you can version your own custom generators as packages and
6070
also that you can share those generators as Conan packages.
6171

0 commit comments

Comments
 (0)