mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 18:02:41 +02:00
- Restructured server module to separate the application creation and configuration. - Moved code dealing with SQLAlchemy database setup and teardown to the main application file. - Moved functions related to configuration file loading to `argos.server.settings`. - Fixed SQLAchemy expressions in `argos.server.queries`. - Implemented a more granular system of setting checks' schedule on the server. - Introduced frequency scheduling on per-website basis in the YAML config. - Introduced Pytest fixtures for handling test database and authorized HTTP client in `tests/conftest.py`. - Included a first test for the api - Implemented changes to models to accommodate changes to task scheduling. - Fixed errors concerning database concurrency arising from changes to the application setup.
58 lines
1.2 KiB
Python
58 lines
1.2 KiB
Python
import os
|
|
from functools import lru_cache
|
|
from os import environ
|
|
|
|
import yaml
|
|
from pydantic_settings import BaseSettings
|
|
from yamlinclude import YamlIncludeConstructor
|
|
|
|
from argos.schemas.config import Config
|
|
|
|
|
|
class DefaultSettings(BaseSettings):
|
|
app_env: str = "prod"
|
|
database_url: str = ""
|
|
yaml_file: str = ""
|
|
|
|
|
|
class DevSettings(DefaultSettings):
|
|
database_url: str = "sqlite:////tmp/argos.db"
|
|
yaml_file: str = "config.yaml"
|
|
|
|
|
|
class TestSettings(DefaultSettings):
|
|
database_url: str = "sqlite:////tmp/test-argos.db"
|
|
yaml_file: str = "tests/config.yaml"
|
|
|
|
|
|
class ProdSettings(DefaultSettings):
|
|
pass
|
|
|
|
|
|
environments = {
|
|
"dev": DevSettings,
|
|
"prod": ProdSettings,
|
|
"test": TestSettings,
|
|
}
|
|
|
|
|
|
@lru_cache()
|
|
def get_app_settings() -> DefaultSettings:
|
|
app_env = environ.get("APP_ENV", "dev")
|
|
settings = environments.get(app_env)
|
|
return settings()
|
|
|
|
|
|
def read_yaml_config(filename):
|
|
parsed = _load_yaml(filename)
|
|
return Config(**parsed)
|
|
|
|
|
|
def _load_yaml(filename):
|
|
base_dir = os.path.dirname(filename)
|
|
YamlIncludeConstructor.add_to_loader_class(
|
|
loader_class=yaml.FullLoader, base_dir=base_dir
|
|
)
|
|
|
|
with open(filename, "r") as stream:
|
|
return yaml.load(stream, Loader=yaml.FullLoader)
|