Skip to content
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

Make sure .env is loaded before env var are set #1181

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions mesop/env/env.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import os

from dotenv import find_dotenv, load_dotenv

from mesop.exceptions import MesopDeveloperException

if os.environ.get("BUILD_WORKSPACE_DIRECTORY"):
# If running with Bazel, we look for `mesop/.env` from the root workspace.
load_dotenv()
else:
# Try to load .env file for PyPi Mesop build which should be in the user's current
# working directory.
load_dotenv(find_dotenv(usecwd=True))


AI_SERVICE_BASE_URL = os.environ.get(
"MESOP_AI_SERVICE_BASE_URL", "http://localhost:43234"
)
Expand Down
10 changes: 2 additions & 8 deletions mesop/server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@
from pathlib import Path
from typing import Literal

from dotenv import find_dotenv, load_dotenv
from pydantic import BaseModel

if os.environ.get("BUILD_WORKSPACE_DIRECTORY"):
# If running with Bazel, we look for `mesop/.env` from the root workspace.
load_dotenv()
else:
# Try to load .env file for PyPi Mesop build which should be in the user's current
# working directory.
load_dotenv(find_dotenv(usecwd=True))
# Needed to ensure dotenv is loaded
import mesop.env.env # noqa: F401


class Config(BaseModel):
Expand Down
Loading