Skip to content

Commit 45c85be

Browse files
committed
Added ignore-missing-version configuration
- Defaults to `False` - File configurations can also override this value
1 parent 733438b commit 45c85be

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

bumpversion/config.py

+23
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class FileConfig(BaseModel):
4040
serialize: Optional[List[str]] # If different from outer scope
4141
search: Optional[str] # If different from outer scope
4242
replace: Optional[str] # If different from outer scope
43+
ignore_missing_version: Optional[bool]
4344

4445

4546
class Config(BaseSettings):
@@ -50,6 +51,7 @@ class Config(BaseSettings):
5051
serialize: List[str] = Field(min_items=1)
5152
search: str
5253
replace: str
54+
ignore_missing_version: bool
5355
tag: bool
5456
sign_tags: bool
5557
tag_name: str
@@ -84,6 +86,7 @@ def version_config(self) -> "VersionConfig":
8486
"serialize": ["{major}.{minor}.{patch}"],
8587
"search": "{current_version}",
8688
"replace": "{new_version}",
89+
"ignore_missing_version": False,
8790
"tag": False,
8891
"sign_tags": False,
8992
"tag_name": "v{new_version}",
@@ -105,6 +108,21 @@ def version_config(self) -> "VersionConfig":
105108
)
106109

107110

111+
def get_all_file_configs(config_dict: dict) -> List[FileConfig]:
112+
"""Make sure all version parts are included."""
113+
defaults = {
114+
"parse": config_dict["parse"],
115+
"serialize": config_dict["serialize"],
116+
"search": config_dict["search"],
117+
"replace": config_dict["replace"],
118+
"ignore_missing_version": config_dict["ignore_missing_version"],
119+
}
120+
files = [{k: v for k, v in filecfg.items() if v} for filecfg in config_dict["files"]]
121+
for f in files:
122+
f.update({k: v for k, v in defaults.items() if k not in f})
123+
return [FileConfig(**f) for f in files]
124+
125+
108126
def get_configuration(config_file: Union[str, Path, None] = None, **overrides) -> Config:
109127
"""
110128
Return the configuration based on any configuration files and overrides.
@@ -129,6 +147,11 @@ def get_configuration(config_file: Union[str, Path, None] = None, **overrides) -
129147

130148
# Set any missing version parts
131149
config_dict["parts"] = get_all_part_configs(config_dict)
150+
151+
# Set any missing file configuration
152+
config_dict["files"] = get_all_file_configs(config_dict)
153+
154+
# Resolve the SCMInfo class for Pydantic's BaseSettings
132155
Config.update_forward_refs(SCMInfo=SCMInfo)
133156
config = Config(**config_dict) # type: ignore[arg-type]
134157

0 commit comments

Comments
 (0)