Skip to content

Commit

Permalink
Added ignore-missing-version configuration
Browse files Browse the repository at this point in the history
- Defaults to `False`
- File configurations can also override this value
  • Loading branch information
coordt committed Jul 13, 2023
1 parent 733438b commit 45c85be
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions bumpversion/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class FileConfig(BaseModel):
serialize: Optional[List[str]] # If different from outer scope
search: Optional[str] # If different from outer scope
replace: Optional[str] # If different from outer scope
ignore_missing_version: Optional[bool]


class Config(BaseSettings):
Expand All @@ -50,6 +51,7 @@ class Config(BaseSettings):
serialize: List[str] = Field(min_items=1)
search: str
replace: str
ignore_missing_version: bool
tag: bool
sign_tags: bool
tag_name: str
Expand Down Expand Up @@ -84,6 +86,7 @@ def version_config(self) -> "VersionConfig":
"serialize": ["{major}.{minor}.{patch}"],
"search": "{current_version}",
"replace": "{new_version}",
"ignore_missing_version": False,
"tag": False,
"sign_tags": False,
"tag_name": "v{new_version}",
Expand All @@ -105,6 +108,21 @@ def version_config(self) -> "VersionConfig":
)


def get_all_file_configs(config_dict: dict) -> List[FileConfig]:
"""Make sure all version parts are included."""
defaults = {
"parse": config_dict["parse"],
"serialize": config_dict["serialize"],
"search": config_dict["search"],
"replace": config_dict["replace"],
"ignore_missing_version": config_dict["ignore_missing_version"],
}
files = [{k: v for k, v in filecfg.items() if v} for filecfg in config_dict["files"]]
for f in files:
f.update({k: v for k, v in defaults.items() if k not in f})
return [FileConfig(**f) for f in files]


def get_configuration(config_file: Union[str, Path, None] = None, **overrides) -> Config:
"""
Return the configuration based on any configuration files and overrides.
Expand All @@ -129,6 +147,11 @@ def get_configuration(config_file: Union[str, Path, None] = None, **overrides) -

# Set any missing version parts
config_dict["parts"] = get_all_part_configs(config_dict)

# Set any missing file configuration
config_dict["files"] = get_all_file_configs(config_dict)

# Resolve the SCMInfo class for Pydantic's BaseSettings
Config.update_forward_refs(SCMInfo=SCMInfo)
config = Config(**config_dict) # type: ignore[arg-type]

Expand Down

0 comments on commit 45c85be

Please sign in to comment.