Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use model_config over Config class #199

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ testpaths = [
"tests",
]
filterwarnings = [
# "error",
# FIXME: find a way to use the BaseSettings from pydantic-settings with ConfigDict
"ignore:Support for class-based `config` is deprecated:pydantic.warnings.PydanticDeprecatedSince20",
"error",
]
xfail_strict = true

Expand Down
25 changes: 10 additions & 15 deletions ragna/core/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

import tomlkit
from pydantic import Field, ImportString, field_validator
from pydantic_settings import BaseSettings, PydanticBaseSettingsSource

import ragna
from pydantic_settings import (
BaseSettings,
PydanticBaseSettingsSource,
SettingsConfigDict,
)

from ._authentication import Authentication
from ._components import Assistant, SourceStorage
Expand Down Expand Up @@ -39,8 +41,7 @@ def customise_sources(


class CoreConfig(BaseSettings):
class Config(ConfigBase):
env_prefix = "ragna_rag_"
model_config = SettingsConfigDict(env_prefix="ragna_core_")

queue_url: str = "memory"

Expand All @@ -54,8 +55,7 @@ class Config(ConfigBase):


class ApiConfig(BaseSettings):
class Config(ConfigBase):
env_prefix = "ragna_api_"
model_config = SettingsConfigDict(env_prefix="ragna_api_")

url: str = "http://127.0.0.1:31476"
# FIXME: this needs to be dynamic for the UI url
Expand All @@ -68,8 +68,7 @@ class Config(ConfigBase):


class UiConfig(BaseSettings):
class Config(ConfigBase):
env_prefix = "ragna_ui_"
model_config = SettingsConfigDict(env_prefix="ragna_ui_")

url: str = "http://127.0.0.1:31477"
# FIXME: this needs to be dynamic for the url
Expand All @@ -79,8 +78,7 @@ class Config(ConfigBase):
class Config(BaseSettings):
"""Ragna configuration"""

class Config(ConfigBase):
env_prefix = "ragna_"
model_config = SettingsConfigDict(env_prefix="ragna_")

local_cache_root: Path = Field(
default_factory=lambda: Path.home() / ".cache" / "ragna"
Expand All @@ -97,11 +95,8 @@ def _resolve_and_make_path(cls, path: Path) -> Path:
api: ApiConfig = Field(default_factory=ApiConfig)
ui: UiConfig = Field(default_factory=UiConfig)

# We need the awkward ragna.Config return annotation, because it otherwise uses the
# Config class we have defined above. Since that needs to be removed for
# pydantic==3, we can cleanup the annotation at the same time
@classmethod
def from_file(cls, path: Union[str, Path]) -> ragna.Config:
def from_file(cls, path: Union[str, Path]) -> Config:
path = Path(path).expanduser().resolve()
if not path.is_file():
raise RagnaException(f"{path} does not exist.")
Expand Down
Loading