Skip to content

Commit 7c51813

Browse files
feat(config): support dotenv file to init env variables (#261)
* feat(config): support dotenv file to init env variables * update version
1 parent b423f58 commit 7c51813

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "veadk-python"
3-
version = "0.2.15"
3+
version = "0.2.16"
44
description = "Volcengine agent development kit, integrations with Volcengine cloud services."
55
readme = "README.md"
66
requires-python = ">=3.10"

veadk/config.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import os
1616
from typing import Any
1717

18-
from dotenv import find_dotenv
18+
from dotenv import find_dotenv, load_dotenv
1919
from pydantic import BaseModel, Field
2020

2121
from veadk.configs.database_configs import (
@@ -33,8 +33,16 @@
3333
PrometheusConfig,
3434
TLSConfig,
3535
)
36+
from veadk.utils.logger import get_logger
3637
from veadk.utils.misc import set_envs
3738

39+
logger = get_logger(__name__)
40+
41+
if load_dotenv(find_dotenv(usecwd=True)):
42+
logger.info(f"Find `.env` file in {find_dotenv(usecwd=True)}, load envs.")
43+
else:
44+
logger.info("No env file found.")
45+
3846

3947
class VeADKConfig(BaseModel):
4048
model: ModelConfig = Field(default_factory=ModelConfig)
@@ -89,7 +97,10 @@ def getenv(
8997
veadk_environments = {}
9098

9199
if config_yaml_path:
100+
logger.info(f"Find `config.yaml` file in {config_yaml_path}")
92101
config_dict, _veadk_environments = set_envs(config_yaml_path=config_yaml_path)
93102
veadk_environments.update(_veadk_environments)
103+
else:
104+
logger.warning("No `config.yaml` file found.")
94105

95106
settings = VeADKConfig()

veadk/utils/misc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ def getenv(
128128

129129

130130
def set_envs(config_yaml_path: str) -> tuple[dict, dict]:
131+
from veadk.utils.logger import get_logger
132+
133+
logger = get_logger(__name__)
134+
131135
with open(config_yaml_path, "r", encoding="utf-8") as yaml_file:
132136
config_dict = safe_load(yaml_file)
133137

@@ -138,6 +142,9 @@ def set_envs(config_yaml_path: str) -> tuple[dict, dict]:
138142
k = k.upper()
139143

140144
if k in os.environ:
145+
logger.info(
146+
f"Environment variable {k} has been set, value in `config.yaml` will be ignored."
147+
)
141148
veadk_environments[k] = os.environ[k]
142149
continue
143150
veadk_environments[k] = str(v)

veadk/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
VERSION = "0.2.15"
15+
VERSION = "0.2.16"

0 commit comments

Comments
 (0)