Skip to content

Commit

Permalink
Replace dataclasses with pydantic v2 models
Browse files Browse the repository at this point in the history
  • Loading branch information
littleK0i committed Oct 10, 2023
1 parent ddbacdc commit 707b63c
Show file tree
Hide file tree
Showing 15 changed files with 243 additions and 298 deletions.
11 changes: 6 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@ classifiers =
Operating System :: OS Independent
Intended Audience :: Developers
Topic :: Database
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12

[options]
packages = find:

python_requires = >=3.7
python_requires = >=3.8
install_requires =
snowflake-connector-python
pyyaml
jsonschema
jsonschema~=4.18
pydantic~=2.4
pyyaml~=6.0
snowflake-connector-python~=3.0

[options.extras_require]
dev =
Expand Down
12 changes: 6 additions & 6 deletions snowddl/app/singledb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from argparse import ArgumentParser, HelpFormatter
from dataclasses import fields, is_dataclass
from os import environ, getcwd
from pydantic import BaseModel
from typing import Optional

from snowddl.app.base import BaseApp
Expand Down Expand Up @@ -114,15 +114,15 @@ def convert_config(self, original_config: SnowDDLConfig):
return singledb_config

def convert_blueprint(self, bp: AbstractBlueprint):
for f in fields(bp):
self.convert_object_recursive(getattr(bp, f.name))
for field_name, field_value in bp:
self.convert_object_recursive(getattr(bp, field_name))

return bp

def convert_object_recursive(self, obj):
if is_dataclass(obj):
for f in fields(obj):
self.convert_object_recursive(getattr(obj, f.name))
if isinstance(obj, BaseModel):
for field_name, field_value in obj:
self.convert_object_recursive(getattr(obj, field_name))

if isinstance(obj, list):
for item in obj:
Expand Down
Loading

0 comments on commit 707b63c

Please sign in to comment.