Skip to content

Commit

Permalink
Fix: remove existing 'file' arg when overwriting print (conan-io#15912)
Browse files Browse the repository at this point in the history
* remove existing 'file' arg when overwriting print

* add unittest for new_print override
  • Loading branch information
dasimmet authored and czoido committed Mar 25, 2024
1 parent f416a7e commit 562f0b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion conans/client/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions conans/test/unittests/model/conanfile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 .")

0 comments on commit 562f0b9

Please sign in to comment.