Skip to content

Commit

Permalink
feat: update pydantic to v2 (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
antheas authored Aug 5, 2024
1 parent 12c95e5 commit 8da8264
Show file tree
Hide file tree
Showing 8 changed files with 336 additions and 227 deletions.
511 changes: 311 additions & 200 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "yafti"
version = "0.8.0"
version = "0.9.0"
description = "Yet another first time installer"
authors = ["Marco Ceppi <marco@ceppi.net>"]
license = "Apache 2.0"
Expand All @@ -19,7 +19,7 @@ yafti = "yafti.__main__:app"

[tool.poetry.dependencies]
python = "^3.11"
pydantic = "1.10.2" # This needs to match the minimum supported version in Fedora
pydantic = "2.8.2"
pygobject = "^3.42.2"
pyyaml = "^6.0"
gbulb = "^0.6.4"
Expand Down
4 changes: 2 additions & 2 deletions yafti/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ def deactivate(self):


class YaftiPluginReturn(BaseModel):
output: Optional[str | list[str]]
errors: Optional[str | list[str]]
output: Optional[str | list[str]] = None
errors: Optional[str | list[str]] = None
code: int = 0
10 changes: 5 additions & 5 deletions yafti/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@


class ActionConfig(BaseModel):
pre: Optional[list[dict[str, str | dict]]]
post: Optional[list[dict[str, str | dict]]]
pre: Optional[list[dict[str, str | dict]]] = None
post: Optional[list[dict[str, str | dict]]] = None


class ScreenConfig(BaseModel):
source: str
values: Optional[dict]
values: Optional[dict] = None


class YaftiRunModes(str, Enum):
Expand All @@ -52,8 +52,8 @@ class YaftiProperties(BaseModel):
class Config(BaseModel):
title: str
properties: YaftiProperties = YaftiProperties()
actions: Optional[ActionConfig]
screens: Optional[dict[str, ScreenConfig]] # Screens are parsed per plugin
actions: Optional[ActionConfig] = None
screens: Optional[dict[str, ScreenConfig]] = None


def parse(config_file: str) -> Config:
Expand Down
4 changes: 2 additions & 2 deletions yafti/plugin/flatpak.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
import asyncio
from typing import Any, Optional

from pydantic import BaseModel, ValidationError, root_validator
from pydantic import BaseModel, ValidationError, field_validator

from yafti.abc import YaftiPluginReturn
from yafti.plugin.run import Run
Expand Down Expand Up @@ -104,7 +104,7 @@ class Scheme(BaseModel):
install: Optional[str | dict] = None
remove: Optional[str | dict] = None

@root_validator
@field_validator("install", "remove")
def must_have_atleast_one(cls, values):
"""Validate one, and only one, key is passed
Expand Down
4 changes: 2 additions & 2 deletions yafti/plugin/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from os.path import isfile
from shutil import which

from pydantic import validate_arguments
from pydantic import validate_call

from yafti import log
from yafti.abc import YaftiPlugin, YaftiPluginReturn
Expand Down Expand Up @@ -100,7 +100,7 @@ async def install(self, package: str) -> YaftiPluginReturn:
"""
return await self.exec(package)

@validate_arguments
@validate_call
async def __call__(self, cmd: list[str] | str) -> YaftiPluginReturn:
log.debug("run called", cmd=cmd)
if isinstance(cmd, list):
Expand Down
8 changes: 3 additions & 5 deletions yafti/screen/package/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from pydantic import BaseModel
from pydantic import RootModel, BaseModel


class PackageConfig(BaseModel):
__root__: dict[str, str | dict]
PackageConfig = RootModel[dict[str, str | dict]]


class PackageGroupConfigDetails(BaseModel):
Expand All @@ -11,5 +10,4 @@ class PackageGroupConfigDetails(BaseModel):
packages: list[PackageConfig]


class PackageGroupConfig(BaseModel):
__root__: dict[str, PackageGroupConfigDetails]
PackageGroupConfig = RootModel[dict[str, PackageGroupConfigDetails]]
18 changes: 9 additions & 9 deletions yafti/screen/package/state.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import validate_arguments
from pydantic import validate_call


class PackageScreenState:
Expand All @@ -14,33 +14,33 @@ def __new__(cls, id: str):
def __init__(self, id: str):
self.state = {}

@validate_arguments
@validate_call
def load(self, data: dict):
for k, v in data.items():
self.set(k, v)

@validate_arguments
@validate_call
def remove(self, item: str) -> None:
del self.state[item]

@validate_arguments
@validate_call
def on(self, item: str) -> None:
self.set(item, True)

@validate_arguments
@validate_call
def off(self, item: str) -> None:
self.set(item, False)

@validate_arguments
@validate_call
def toggle(self, item: str) -> bool:
self.state[item] = not self.state[item]
return self.get(item)

@validate_arguments
@validate_call
def set(self, item: str, state: bool) -> None:
self.state[item] = state

@validate_arguments
@validate_call
def get_on(self, prefix: str = "") -> list[str]:
return [
item
Expand All @@ -51,6 +51,6 @@ def get_on(self, prefix: str = "") -> list[str]:
def keys(self) -> list[str]:
return list(self.state.keys())

@validate_arguments
@validate_call
def get(self, item: str) -> bool:
return self.state.get(item)

0 comments on commit 8da8264

Please sign in to comment.