Skip to content

Commit

Permalink
Updating to pydantic v2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark committed Nov 13, 2023
1 parent 1733cc3 commit 6ecc4d9
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 110 deletions.
4 changes: 1 addition & 3 deletions integration_tests/setup_test_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import boto3

from integration_tests.s3_utils import (
build_bucket,
)
from integration_tests.s3_utils import build_bucket


def build(
Expand Down
235 changes: 145 additions & 90 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
Expand Up @@ -16,7 +16,7 @@ navigator-data-ingest = 'navigator_data_ingest.main:main'
python = "^3.9"
click = "^8.1.2"
cloudpathlib = { version = "^0.10.0", extras = ["s3"] }
pydantic = "^1.9"
pydantic = "^2.4.0"
python-slugify = "^6.1.2"
python-dateutil = "^2.8.2"
python-dotenv = "^0.19.2"
Expand All @@ -26,7 +26,7 @@ json-logging = "^1.3.0"
pytest = "^7.2.1"
moto = {extras = ["all", "ec2", "s3"], version = "^4.1.6"}
pytest-asyncio = "^0.21.0"
cpr-data-access = {git = "https://github.com/climatepolicyradar/data-access.git", tag = "v0.1.9"}
cpr-data-access = {git = "https://github.com/climatepolicyradar/data-access.git", tag = "0.4.0"}

[tool.poetry.dev-dependencies]
black = "^22.1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/navigator_data_ingest/base/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def write_parser_input(
output_location / f"{parser_input.document_id}.json",
)
with output_file_location.open("w") as output_file:
output_file.write(json.dumps(parser_input.to_json(), indent=2))
output_file.write(parser_input.model_dump_json(indent=2))


@retry(
Expand Down
10 changes: 0 additions & 10 deletions src/navigator_data_ingest/base/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from datetime import datetime
from enum import Enum
from typing import (
Any,
Generator,
Mapping,
Optional,
Callable,
)
Expand Down Expand Up @@ -58,14 +56,6 @@ class Event(BaseModel): # noqa: D101
description: str
created_ts: datetime

def to_json(self) -> Mapping[str, Any]:
"""Output a JSON serialising friendly dict representing this model"""
return {
"name": self.name,
"description": self.description,
"created_ts": self.created_ts.isoformat(),
}


PipelineFieldMapping = {
UpdateTypes.NAME: "document_name",
Expand Down
2 changes: 1 addition & 1 deletion src/navigator_data_ingest/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, input_file: S3Path, output_location_path: S3Path):
"""Initialize the generator."""
_LOGGER.info("Initializing LawPolicyGenerator")
json_data = read_s3_json_file(input_file)
self.input_data = PipelineUpdates.parse_obj(json_data)
self.input_data = PipelineUpdates.model_validate(json_data)
self.output_location_path = output_location_path

def process_new_documents(self) -> Generator[BackendDocument, None, None]:
Expand Down
5 changes: 2 additions & 3 deletions src/navigator_data_ingest/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import logging
import logging.config
import os
Expand Down Expand Up @@ -148,8 +147,8 @@ def main(
)

input_dir_path = S3Path(
ExecutionData.parse_obj(
json.loads(execution_data_path.read_text())
ExecutionData.model_validate_json(
execution_data_path.read_text()
).input_dir_path
)

Expand Down

0 comments on commit 6ecc4d9

Please sign in to comment.