From af3152b78b324a244f24739fad964ef82844ed7a Mon Sep 17 00:00:00 2001 From: Tobias Simetsreiter Date: Fri, 22 Mar 2024 14:48:13 +0100 Subject: [PATCH 1/2] remove existing 'file' arg when overwriting print --- conans/client/loader.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/conans/client/loader.py b/conans/client/loader.py index da078b61bc6..24146dfed6d 100644 --- a/conans/client/loader.py +++ b/conans/client/loader.py @@ -323,7 +323,8 @@ def _load_python_file(conan_file_path): raise NotFoundException("%s not found!" % conan_file_path) def new_print(*args, **kwargs): # Make sure that all user python files print() goes to stderr - print(*args, **kwargs, file=sys.stderr) + kwargs['file'] = sys.stderr + print(*args, **kwargs) module_id = str(uuid.uuid1()) current_dir = os.path.dirname(conan_file_path) From 23f7483d5884187bbc583b7c2d6134e92554630d Mon Sep 17 00:00:00 2001 From: Tobias Simetsreiter Date: Fri, 22 Mar 2024 15:24:06 +0100 Subject: [PATCH 2/2] add unittest for new_print override --- conans/test/unittests/model/conanfile_test.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/conans/test/unittests/model/conanfile_test.py b/conans/test/unittests/model/conanfile_test.py index a139d1bbe67..1ec20ae6a4f 100644 --- a/conans/test/unittests/model/conanfile_test.py +++ b/conans/test/unittests/model/conanfile_test.py @@ -37,3 +37,15 @@ def package_info(self): client.save({"conanfile.py": conanfile.replace("pass", "requires = 'pkgb/0.1@user/testing'")}) client.run("create . --name=pkgc --version=0.1 --user=user --channel=testing") + + def test_conanfile_new_print(self): + client = TestClient() + conanfile = """from conan import ConanFile +import sys +class Pkg(ConanFile): + def source(self): + print("Test", file=sys.stderr) + print("Test") +""" + client.save({"conanfile.py": conanfile}) + client.run("source .") \ No newline at end of file