-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add support for loading from .env
files
#296
base: main
Are you sure you want to change the base?
Conversation
d64522f
to
f541656
Compare
❌ 6 Tests Failed:
View the top 3 failed tests by shortest run timetests.agent.test_event_handler�test_parse_event_invalid_json tests.agent.test_event_handler�test_parse_event_invalid_json tests.agent.test_event_handler�test_parse_event_missing_required_field To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard |
examples/agent/imgs/sidebar.png
Outdated
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.
should this be included in changes?
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.
It's part of the README update to better explain where the env variables come from.
cc @joshzzheng
import os | ||
|
||
# throw error if file does not exist | ||
initial_vars: set[str] = set(os.environ.keys()) # noqa: TID251 # we aren't actually using these vars |
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'd like to avoid loading all the user's env vars. Can the following be used instead:
from dotenv import dotenv_values
config = dotenv_values(".env")
"returns a dict with the values parsed from the .env file."
https://pypi.org/project/python-dotenv/#load-configuration-without-altering-the-environment
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.
fyi doing above would mean we cannot merge system env vars + .env
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.
What's the concern here?
Users have to opt-in to load their environment variables in 2 different ways.
- By creating a
env
file and specifically putting the variables they want loaded into it. - By explicitly passing that file to
gx-agent --env-file
We are never directly accessing any env variable values in the agent code.
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.
Is the idea that we would selectively load environment variables from the env
file?
That would be a departure from how .env
file loading typically works.
Or are you just saying you want me to use dotenv_values()
to determine which env variables were loaded (instead of doing the set difference operation)?
Edit:
I've updated the implementation.
5c84a64
to
c8b2eaf
Compare
I don't understand the test failures I'm seeing. The only way I could see the changes I've added affecting these tests is if they were relying on some prior env variable state, which my
|
--json-log Output logs in JSON format. Defaults to False. | ||
--log-cfg-file LOG_CFG_FILE | ||
Path to a logging configuration json file. Supersedes --log-level and --skip-log-file. | ||
--version Show the GX Agent version. | ||
Path to a logging configuration file in JSON format. Supersedes --log-level and --skip-log-file. | ||
--custom-log-tags CUSTOM_LOG_TAGS | ||
Additional tags for logs in form of key-value pairs | ||
--version Show the gx agent version. |
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.
These args aren't new but the Readme example hadn't been updated in awhile.
Add an optional
gx-agent --env-file
CLI argument that allows the agent to load ENV variables from a file.https://saurabh-kumar.com/python-dotenv/
Also, update our readme to have a more complete Quick-Start started example.