Skip to content

Commit

Permalink
Make sure .env is loaded before env var are set (#1181)
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-to authored Jan 17, 2025
1 parent 6f644d5 commit d0b252d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
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

0 comments on commit d0b252d

Please sign in to comment.