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

Verbosity as Resource Option triggers an error #11

Closed
Yannick-Dayer opened this issue Oct 1, 2024 · 4 comments · Fixed by #12
Closed

Verbosity as Resource Option triggers an error #11

Yannick-Dayer opened this issue Oct 1, 2024 · 4 comments · Fixed by #12
Assignees

Comments

@Yannick-Dayer
Copy link
Collaborator

The fix to have the correct log level in config files (implemented in #6) has the side effect of causing an error when verbosity_option is also a config option, and its entry_point_group argument is not provided.

    @click.command(cls=ConfigCommand)
    @clapper.click.verbosity_option(
        # entry_point_group="config_group",  # Commenting this causes an error
        cls=ResourceOption,
    )
    my_command(**kwargs):
        pass

Calling my_command -v causes the following error:

TypeError: The ResourceOption class is not meant to be used this way. See package documentation for details.
@Yannick-Dayer Yannick-Dayer self-assigned this Oct 1, 2024
@anjos
Copy link
Member

anjos commented Oct 2, 2024

I can confirm I experienced that. I had to remove all occurrences of that from my code.

@Yannick-Dayer
Copy link
Collaborator Author

It shows the conflict that the verbosity option could be set in a config file.

I can mitigate this problem (and keep back-compatibility) by making the option "eager" only if there is no way to set it in the config.
There would be two cases:

  • When verbosity_option is an instance of ResourceOption, the logger will not be set during the config (previous behavior: the logging level of the app can be set either by the config or by the -v option).
  • If verbosity_option is not a ResourceOption, the logger level will be set correctly in the config files (new behavior, the logging level of the config files and the app can be set by the -v option).

It seems a good compromise, without trying to pre-load the files to search for a possible verbosity config before loading the configs.

@183amir
Copy link
Collaborator

183amir commented Oct 2, 2024

can we parse the option twice and call the callback twice if eager mode is set?

@Yannick-Dayer
Copy link
Collaborator Author

Even then, what is the behavior when verbosity_option is a ResourceOption and verbose is set in a config file?

When we have the verbose value, the config loading will have already been done, and the logs in the config files are already out; too late to change the log level of those.

@anjos anjos closed this as completed in #12 Oct 2, 2024
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 a pull request may close this issue.

3 participants