16
16
from bumpversion .scm import SCMInfo
17
17
from bumpversion .version_part import VersionConfig
18
18
19
- from pydantic import BaseModel , BaseSettings , Field
19
+ from pydantic import BaseModel , Field
20
+ from pydantic_settings import BaseSettings , SettingsConfigDict
20
21
21
22
from bumpversion .exceptions import ConfigurationError
22
23
26
27
class VersionPartConfig (BaseModel ):
27
28
"""Configuration of a part of the version."""
28
29
29
- values : Optional [list ] # Optional. Numeric is used if missing or no items in list
30
- optional_value : Optional [str ] # Optional.
30
+ values : Optional [list ] = None # Optional. Numeric is used if missing or no items in list
31
+ optional_value : Optional [str ] = None # Optional.
31
32
# Defaults to first value. 0 in the case of numeric. Empty string means nothing is optional.
32
- first_value : Optional [str ] # Optional. Defaults to first value in values
33
+ first_value : Union [str , int , None ] = None # Optional. Defaults to first value in values
33
34
independent : bool = False
34
35
35
36
36
37
class FileConfig (BaseModel ):
37
38
"""Search and replace file config."""
38
39
39
- filename : Optional [str ]
40
- glob : Optional [str ] # Conflicts with filename. If both are specified, glob wins
41
- parse : Optional [str ] # If different from outer scope
42
- serialize : Optional [List [str ]] # If different from outer scope
43
- search : Optional [str ] # If different from outer scope
44
- replace : Optional [str ] # If different from outer scope
45
- no_regex : Optional [bool ] # If different from outer scope
46
- ignore_missing_version : Optional [bool ]
40
+ filename : Optional [str ] = None
41
+ glob : Optional [str ] = None # Conflicts with filename. If both are specified, glob wins
42
+ parse : Optional [str ] = None # If different from outer scope
43
+ serialize : Optional [List [str ]] = None # If different from outer scope
44
+ search : Optional [str ] = None # If different from outer scope
45
+ replace : Optional [str ] = None # If different from outer scope
46
+ no_regex : Optional [bool ] = None # If different from outer scope
47
+ ignore_missing_version : Optional [bool ] = None
47
48
48
49
49
50
class Config (BaseSettings ):
50
51
"""Bump Version configuration."""
51
52
52
53
current_version : Optional [str ]
53
54
parse : str
54
- serialize : List [str ] = Field (min_items = 1 )
55
+ serialize : List [str ] = Field (min_length = 1 )
55
56
search : str
56
57
replace : str
57
58
no_regex : bool
@@ -67,11 +68,9 @@ class Config(BaseSettings):
67
68
scm_info : Optional ["SCMInfo" ]
68
69
parts : Dict [str , VersionPartConfig ]
69
70
files : List [FileConfig ]
70
- included_paths : List [str ] = []
71
- excluded_paths : List [str ] = []
72
-
73
- class Config :
74
- env_prefix = "bumpversion_"
71
+ included_paths : List [str ] = Field (default_factory = list )
72
+ excluded_paths : List [str ] = Field (default_factory = list )
73
+ model_config = SettingsConfigDict (env_prefix = "bumpversion_" )
75
74
76
75
def add_files (self , filename : Union [str , List [str ]]) -> None :
77
76
"""Add a filename to the list of files."""
@@ -177,7 +176,7 @@ def get_configuration(config_file: Union[str, Path, None] = None, **overrides) -
177
176
Returns:
178
177
The configuration
179
178
"""
180
- from bumpversion .scm import SCMInfo , get_scm_info
179
+ from bumpversion .scm import SCMInfo , SourceCodeManager , get_scm_info # noqa: F401
181
180
182
181
config_dict = DEFAULTS .copy ()
183
182
parsed_config = read_config_file (config_file ) if config_file else {}
@@ -195,7 +194,7 @@ def get_configuration(config_file: Union[str, Path, None] = None, **overrides) -
195
194
config_dict ["files" ] = get_all_file_configs (config_dict )
196
195
197
196
# Resolve the SCMInfo class for Pydantic's BaseSettings
198
- Config .update_forward_refs ( SCMInfo = SCMInfo )
197
+ Config .model_rebuild ( )
199
198
config = Config (** config_dict ) # type: ignore[arg-type]
200
199
201
200
# Get the information about the SCM
0 commit comments