-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Convert config template to pydantic model
- Loading branch information
1 parent
1dd9f84
commit ae531cc
Showing
37 changed files
with
349 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
|
||
.idea | ||
config/* | ||
!config/config_template.yaml | ||
.history | ||
**/__pycache__/ | ||
.vscode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,18 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
import logging | ||
|
||
import jsonschema | ||
import jsonschema.exceptions | ||
|
||
from . import exceptions, loader | ||
from . import generate, loader, models | ||
|
||
log = logging.getLogger(__name__) | ||
config = loader.load_yaml() | ||
|
||
if not loader.does_config_exist(): | ||
log.warning( | ||
"No configuration file found. Generating default configuration at backend/capellacollab/config/config.yaml" | ||
) | ||
generate.write_config() | ||
|
||
|
||
def validate_schema(): | ||
config_schema = loader.load_config_schema() | ||
try: | ||
jsonschema.validate(config, config_schema) | ||
except jsonschema.exceptions.ValidationError as error: | ||
raise exceptions.InvalidConfigurationError( | ||
f"{error.__class__.__name__}: {error.message}", | ||
) from None | ||
config_data = loader.load_yaml() | ||
config = models.AppConfig(**config_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import os | ||
|
||
import yaml | ||
|
||
from . import models | ||
|
||
|
||
def write_config(): | ||
current_dir = os.path.dirname(os.path.realpath(__file__)) | ||
config_path = os.path.join(current_dir, "config.yaml") | ||
|
||
app_config = models.AppConfig() | ||
config_dict = app_config.model_dump() | ||
yaml_str = yaml.dump(config_dict, sort_keys=False) | ||
|
||
with open(config_path, "w", encoding="utf-8") as yaml_file: | ||
yaml_file.write(yaml_str) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.