Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print to stderr #15704

Merged
merged 1 commit into from
Feb 20, 2024
Merged

print to stderr #15704

merged 1 commit into from
Feb 20, 2024

Conversation

memsharded
Copy link
Member

@memsharded memsharded commented Feb 19, 2024

Changelog: Fix: Make all recipe and plugins python file print() to stderr, so json outputs to stdout are not broken.
Docs: omit

Close #15671

@memsharded memsharded added this to the 2.2.0 milestone Feb 19, 2024
@@ -362,6 +366,7 @@ def _load_python_file(conan_file_path):
else:
if folder.startswith(current_dir):
module = sys.modules.pop(added)
module.print = new_print
Copy link
Contributor

@jcar87 jcar87 Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this - but makes me wonder if there are any risks since print is a built-in? thinking of unusual scenarios like a frozen interpreter embedded in an executable - but it looks good otherwise!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look, and in theory it seems ok, this kind of overwrite of module globals seems allowed, it is not changing the built-in print, just making the module print() pointing to another function, and this is done per-module, not globally.

@jcar87 jcar87 requested a review from uilianries February 19, 2024 17:12
@AbrilRBS
Copy link
Member

Should this be using builtins.print internally? https://docs.python.org/3/library/builtins.html say that's what the builtins map to, but this also seems to work

@memsharded
Copy link
Member Author

Should this be using builtins.print internally? https://docs.python.org/3/library/builtins.html say that's what the builtins map to, but this also seems to work

If we were forced to use the print() name in our replacement, this would be necessary, but as we have control over the loaded module, our own new_print is good too.

Copy link
Member

@uilianries uilianries left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jenkins will be pleased by this change.

@czoido czoido merged commit 896035e into conan-io:develop2 Feb 20, 2024
2 checks passed
@memsharded memsharded deleted the fix/print_stderr branch February 20, 2024 09:31
@araffin araffin mentioned this pull request Apr 17, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] calls to python's builtin print() function cause issues with --format=json command output
5 participants