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

Save/restore ConanOutput global state when using Conan API's command #17095

Merged

Conversation

AbrilRBS
Copy link
Member

@AbrilRBS AbrilRBS commented Oct 1, 2024

Changelog: Bugfix: Restore ConanOutput global state when using Commands API.
Docs: Omit

@AbrilRBS AbrilRBS changed the title Add failing test Save/restore ConanOutput global state when using Conan API's command Oct 6, 2024
@AbrilRBS AbrilRBS marked this pull request as ready for review October 6, 2024 19:00
@AbrilRBS AbrilRBS added this to the 2.9.0 milestone Oct 6, 2024
# 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
Copy link
Member Author

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?

Copy link
Member

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
Copy link
Member

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.

@memsharded memsharded merged commit e25b357 into conan-io:develop2 Oct 8, 2024
2 checks passed
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.

3 participants