|
15 | 15 | import os |
16 | 16 | from typing import Any |
17 | 17 |
|
18 | | -from dotenv import find_dotenv, load_dotenv |
| 18 | +from dotenv import find_dotenv, load_dotenv, dotenv_values |
19 | 19 | from pydantic import BaseModel, Field |
20 | 20 |
|
21 | 21 | from veadk.configs.auth_configs import VeIdentityConfig |
|
39 | 39 |
|
40 | 40 | logger = get_logger(__name__) |
41 | 41 |
|
42 | | -if load_dotenv(find_dotenv(usecwd=True)): |
43 | | - logger.info(f"Find `.env` file in {find_dotenv(usecwd=True)}, load envs.") |
| 42 | +env_file_path = os.path.join(os.getcwd(), ".env") |
| 43 | +if os.path.isfile(env_file_path): |
| 44 | + load_dotenv(env_file_path) |
| 45 | + env_from_dotenv = dotenv_values(env_file_path) |
| 46 | + logger.info(f"Find `.env` file in {env_file_path}, load envs.") |
44 | 47 | else: |
45 | | - logger.info("No env file found.") |
| 48 | + env_from_dotenv = {} |
| 49 | + logger.info("No `.env` file found.") |
46 | 50 |
|
47 | 51 |
|
48 | 52 | class VeADKConfig(BaseModel): |
@@ -97,11 +101,13 @@ def getenv( |
97 | 101 |
|
98 | 102 | config_yaml_path = find_dotenv(filename="config.yaml", usecwd=True) |
99 | 103 |
|
100 | | -veadk_environments = {} |
| 104 | +veadk_environments = dict(env_from_dotenv) |
101 | 105 |
|
102 | 106 | if config_yaml_path: |
103 | 107 | logger.info(f"Find `config.yaml` file in {config_yaml_path}") |
104 | | - config_dict, _veadk_environments = set_envs(config_yaml_path=config_yaml_path) |
| 108 | + config_dict, _veadk_environments = set_envs( |
| 109 | + config_yaml_path=config_yaml_path, env_from_dotenv=env_from_dotenv |
| 110 | + ) |
105 | 111 | veadk_environments.update(_veadk_environments) |
106 | 112 | else: |
107 | 113 | logger.warning("No `config.yaml` file found.") |
|
0 commit comments