diff --git a/mesop/env/env.py b/mesop/env/env.py index 1feb753e..b783179a 100644 --- a/mesop/env/env.py +++ b/mesop/env/env.py @@ -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" ) diff --git a/mesop/server/config.py b/mesop/server/config.py index 0026a10e..15ceff98 100644 --- a/mesop/server/config.py +++ b/mesop/server/config.py @@ -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):