Skip to content

Commit

Permalink
fix: environment variable loading
Browse files Browse the repository at this point in the history
  • Loading branch information
01Joseph-Hwang10 committed May 15, 2024
1 parent 74bcf0e commit f8e5f06
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions ldm/commands/_install.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
from os import getcwd
from os.path import join
from os.path import join, exists
from yaml_replace import YAMLTemplate
from os.path import exists
from ._command import Command
from ..api.installer import Installer
from ..api.config import CONFIG_FILE_NAME, DependencyConfig
Expand All @@ -17,9 +16,9 @@ def run(self, targets: list[str] | None = None):
self.logger.error("No configuration file found")
exit(1)

# Load environment variables
for env_file in config.config.environment.env_files:
load_dotenv(dotenv_path=join(getcwd(), env_file))
self.logger.debug("Read configuration file: ")
for line in config.model_dump_json(indent=2).split("\n"):
self.logger.debug(line)

Installer(logger=self.logger).install(config, targets)
exit(0)
Expand All @@ -28,6 +27,14 @@ def run(self, targets: list[str] | None = None):
def read_config() -> DependencyConfig | None:
if exists(CONFIG_FILE_NAME):
with open(CONFIG_FILE_NAME, "r") as f:
config = YAMLTemplate(f.read()).render(dict(os.environ))
return DependencyConfig(**config)
# Read configuration file
template = YAMLTemplate(f.read())
config = DependencyConfig(**template.render({}))

# Load environment variables
for env_file in config.config.environment.env_files:
load_dotenv(dotenv_path=join(getcwd(), env_file))

# Rerender configuration file with environment variables
return DependencyConfig(**template.render(os.environ))
return None

0 comments on commit f8e5f06

Please sign in to comment.