-
Notifications
You must be signed in to change notification settings - Fork 988
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
Save/restore ConanOutput global state when using Conan API's command #17095
Save/restore ConanOutput global state when using Conan API's command #17095
Conversation
# get redefined when running a command and leak to the calling scope | ||
# if running from a custom command. | ||
# Store the old one and restore it after the command execution as a workaround. | ||
_conan_output_level = ConanOutput._conan_output_level |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern is spread thru the code in a few places, we could have something like this maybe?
@contenxtmanager
def restore_after(entity, *attributes):
old_values = [getvalue(entity, attribute) for attribute in attributes)
try:
yield
finally:
for attribute, old_value in zip(attributes, old_values):
setattr(entity, attribute, old_value)
which would be used in 3-4 places from a quick look. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reviewed all finally
in our code, I am not sure it is worth the abstraction at this point, but we can discussed, I am not opposed.
# get redefined when running a command and leak to the calling scope | ||
# if running from a custom command. | ||
# Store the old one and restore it after the command execution as a workaround. | ||
_conan_output_level = ConanOutput._conan_output_level |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reviewed all finally
in our code, I am not sure it is worth the abstraction at this point, but we can discussed, I am not opposed.
Changelog: Bugfix: Restore ConanOutput global state when using
Commands
API.Docs: Omit