Skip to content

Commit

Permalink
feat: upugrade to pydantic v2
Browse files Browse the repository at this point in the history
Signed-off-by: Stefano Cappa <[email protected]>
  • Loading branch information
Ks89 committed Dec 4, 2023
1 parent c90fc59 commit 01e0375
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
argparse==1.4.0
jinja2==3.1.2
pydantic==1.10.2
pyyaml==6.0
pydantic==2.5.2
pyyaml==6.0.1
5 changes: 3 additions & 2 deletions src/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import yaml
from jinja2 import Environment, FileSystemLoader, select_autoescape, StrictUndefined
from pydantic import parse_obj_as
from pydantic import TypeAdapter

from src.models.secrets import Secrets

Expand Down Expand Up @@ -56,7 +56,8 @@ def main() -> None:
def parse_yaml_as_obj(path: Path) -> Secrets:
with open(path, 'r') as stream:
try:
return parse_obj_as(Secrets, yaml.safe_load(stream))
adapter = TypeAdapter(Secrets)
return adapter.validate_python(yaml.safe_load(stream))
except yaml.YAMLError as err:
print(err)

Expand Down
2 changes: 1 addition & 1 deletion src/models/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Secrets(BaseModel):
server_path: str = '/api/register'

mqtt_domain: str
mqtt_port: str = 8883
mqtt_port: int = 8883
mqtt_auth: bool = True
mqtt_username: str
mqtt_password: str

0 comments on commit 01e0375

Please sign in to comment.