Skip to content

Commit

Permalink
0.9 (#67)
Browse files Browse the repository at this point in the history
* 0.9 branch

* Bump minimum python version to 3.8 (#65)

* 63 update pydantic to v2 (#66)

* Upgrade to Pydantic V2 + upgrades to dev dependencies

* Updated urllib
  • Loading branch information
natsunlee committed Mar 5, 2024
1 parent 606de8c commit 70fff20
Show file tree
Hide file tree
Showing 11 changed files with 345 additions and 356 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[bumpversion]
current_version = 0.8.2
current_version = 0.9.0
files = flowmancer/version.py pyproject.toml
6 changes: 2 additions & 4 deletions flowmancer/checkpointer/checkpointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dataclasses import dataclass
from typing import Any, Dict, Set

from pydantic import BaseModel, Extra
from pydantic import BaseModel, ConfigDict

from ..lifecycle import AsyncLifecycle

Expand All @@ -30,9 +30,7 @@ class CheckpointContents:


class Checkpointer(ABC, BaseModel, AsyncLifecycle):
class Config:
extra = Extra.forbid
underscore_attrs_are_private = True
model_config = ConfigDict(extra='forbid', use_enum_values=True)

@abstractmethod
async def write_checkpoint(self, name: str, content: CheckpointContents) -> None:
Expand Down
9 changes: 3 additions & 6 deletions flowmancer/eventbus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from queue import Queue
from typing import Any, Dict, Generic, Optional, Type, TypeVar

from pydantic import BaseModel, Extra
from pydantic import BaseModel, ConfigDict

_event_classes: Dict[str, Dict[str, Type[SerializableEvent]]] = defaultdict(dict)

Expand All @@ -20,10 +20,7 @@ class NotADeserializableEventError(Exception):


class SerializableEvent(BaseModel, ABC):
class Config:
extra = Extra.forbid
underscore_attrs_are_private = True
use_enum_values = True
model_config = ConfigDict(extra='forbid', use_enum_values=True)

@classmethod
@abstractmethod
Expand All @@ -32,7 +29,7 @@ def event_group(cls) -> str:

def serialize(self) -> str:
try:
return json.dumps({'group': self.event_group(), 'event': type(self).__name__, 'body': self.dict()})
return json.dumps({'group': self.event_group(), 'event': type(self).__name__, 'body': self.model_dump()})
except Exception as e:
raise NotASerializableEventError(str(e))

Expand Down
7 changes: 2 additions & 5 deletions flowmancer/extensions/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from abc import ABC, abstractmethod

from pydantic import BaseModel, Extra
from pydantic import BaseModel, ConfigDict

from ..executor import SerializableExecutionEvent
from ..lifecycle import AsyncLifecycle
Expand All @@ -18,10 +18,7 @@ def extension(t: type[Extension]):


class Extension(ABC, AsyncLifecycle, BaseModel):
class Config:
extra = Extra.forbid
underscore_attrs_are_private = True
use_enum_values = True
model_config = ConfigDict(extra='forbid', use_enum_values=True)

@abstractmethod
async def update(self, e: SerializableExecutionEvent) -> None:
Expand Down
11 changes: 3 additions & 8 deletions flowmancer/jobdefinition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path
from typing import Any, Callable, Dict, List, Type, Union

from pydantic import BaseModel, Extra
from pydantic import BaseModel, ConfigDict

_job_definition_classes = dict()

Expand All @@ -19,10 +19,7 @@ def inner(t: type[SerializableJobDefinition]) -> Type[SerializableJobDefinition]


class JobDefinitionComponent(BaseModel):
class Config:
extra = Extra.forbid
underscore_attrs_are_private = True
use_enum_values = True
model_config = ConfigDict(extra='forbid', use_enum_values=True)


class LoggerDefinition(JobDefinitionComponent):
Expand Down Expand Up @@ -70,11 +67,9 @@ class JobDefinition(JobDefinitionComponent):


class LoadParams(BaseModel):
model_config = ConfigDict(extra='forbid', use_enum_values=True)
APP_ROOT_DIR: str = '.'

class Config:
extra = Extra.forbid


class SerializableJobDefinition(ABC):
@abstractmethod
Expand Down
2 changes: 1 addition & 1 deletion flowmancer/jobdefinition/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ def process_includes(jdef, merged, seen):

def dump(self, jdef: JobDefinition, filename: Union[Path, str]) -> None:
with open(filename, 'r') as f:
f.write(yaml.dump(jdef.dict()))
f.write(yaml.dump(jdef.model_dump()))
7 changes: 2 additions & 5 deletions flowmancer/loggers/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from abc import ABC, abstractmethod
from typing import Any

from pydantic import BaseModel, Extra
from pydantic import BaseModel, ConfigDict

from ..eventbus.log import SerializableLogEvent
from ..lifecycle import AsyncLifecycle
Expand All @@ -19,10 +19,7 @@ def logger(t: type[Logger]) -> Any:


class Logger(ABC, AsyncLifecycle, BaseModel):
class Config:
extra = Extra.forbid
underscore_attrs_are_private = True
use_enum_values = True
model_config = ConfigDict(extra='forbid', use_enum_values=True)

@abstractmethod
async def update(self, m: SerializableLogEvent) -> None:
Expand Down
8 changes: 2 additions & 6 deletions flowmancer/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from abc import ABC, abstractmethod
from typing import Any, Dict

from pydantic import BaseModel, Extra
from pydantic import BaseModel, ConfigDict

from .lifecycle import Lifecycle

Expand All @@ -18,17 +18,13 @@ def task(t: type[Task]):


class Task(ABC, BaseModel, Lifecycle):
model_config = ConfigDict(extra='forbid', use_enum_values=True)
_shared_dict: Dict[str, Any] = dict()

@property
def shared_dict(self) -> Dict[str, Any]:
return self._shared_dict

class Config:
extra = Extra.forbid
underscore_attrs_are_private = True
use_enum_values = True

@abstractmethod
def run(self) -> None:
pass
2 changes: 1 addition & 1 deletion flowmancer/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.8.2"
__version__ = "0.9.0"
Loading

0 comments on commit 70fff20

Please sign in to comment.