Skip to content

Commit

Permalink
Allow pydantic v1 by using some deprecated functions (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
joloppo authored May 9, 2024
1 parent b88454e commit 69a44a2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
10 changes: 5 additions & 5 deletions dynamicio/config/pydantic/io_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Mapping, Optional, Union

import pydantic
from pydantic import BaseModel, model_validator
from pydantic import BaseModel

import dynamicio.config.pydantic.table_schema as table_spec

Expand Down Expand Up @@ -93,7 +93,7 @@ def _preprocess_raw_config(cls, values):


class IOEnvironment(BaseModel):
"""A section specifiing an data source backed by a particular data backend."""
"""A section specifying an data source backed by a particular data backend."""

_parent: Optional[IOBinding] = None # noqa: F821
options: Mapping = pydantic.Field(default_factory=dict)
Expand Down Expand Up @@ -137,7 +137,7 @@ class LocalBatchDataSubSection(BaseModel):
dynamic_file_path: Optional[str] = None
file_type: FileType

@model_validator(mode="before")
@pydantic.root_validator(pre=True)
def check_path_fields(cls, values):
"""Check that only one of path_prefix or dynamic_file_path is provided & they meet format requirements."""
path_prefix = values.get("path_prefix")
Expand Down Expand Up @@ -188,7 +188,7 @@ class S3PathPrefixSubSection(BaseModel):
file_type: FileType
bucket: str

@model_validator(mode="before")
@pydantic.root_validator(pre=True)
def check_path_fields(cls, values):
"""Check that only one of path_prefix or dynamic_file_path is provided & they meet format requirements."""
path_prefix = values.get("path_prefix")
Expand Down Expand Up @@ -270,4 +270,4 @@ class PostgresDataEnvironment(IOEnvironment):
postgres: PostgresDataSubSection


IOBinding.model_rebuild()
IOBinding.update_forward_refs()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ no_implicit_optional==1.4.0
pandas>=1.2.4
psycopg2-binary~=2.9.3
pyarrow>=7.0.0
pydantic>=2.0,<3
pydantic>=1.9.2,<3
python-json-logger~=2.0.1
PyYAML>=5.4.1
s3fs==0.4.2
Expand Down
3 changes: 1 addition & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# pylint: disable=missing-module-docstring, missing-class-docstring, missing-function-docstring, R0801
import io
import json
import os

import pytest
Expand All @@ -21,7 +20,7 @@ def test_config_io_parser_returns_a_transformed_dict_version_of_the_yaml_input_w
)

# When
yaml_dict = json.loads(input_config.config.model_dump_json())
yaml_dict = input_config.config.dict()
# Then
assert yaml_dict == expected_input_yaml_dict

Expand Down

0 comments on commit 69a44a2

Please sign in to comment.