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

Set implementation version in config by default #385

Merged
merged 2 commits into from
Jul 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion optimade/server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
from typing_extensions import Literal
from pathlib import Path

from pydantic import BaseSettings, Field, root_validator, AnyHttpUrl
from pydantic import ( # pylint: disable=no-name-in-module
BaseSettings,
Field,
root_validator,
AnyHttpUrl,
validator,
)

from optimade import __version__
from optimade.models import Implementation, Provider
Expand Down Expand Up @@ -113,6 +119,13 @@ class ServerConfig(BaseSettings):
description="Absolute path to a JSON file containing the MongoDB collection of /links resources for the index meta-database",
)

@validator("implementation", pre=True)
def set_implementation_version(cls, v):
"""Set defaults and modify by passed value(s)"""
res = {"version": __version__}
res.update(v)
return res

@root_validator(pre=True)
def load_default_settings(cls, values): # pylint: disable=no-self-argument
"""
Expand Down