-
Notifications
You must be signed in to change notification settings - Fork 75
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
[server] 4/n Update Use .env at the run step #1384
Conversation
@@ -334,7 +334,8 @@ def run() -> FlaskResponse: | |||
|
|||
# Allow user to modify their environment keys without reloading the server. | |||
# Execution time of `0.001s` is arbitrary, but should be small enough to not be noticeable. | |||
dotenv.load_dotenv() | |||
# Should override be set to True? | |||
dotenv.load_dotenv(state.env_path) |
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.
RFC: should we override when a new key is set? unsure
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.
Good question. I say yes, we should override if env_path is set.
If we don't override, then calling set_env_file_path
will effectively be a no-op if the file contains variables that already exist (e.g. from a previous call). This would be confusing in a scenario where we call set_env_file_path
with one file and then call it again with another. From the server standpoint, I would say:
- if no state.env_path, then don't override (keep existing behaviour)
- if state.env_path is set, there has been an explicit request to set env path and would be ideal for the variables in that env file to take precedence
But, from the vscode perspective, is there any scenario where set_env_file_path
will be called with different paths for the same server? Is the server persisted when moving a file to a different dir, for example? If there is such a case I think we must override if the path is set, otherwise we would not be using the closest/expected env variables. I guess the fact we have a 'set API keys' command means this is the case.
More generally, the only way I could make an argument to not override is:
- if it can't be changed for an existing server
- user is familiar with load_dotenv so they know existing environment (e.g. set in shell) takes precedence over .env file
IMO this argument isn't very strong and as a user if I explicitly do an action to "Set API Keys" I would 100% want the key I just set to be used instead of whatever may already be set for the same variable
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.
Thanks for the analysis. I'm in agreement. In the meantime I've updated to set override to true
d491230
to
c5bf44b
Compare
Summary: Title. No functional Changes in this diff. Test Plan: --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/lastmile-ai/aiconfig/pull/1384). * __->__ #1384 * #1383 * #1382
c5bf44b
to
8f5787f
Compare
Summary: Stack contains changes that updates overall environment setup flow for vscode extension. No functional Changes in this diff. Test Plan:
9233558
to
90c1e69
Compare
5763b34
to
0f8d6cb
Compare
|
0f8d6cb
to
8504d1e
Compare
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.
Accepting to unblock, but please make suggested changes
@@ -335,7 +335,8 @@ def run() -> FlaskResponse: | |||
|
|||
# Allow user to modify their environment keys without reloading the server. | |||
# Execution time of `0.001s` is arbitrary, but should be small enough to not be noticeable. | |||
dotenv.load_dotenv() | |||
# Should override be set to True? |
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.
Maybe update comment to state something like,
"Override if env_file_path is specified so that provided .env values take precedence over existing values"
@@ -335,7 +335,8 @@ def run() -> FlaskResponse: | |||
|
|||
# Allow user to modify their environment keys without reloading the server. | |||
# Execution time of `0.001s` is arbitrary, but should be small enough to not be noticeable. | |||
dotenv.load_dotenv() | |||
# Should override be set to True? | |||
dotenv.load_dotenv(state.env_file_path, override= True) |
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.
Let's do override=(state.env_file_path is not None)
(or whatever the clean python way is). We should not override if no path is set since that changes behaviour
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.
thanks, +1. You're pretty good at python 😉
Summary: Stack contains changes that updates overall environment setup flow for vscode extension. This diff implements the server side endpoint. Will test on top with vscode Test Plan: ``` payload={'env_file_path': {}} Status Code: 400 Response JSON: {'message': 'Invalid request, specified .env file path is not a string.'} payload={'env_file_path': '/hi'} Status Code: 400 Response JSON: {'message': 'Specified .env file path does not exist.'} payload={'env_file_path': '.env'} Status Code: 200 Response JSON: {'message': 'Updated .env file path.'} ```
Summary: Test Plan:
|
Summary: This diff modifies the AIConfig start and edit commands to take in an dot env path. Due to core utils logic of handling args, the help messages automatically get updated too. Also Removes the loadenv() on server init. This is okay because loadenv is invoked at the run step. [see 4/n](#1384) Test Plan:
Summary: This diff modifies the AIConfig start and edit commands to take in an dot env path. Due to core utils logic of handling args, the help messages automatically get updated too. Also Removes the loadenv() on server init. This is okay because loadenv is invoked at the run step. [see 4/n](#1384) Test Plan: ``` ankush@ap-mbp aiconfig % aiconfig start -h /opt/homebrew/lib/python3.11/site-packages/pydantic/_internal/_fields.py:151: UserWarning: Field "model_parsers" has conflict with protected namespace "model_". You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`. warnings.warn( usage: aiconfig start [-h] [--server-port SERVER_PORT] [--log-level LOG_LEVEL] [--server-mode {debug_servers,debug_backend,prod}] [--parsers-module-path PARSERS_MODULE_PATH] [--env-file-path ENV_FILE_PATH] options: -h, --help show this help message and exit --server-port SERVER_PORT --log-level LOG_LEVEL --server-mode {debug_servers,debug_backend,prod} --parsers-module-path PARSERS_MODULE_PATH **--env-file-path ENV_FILE_PATH** ```
Summary: This diff modifies the AIConfig start and edit commands to take in an dot env path. Due to core utils logic of handling args, the help messages automatically get updated too. Also Removes the loadenv() on server init. This is okay because loadenv is invoked at the run step. [see 4/n](#1384) Test Plan: ``` ankush@ap-mbp aiconfig % aiconfig start -h /opt/homebrew/lib/python3.11/site-packages/pydantic/_internal/_fields.py:151: UserWarning: Field "model_parsers" has conflict with protected namespace "model_". You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`. warnings.warn( usage: aiconfig start [-h] [--server-port SERVER_PORT] [--log-level LOG_LEVEL] [--server-mode {debug_servers,debug_backend,prod}] [--parsers-module-path PARSERS_MODULE_PATH] [--env-file-path ENV_FILE_PATH] options: -h, --help show this help message and exit --server-port SERVER_PORT --log-level LOG_LEVEL --server-mode {debug_servers,debug_backend,prod} --parsers-module-path PARSERS_MODULE_PATH **--env-file-path ENV_FILE_PATH** ```
[server] 4/n Update Use .env at the run step
Summary:
Test Plan:
Stack created with Sapling. Best reviewed with ReviewStack.