@@ -16,6 +16,7 @@ One way of having your own custom generators in Conan is by using them as
16
16
`python_requires ` package:
17
17
18
18
.. code-block :: python
19
+ :caption: mygenerator/ conanfile.py
19
20
20
21
from conan import ConanFile
21
22
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
28
29
def generate (self ):
29
30
deps_info = " "
30
31
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 "
32
33
save(self ._conanfile, " deps.txt" , deps_info)
33
34
34
35
@@ -38,9 +39,10 @@ One way of having your own custom generators in Conan is by using them as
38
39
package_type = " python-require"
39
40
40
41
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:
42
43
43
44
.. code-block :: python
45
+ :caption: pkg/ conanfile.py
44
46
45
47
from conan import ConanFile
46
48
@@ -50,12 +52,20 @@ And then use it in the generate method of your own packages like this:
50
52
version = " 1.0"
51
53
52
54
python_requires = " mygenerator/1.0"
53
- requires = " zlib/1.2.11"
55
+ requires = " zlib/1.2.11" , " bzip2/1.0.8 "
54
56
55
57
def generate (self ):
56
- mygenerator = self .python_requires[" mygenerator" ].module.MyGenerator()
58
+ mygenerator = self .python_requires[" mygenerator" ].module.MyGenerator(self )
57
59
mygenerator.generate()
58
60
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
+
59
69
This has the advantage that you can version your own custom generators as packages and
60
70
also that you can share those generators as Conan packages.
61
71
0 commit comments