Adding dotenv to cli#41
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the command-line interface (CLI) by integrating Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds python-dotenv to load environment variables from a .env file for the CLI. The dependency is correctly moved to the core dependencies. However, the call to load_dotenv() is at the module level in skydiscover/cli.py, which can cause side effects, especially for testing. I've recommended moving this call into the main() function to scope its execution to when the CLI is run as a script, which will improve testability and prevent unexpected behavior when the module is imported elsewhere.
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| load_dotenv() |
There was a problem hiding this comment.
Calling load_dotenv() at the module level can cause unintended side effects, especially during testing. For example, tests/test_cli_checkpoint_discovery.py imports a function from this module, which would trigger load_dotenv() and could make tests dependent on a .env file or modify the environment unexpectedly.
It's better to move this call inside the main() function to ensure it only runs when the CLI is executed as a script. This will isolate the side effect of loading environment variables to the application's entry point. You should remove this line and add load_dotenv() to your main function, like so:
def main() -> int:
"""Synchronous entry point for the skydiscover console script."""
load_dotenv()
return asyncio.run(main_async())There was a problem hiding this comment.
I can make this change if requested. Note that there are main() and main_async(). I'm not sure which of them to update (or maybe both).
|
Hi @lynnliu030 , any input from you on this? |
lynnliu030
left a comment
There was a problem hiding this comment.
hi @assaftibm, sorry for the delay! I think put it in main() only is fine, which is the CLI entry point. No need to add it to both. Thanks for the contribution!
Loading environment variables from a .env file when running from the cli.