11from collections import defaultdict
22from typing import Any , Dict , List , Optional , Type , Union
33
4- try :
5- from pydantic .v1 import BaseModel , Field , StrictStr , ValidationError , root_validator
6- except ImportError :
7- from pydantic import BaseModel , Field , StrictStr , ValidationError , root_validator # type: ignore
8-
4+ from pydantic import BaseModel , ConfigDict , Field , StrictStr , ValidationError , model_validator
95from wasabi import msg
106
117
@@ -43,15 +39,15 @@ class ProjectConfigAssetURL(BaseModel):
4339 # fmt: off
4440 dest : StrictStr = Field (..., title = "Destination of downloaded asset" )
4541 url : Optional [StrictStr ] = Field (None , title = "URL of asset" )
46- checksum : Optional [str ] = Field (None , title = "MD5 hash of file" , regex = r"([a-fA-F\d]{32})" )
42+ checksum : Optional [str ] = Field (None , title = "MD5 hash of file" , pattern = r"([a-fA-F\d]{32})" )
4743 description : StrictStr = Field ("" , title = "Description of asset" )
4844 # fmt: on
4945
5046
5147class ProjectConfigAssetGit (BaseModel ):
5248 # fmt: off
5349 git : ProjectConfigAssetGitItem = Field (..., title = "Git repo information" )
54- checksum : Optional [str ] = Field (None , title = "MD5 hash of file" , regex = r"([a-fA-F\d]{32})" )
50+ checksum : Optional [str ] = Field (None , title = "MD5 hash of file" , pattern = r"([a-fA-F\d]{32})" )
5551 description : Optional [StrictStr ] = Field (None , title = "Description of asset" )
5652 # fmt: on
5753
@@ -67,9 +63,10 @@ class ProjectConfigCommand(BaseModel):
6763 no_skip : bool = Field (False , title = "Never skip this command, even if nothing changed" )
6864 # fmt: on
6965
70- class Config :
71- title = "A single named command specified in a project config"
72- extra = "forbid"
66+ model_config = ConfigDict (
67+ title = "A single named command specified in a project config" ,
68+ extra = "forbid" ,
69+ )
7370
7471
7572class ProjectConfigSchema (BaseModel ):
@@ -82,10 +79,10 @@ class ProjectConfigSchema(BaseModel):
8279 title : Optional [str ] = Field (None , title = "Project title" )
8380 # fmt: on
8481
85- class Config :
86- title = "Schema for project configuration file"
82+ model_config = ConfigDict (title = "Schema for project configuration file" )
8783
88- @root_validator (pre = True )
84+ @model_validator (mode = "before" )
85+ @classmethod
8986 def check_legacy_keys (cls , obj : Dict [str , Any ]) -> Dict [str , Any ]:
9087 if "spacy_version" in obj :
9188 msg .warn (
0 commit comments