Skip to content

Commit

Permalink
bug: use correct config file path when loading all configs (#397)
Browse files Browse the repository at this point in the history
* bug: use correct config file path when loading all configs

* bug: deglob directory path from config path when loading config files

---------

Co-authored-by: Gerred Dillon <[email protected]>
  • Loading branch information
YrrepNoj and gerred authored Apr 15, 2024
1 parent 0463af9 commit fdc0ef9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
python-version-file: 'pyproject.toml'

- name: Run Repeater
run: docker run -p 50051:50051 -d ghcr.io/defenseunicorns/leapfrogai/repeater:0.3.3
run: docker run -p 50051:50051 -d --name=repeater ghcr.io/defenseunicorns/leapfrogai/repeater:0.3.3

- name: Install Python Deps
run: pip install ".[dev]"
Expand Down
18 changes: 14 additions & 4 deletions src/leapfrogai_api/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import yaml
from watchfiles import Change, awatch

logging.basicConfig(level=logging.INFO)


class Model:
name: str
Expand Down Expand Up @@ -78,6 +80,8 @@ async def clear_all_models(self):
logging.info("All models have been removed")

def load_config_file(self, directory: str, config_file: str):
logging.info("Loading config file: {}/{}".format(directory, config_file))

# load the config file into the config object
config_path = os.path.join(directory, config_file)
with open(config_path) as c:
Expand All @@ -100,15 +104,21 @@ def load_config_file(self, directory: str, config_file: str):
return

def load_all_configs(self, directory="", filename="config.yaml"):
logging.info(
"Loading all configs in {} that match the name '{}'".format(
directory, filename
)
)

if not os.path.exists(directory):
logging.error("The config directory ({}) does not exist".format(directory))
return "THE CONFIG DIRECTORY DOES NOT EXIST"

# Get all config files
# Get all config files and load them into the config object
config_files = glob.glob(os.path.join(directory, filename))

# load all the found config files into the config object
for config_path in config_files:
self.load_config_file(directory, filename)
dir_path, file_path = os.path.split(config_path)
self.load_config_file(directory=dir_path, config_file=file_path)

return

Expand Down

0 comments on commit fdc0ef9

Please sign in to comment.