Skip to content

Commit

Permalink
fix env loading (#140)
Browse files Browse the repository at this point in the history
* fix env loading

* only set missing, required variables
  • Loading branch information
bjchambers authored Feb 7, 2025
1 parent e85dbbd commit b26aed6
Showing 1 changed file with 4 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,13 @@ def initialize_from_prompts(env: Environment = Environment.CASSIO):
import getpass

for required in env.required_envvars():
if required in NON_SECRETS:
if required in os.environ:
continue
elif required in NON_SECRETS:
os.environ[required] = input(required)
else:
os.environ[required] = getpass.getpass(required)

if (keyspace := input("ASTRA_DB_KEYSPACE (empty for default)")) is not None:
os.environ["ASTRA_DB_KEYSPACE"] = keyspace
else:
os.environ.pop("ASTRA_DB_KEYSPACE", None)

if (
lc_api_key := getpass.getpass("LANGCHAIN_API_KEY (empty for no tracing)")
) is not None:
os.environ["LANGCHAIN_API_KEY"] = lc_api_key
os.environ["LANGCHAIN_TRACING_V2"] = "True"
else:
os.environ.pop("LANGCHAIN_API_KEY")
os.environ.pop("LANGCHAIN_TRACING_V2")


def initialize_environment(env: Environment = Environment.CASSIO):
"""
Expand All @@ -113,7 +101,7 @@ def initialize_environment(env: Environment = Environment.CASSIO):
3. If necessary variables aren't set by the above, then prompts the user.
"""
# 1. If a `.env` file is found, load environment variables from that.
if (dotenv_path := find_dotenv()) is not None:
if dotenv_path := find_dotenv():
load_dotenv(dotenv_path)
verify_environment(env)
return
Expand Down

0 comments on commit b26aed6

Please sign in to comment.