@@ -38,6 +38,10 @@ def _fake_conan_sources(graph):
3838 if recipe_folder :
3939 fake_sources_tgz_path = os .path .join (os .path .dirname (node .get ("recipe_folder" )), "d" , "conan_sources.tgz" )
4040 save (fake_sources_tgz_path , "" )
41+ if node .get ("python_requires" ):
42+ for _ , pyreq_info in node .get ("python_requires" ).items ():
43+ fake_pyreq_tgz_path = os .path .join (os .path .dirname (pyreq_info .get ("path" )), "d" , "conan_sources.tgz" )
44+ save (fake_pyreq_tgz_path , "" )
4145
4246
4347def test_static_library_skip_binaries ():
@@ -161,6 +165,62 @@ def package_info(self):
161165 assert len (build_info ["modules" ][3 ]["dependencies" ]) == 2
162166
163167
168+ def test_python_requires_in_build_info_dependencies ():
169+ pyreq_cf = textwrap .dedent ("""
170+ from conan import ConanFile
171+
172+ class PyreqConan(ConanFile):
173+ name = "pyreq"
174+ version = "1.0"
175+ package_type = "python-require"
176+ """ )
177+ save ("conanfile.py" , pyreq_cf )
178+ run ("conan create ." )
179+
180+ app_cf = textwrap .dedent ("""
181+ from conan import ConanFile
182+
183+ class AppConan(ConanFile):
184+ name = "app"
185+ version = "1.0"
186+ package_type = "application"
187+ python_requires = "pyreq/1.0"
188+ """ )
189+ save ("conanfile.py" , app_cf )
190+ run ("conan create . -f json > create.json" )
191+
192+ graph = json .loads (load ("create.json" ))["graph" ]
193+ _fake_conan_sources (graph )
194+
195+ run ("conan art:build-info create create.json build_name 1 repo --with-dependencies > bi.json" )
196+ build_info = json .loads (load ("bi.json" ))
197+
198+ modules = build_info ["modules" ]
199+ app_recipe_module = [m for m in modules if m ["id" ] == "app/1.0#697c25af89f95d7c16b88d97972fb7ad" ][0 ]
200+ app_pkg_module = [m for m in modules if
201+ "app/1.0#697c25af89f95d7c16b88d97972fb7ad:19f85b5f0cf7b39158b8bce1a58bcb78449fee9d" in m ["id" ]][0 ]
202+
203+ app_recipe_module_deps = [d ["id" ] for d in app_recipe_module .get ("dependencies" )]
204+ assert "pyreq/1.0#7ff25468818796e3c188019d6db1ff93 :: conan_sources.tgz" in app_recipe_module_deps
205+ assert "pyreq/1.0#7ff25468818796e3c188019d6db1ff93 :: conanfile.py" in app_recipe_module_deps
206+ assert "pyreq/1.0#7ff25468818796e3c188019d6db1ff93 :: conanmanifest.txt" in app_recipe_module_deps
207+ # assert python require is not a dependency of the package
208+ assert len (app_pkg_module .get ("dependencies" )) == 0
209+
210+ # Test no python_requires found if --with-dependencies is not used
211+ run ("conan art:build-info create create.json build_name 1 repo > bi_nodeps.json" )
212+ build_info = json .loads (load ("bi_nodeps.json" ))
213+
214+ modules = build_info ["modules" ]
215+ app_recipe_module = [m for m in modules if m ["id" ] == "app/1.0#697c25af89f95d7c16b88d97972fb7ad" ][0 ]
216+ app_pkg_module = [m for m in modules if
217+ "app/1.0#697c25af89f95d7c16b88d97972fb7ad:19f85b5f0cf7b39158b8bce1a58bcb78449fee9d" in m ["id" ]][0 ]
218+
219+ assert "dependencies" not in app_recipe_module
220+ assert "dependencies" not in app_pkg_module
221+
222+
223+
164224def test_formatted_time ():
165225 """Compare local timestamp hours from build-info JSON with current timestamp in UTC"""
166226 run ("conan new cmake_lib -d name=lib1 -d version=1.0" )
0 commit comments