Replies: 1 comment
-
The only solution I can think of is to lazily load the code that does the work (this applies to Rich and logging). Import whatever functionality you need within the function that parses your arguments. def main():
init_rich(sys.argv)
from .app import run
run(sys.argv) Thus ensuring that the console and logging is initialized prior to the code that needs them. No need to reconfigure. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Please take a look at https://stackoverflow.com/questions/65698526/python-catch-22-between-config-loading-console-and-logging-initialization as it is touching rich usage in two particular areas:
I do know that if all CLI tools would trigger console activation and logging only based on environment variables, this conundrum can be avoided, but the reality is that almost all tools also have either command line parameters and/or config files that determine the runtime configuration to use.
Code that runs before config is fully loaded may need to either use log or do some console printing, and both of these are dependent on config loading.
I think that if we manage to find a simple generic solution that addresses the chicken and the egg issue with console and logging initialization for cli tool creators, we could make rich even easier to adopt.
Beta Was this translation helpful? Give feedback.
All reactions