feat: --env-path support

This commit is contained in:
Timothy Jaeryang Baek
2025-04-10 09:27:41 -07:00
parent f25a6fbb9a
commit 6e05f1c56f
3 changed files with 13 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ dependencies = [
"passlib[bcrypt]>=1.7.4",
"pydantic>=2.11.1",
"pyjwt[crypto]>=2.10.1",
"python-dotenv>=1.1.0",
"typer>=0.15.2",
"uvicorn>=0.34.0",
]

View File

@@ -2,7 +2,7 @@ import sys
import asyncio
import typer
import os
from dotenv import load_dotenv
from typing_extensions import Annotated
from typing import Optional, List
@@ -29,6 +29,10 @@ def main(
env: Annotated[
Optional[List[str]], typer.Option("--env", "-e", help="Environment variables")
] = None,
env_path: Annotated[
Optional[str],
typer.Option("--env-path", help="Path to environment variables file"),
] = None,
config: Annotated[
Optional[str], typer.Option("--config", "-c", help="Config file path")
] = None,
@@ -81,6 +85,11 @@ def main(
key, value = var.split("=", 1)
env_dict[key] = value
if env_path:
# Load environment variables from the specified file
load_dotenv(env_path)
env_dict.update(dict(os.environ))
# Set environment variables
for key, value in env_dict.items():
os.environ[key] = value

3
uv.lock generated
View File

@@ -1,5 +1,4 @@
version = 1
revision = 1
requires-python = ">=3.11"
[[package]]
@@ -313,6 +312,7 @@ dependencies = [
{ name = "passlib", extra = ["bcrypt"] },
{ name = "pydantic" },
{ name = "pyjwt", extra = ["crypto"] },
{ name = "python-dotenv" },
{ name = "typer" },
{ name = "uvicorn" },
]
@@ -330,6 +330,7 @@ requires-dist = [
{ name = "passlib", extras = ["bcrypt"], specifier = ">=1.7.4" },
{ name = "pydantic", specifier = ">=2.11.1" },
{ name = "pyjwt", extras = ["crypto"], specifier = ">=2.10.1" },
{ name = "python-dotenv", specifier = ">=1.1.0" },
{ name = "typer", specifier = ">=0.15.2" },
{ name = "uvicorn", specifier = ">=0.34.0" },
]