Skip to content

Commit

Permalink
chore: remove warnings from pydantic v2 (#183)
Browse files Browse the repository at this point in the history
Signed-off-by: ThibaultFy <[email protected]>
  • Loading branch information
ThibaultFy authored Oct 30, 2023
1 parent ec8628e commit 325a43f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## \[Unreleased\]

### Fixed

- Update schemas and tests to remove Pydantic v2 warnings ([#183](https://github.com/Substra/substrafl/pull/183))

## [0.42.0](https://github.com/Substra/substrafl/releases/tag/0.42.0) - 2023-10-18

### Added
Expand Down
11 changes: 5 additions & 6 deletions substrafl/dependency/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
import substra
import substratools
from pydantic import BaseModel
from pydantic import ConfigDict
from pydantic import Field
from pydantic import validator
from pydantic import field_validator

import substrafl
from substrafl import exceptions
Expand Down Expand Up @@ -67,9 +68,7 @@ class Dependency(BaseModel):
_wheels: List[Path] = []
_local_paths: List[Path] = []
_cache_directory: Optional[Path] = None

class Config:
arbitrary_types_allowed = True
model_config = ConfigDict(arbitrary_types_allowed=True)

def __init__(self, *args, **kwargs):
"""Dependencies are computed at object initialization.
Expand All @@ -83,7 +82,7 @@ def __del__(self):
"""Delete the cache directory."""
self._delete_cache_directory()

@validator("local_installable_dependencies", "local_code")
@field_validator("local_installable_dependencies", "local_code")
def resolve_path(cls, v): # noqa: N805
"""Resolve list of local code paths and check if they exist."""
not_existing_paths = list()
Expand All @@ -101,7 +100,7 @@ def resolve_path(cls, v): # noqa: N805

return resolved_paths

@validator("local_installable_dependencies")
@field_validator("local_installable_dependencies")
def check_setup(cls, v): # noqa: N805
"""Check the presence of a setup.py file or a pyproject.toml in the provided paths."""
not_installable = list()
Expand Down
4 changes: 2 additions & 2 deletions substrafl/nodes/train_data_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def init_states(
},
tag=TaskType.INITIALIZATION,
worker=self.organization_id,
).dict()
).model_dump()

init_task.pop("function_key")
init_task["remote_operation"] = operation.remote_struct
Expand Down Expand Up @@ -181,7 +181,7 @@ def update_states(
metadata=task_metadata,
tag=TaskType.TRAIN,
worker=self.organization_id,
).dict()
).model_dump()

train_task.pop("function_key")
train_task["remote_operation"] = operation.remote_struct
Expand Down
3 changes: 1 addition & 2 deletions substrafl/strategies/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class StrategyName(str, Enum):
class _Model(pydantic.BaseModel):
"""Base model configuration"""

class Config:
arbitrary_types_allowed = True
model_config = pydantic.ConfigDict(arbitrary_types_allowed=True)


class FedAvgAveragedState(_Model):
Expand Down
10 changes: 5 additions & 5 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import substra
import yaml
from pydantic import BaseModel
from pydantic import validator
from pydantic import ConfigDict
from pydantic import field_validator

CURRENT_DIR = Path(__file__).parent

Expand Down Expand Up @@ -44,7 +45,7 @@ class Configuration(BaseModel):

organizations: List[OrganizationCfg]

@validator("organizations")
@field_validator("organizations")
def minimal_number_of_organizations(cls, v): # noqa: N805
assert len(v) >= MIN_ORGANIZATIONS, (
"Not enough organizations defined in your configuration. "
Expand All @@ -67,9 +68,8 @@ class Network(BaseModel):
clients: List[substra.sdk.client.Client]
msp_ids: Optional[List[str]] = None

class Config:
# Arbitrary type is used because substra Client is not pydantic compatible
arbitrary_types_allowed = True
# Arbitrary type is used because substra Client is not pydantic compatible
model_config = ConfigDict(arbitrary_types_allowed=True)

@property
def n_organizations(self) -> int:
Expand Down

0 comments on commit 325a43f

Please sign in to comment.