Skip to content

Commit 2df57cc

Browse files
committed
Refactor valid_bumps and invalid_bumps to include_bumps and exclude_bumps
The configuration parameters `valid_bumps` and `invalid_bumps` were renamed to `include_bumps` and `exclude_bumps` respectively. This new naming better denotes their function, and the changes were consistently applied across all related files and tests. Numerous fixture outputs were also updated to reflect these changes.
1 parent 7c801c0 commit 2df57cc

File tree

10 files changed

+78
-80
lines changed

10 files changed

+78
-80
lines changed

bumpversion/bump.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ def do_bump(
9898

9999
if version_part:
100100
# filter the files that are not valid for this bump
101-
configured_files = [file for file in configured_files if version_part in file.file_change.valid_bumps]
102-
configured_files = [file for file in configured_files if version_part not in file.file_change.invalid_bumps]
101+
configured_files = [file for file in configured_files if version_part in file.file_change.include_bumps]
102+
configured_files = [file for file in configured_files if version_part not in file.file_change.exclude_bumps]
103103

104104
modify_files(configured_files, version, next_version, ctx, dry_run)
105105
if config_file and config_file.suffix in {".cfg", ".ini"}:

bumpversion/config/models.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class FileChange(BaseModel):
3535
glob: Optional[str] = None # Conflicts with filename. If both are specified, glob wins
3636
glob_exclude: Optional[tuple] = None
3737
key_path: Optional[str] = None # If specified, and has an appropriate extension, will be treated as a data file
38-
valid_bumps: Optional[tuple] = None
39-
invalid_bumps: Optional[tuple] = None
38+
include_bumps: Optional[tuple] = None
39+
exclude_bumps: tuple = Field(default_factory=tuple)
4040

4141
def __hash__(self):
4242
"""Return a hash of the model."""
@@ -122,8 +122,7 @@ def add_files(self, filename: Union[str, List[str]]) -> None:
122122
regex=self.regex,
123123
ignore_missing_version=self.ignore_missing_version,
124124
ignore_missing_file=self.ignore_missing_files,
125-
valid_bumps=tuple(self.parts.keys()),
126-
invalid_bumps=(),
125+
include_bumps=tuple(self.parts.keys()),
127126
)
128127
)
129128
self.files = list(files)

bumpversion/config/utils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ def get_all_file_configs(config_dict: dict) -> List[FileChange]:
2222
"ignore_missing_version": config_dict["ignore_missing_version"],
2323
"ignore_missing_file": config_dict["ignore_missing_files"],
2424
"regex": config_dict["regex"],
25-
"valid_bumps": tuple(config_dict["parts"]),
26-
"invalid_bumps": (),
25+
"include_bumps": tuple(config_dict["parts"]),
2726
}
2827
files = [{k: v for k, v in filecfg.items() if v is not None} for filecfg in config_dict["files"]]
2928
for f in files:

bumpversion/files.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def __init__(
9090
filename=file_change.filename,
9191
glob=file_change.glob,
9292
key_path=file_change.key_path,
93-
valid_bumps=file_change.valid_bumps,
94-
invalid_bumps=file_change.invalid_bumps,
93+
include_bumps=file_change.include_bumps,
94+
exclude_bumps=file_change.exclude_bumps,
9595
)
9696
self.version_config = VersionConfig(
9797
self.file_change.parse,

docs/reference/configuration.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -723,24 +723,24 @@ If `True`, don't fail if the version string to be replaced is not found in the f
723723

724724
if `True`, don't fail if the configured file is missing.
725725

726-
### valid_bumps
726+
### include_bumps
727727

728728
::: field-list
729729

730730
required
731731
: No
732732

733733
default
734-
: all version parts
734+
: all version components
735735

736736
type
737737
: list of strings
738738

739-
The `valid_bumps` file configuration allows you to control when this file is changed. When a `bump <version component>` command is issued, this file is changed only if the version component is in this list and not in [`invalid_bumps`](#invalid_bumps). The [parse](#parse) configuration defines version components.
739+
The `include_bumps` file configuration allows you to control when this file is changed by inclusion. Its alternative is the `exclude_bumps` configuration. When a `bump <version component>` command is issued, this file is changed only if the version component is in this list and not in [`exclude_bumps`](#exclude_bumps). The [parse](#parse) configuration defines version components.
740740

741-
The default value, or an empty list, includes all version components.
741+
The default value, or an empty list, includes all version components.
742742

743-
### invalid_bumps
743+
### exclude_bumps
744744

745745
::: field-list
746746

@@ -753,7 +753,7 @@ The default value, or an empty list, includes all version components.
753753
type
754754
: list of strings
755755

756-
The `invalid_bumps` file configuration allows you to control when this file is changed by exclusion. When a `bump <version component>` command is issued, this file is only changed if the version component is *not in this list.* The [parse](#parse) configuration defines version components.
756+
The `exclude_bumps` file configuration allows you to control when this file is changed by exclusion. Its alternative is the `include_bumps` configuration.When a `bump <version component>` command is issued, this file is only changed if the version component is *not in this list.* The [parse](#parse) configuration defines version components.
757757

758758
The default value does not exclude anything.
759759

tests/fixtures/basic_cfg_expected.txt

+12-12
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,48 @@
33
'commit_args': None,
44
'current_version': '1.0.0',
55
'excluded_paths': [],
6-
'files': [{'filename': 'setup.py',
6+
'files': [{'exclude_bumps': (),
7+
'filename': 'setup.py',
78
'glob': None,
89
'glob_exclude': None,
910
'ignore_missing_file': False,
1011
'ignore_missing_version': False,
11-
'invalid_bumps': (),
12+
'include_bumps': ('major', 'minor', 'patch', 'release'),
1213
'key_path': None,
1314
'parse': '(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\-(?P<release>[a-z]+))?',
1415
'regex': False,
1516
'replace': '{new_version}',
1617
'search': '{current_version}',
1718
'serialize': ('{major}.{minor}.{patch}-{release}',
18-
'{major}.{minor}.{patch}'),
19-
'valid_bumps': ('major', 'minor', 'patch', 'release')},
20-
{'filename': 'bumpversion/__init__.py',
19+
'{major}.{minor}.{patch}')},
20+
{'exclude_bumps': (),
21+
'filename': 'bumpversion/__init__.py',
2122
'glob': None,
2223
'glob_exclude': None,
2324
'ignore_missing_file': False,
2425
'ignore_missing_version': False,
25-
'invalid_bumps': (),
26+
'include_bumps': ('major', 'minor', 'patch', 'release'),
2627
'key_path': None,
2728
'parse': '(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\-(?P<release>[a-z]+))?',
2829
'regex': False,
2930
'replace': '{new_version}',
3031
'search': '{current_version}',
3132
'serialize': ('{major}.{minor}.{patch}-{release}',
32-
'{major}.{minor}.{patch}'),
33-
'valid_bumps': ('major', 'minor', 'patch', 'release')},
34-
{'filename': 'CHANGELOG.md',
33+
'{major}.{minor}.{patch}')},
34+
{'exclude_bumps': (),
35+
'filename': 'CHANGELOG.md',
3536
'glob': None,
3637
'glob_exclude': None,
3738
'ignore_missing_file': False,
3839
'ignore_missing_version': False,
39-
'invalid_bumps': (),
40+
'include_bumps': ('major', 'minor', 'patch', 'release'),
4041
'key_path': None,
4142
'parse': '(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\-(?P<release>[a-z]+))?',
4243
'regex': False,
4344
'replace': '**unreleased**\n**v{new_version}**',
4445
'search': '**unreleased**',
4546
'serialize': ('{major}.{minor}.{patch}-{release}',
46-
'{major}.{minor}.{patch}'),
47-
'valid_bumps': ('major', 'minor', 'patch', 'release')}],
47+
'{major}.{minor}.{patch}')}],
4848
'ignore_missing_files': False,
4949
'ignore_missing_version': False,
5050
'included_paths': [],

tests/fixtures/basic_cfg_expected.yaml

+24-24
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ current_version: "1.0.0"
55
excluded_paths:
66

77
files:
8-
- filename: "setup.py"
8+
- exclude_bumps:
9+
10+
filename: "setup.py"
911
glob: null
1012
glob_exclude: null
1113
ignore_missing_file: false
1214
ignore_missing_version: false
13-
invalid_bumps:
14-
15+
include_bumps:
16+
- "major"
17+
- "minor"
18+
- "patch"
19+
- "release"
1520
key_path: null
1621
parse: "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\-(?P<release>[a-z]+))?"
1722
regex: false
@@ -20,18 +25,18 @@ files:
2025
serialize:
2126
- "{major}.{minor}.{patch}-{release}"
2227
- "{major}.{minor}.{patch}"
23-
valid_bumps:
24-
- "major"
25-
- "minor"
26-
- "patch"
27-
- "release"
28-
- filename: "bumpversion/__init__.py"
28+
- exclude_bumps:
29+
30+
filename: "bumpversion/__init__.py"
2931
glob: null
3032
glob_exclude: null
3133
ignore_missing_file: false
3234
ignore_missing_version: false
33-
invalid_bumps:
34-
35+
include_bumps:
36+
- "major"
37+
- "minor"
38+
- "patch"
39+
- "release"
3540
key_path: null
3641
parse: "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\-(?P<release>[a-z]+))?"
3742
regex: false
@@ -40,18 +45,18 @@ files:
4045
serialize:
4146
- "{major}.{minor}.{patch}-{release}"
4247
- "{major}.{minor}.{patch}"
43-
valid_bumps:
44-
- "major"
45-
- "minor"
46-
- "patch"
47-
- "release"
48-
- filename: "CHANGELOG.md"
48+
- exclude_bumps:
49+
50+
filename: "CHANGELOG.md"
4951
glob: null
5052
glob_exclude: null
5153
ignore_missing_file: false
5254
ignore_missing_version: false
53-
invalid_bumps:
54-
55+
include_bumps:
56+
- "major"
57+
- "minor"
58+
- "patch"
59+
- "release"
5560
key_path: null
5661
parse: "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\-(?P<release>[a-z]+))?"
5762
regex: false
@@ -60,11 +65,6 @@ files:
6065
serialize:
6166
- "{major}.{minor}.{patch}-{release}"
6267
- "{major}.{minor}.{patch}"
63-
valid_bumps:
64-
- "major"
65-
- "minor"
66-
- "patch"
67-
- "release"
6868
ignore_missing_files: false
6969
ignore_missing_version: false
7070
included_paths:

tests/fixtures/basic_cfg_expected_full.json

+21-21
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66
"excluded_paths": [],
77
"files": [
88
{
9+
"exclude_bumps": [],
910
"filename": "setup.py",
1011
"glob": null,
1112
"glob_exclude": null,
1213
"ignore_missing_file": false,
1314
"ignore_missing_version": false,
14-
"invalid_bumps": [],
15+
"include_bumps": [
16+
"major",
17+
"minor",
18+
"patch",
19+
"release"
20+
],
1521
"key_path": null,
1622
"parse": "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\-(?P<release>[a-z]+))?",
1723
"regex": false,
@@ -20,21 +26,21 @@
2026
"serialize": [
2127
"{major}.{minor}.{patch}-{release}",
2228
"{major}.{minor}.{patch}"
23-
],
24-
"valid_bumps": [
25-
"major",
26-
"minor",
27-
"patch",
28-
"release"
2929
]
3030
},
3131
{
32+
"exclude_bumps": [],
3233
"filename": "bumpversion/__init__.py",
3334
"glob": null,
3435
"glob_exclude": null,
3536
"ignore_missing_file": false,
3637
"ignore_missing_version": false,
37-
"invalid_bumps": [],
38+
"include_bumps": [
39+
"major",
40+
"minor",
41+
"patch",
42+
"release"
43+
],
3844
"key_path": null,
3945
"parse": "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\-(?P<release>[a-z]+))?",
4046
"regex": false,
@@ -43,21 +49,21 @@
4349
"serialize": [
4450
"{major}.{minor}.{patch}-{release}",
4551
"{major}.{minor}.{patch}"
46-
],
47-
"valid_bumps": [
48-
"major",
49-
"minor",
50-
"patch",
51-
"release"
5252
]
5353
},
5454
{
55+
"exclude_bumps": [],
5556
"filename": "CHANGELOG.md",
5657
"glob": null,
5758
"glob_exclude": null,
5859
"ignore_missing_file": false,
5960
"ignore_missing_version": false,
60-
"invalid_bumps": [],
61+
"include_bumps": [
62+
"major",
63+
"minor",
64+
"patch",
65+
"release"
66+
],
6167
"key_path": null,
6268
"parse": "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\-(?P<release>[a-z]+))?",
6369
"regex": false,
@@ -66,12 +72,6 @@
6672
"serialize": [
6773
"{major}.{minor}.{patch}-{release}",
6874
"{major}.{minor}.{patch}"
69-
],
70-
"valid_bumps": [
71-
"major",
72-
"minor",
73-
"patch",
74-
"release"
7575
]
7676
}
7777
],

tests/test_bump.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ def test_passing_no_arguments_raises_error(self):
157157

158158
@patch("bumpversion.files.modify_files")
159159
@patch("bumpversion.bump.update_config_file")
160-
def test_includes_files_with_valid_bumps(self, mock_update_config_file, mock_modify_files):
161-
"""Files that have valid_bumps are included when those bumps happen."""
160+
def test_includes_files_with_include_bumps(self, mock_update_config_file, mock_modify_files):
161+
"""Files that have include_bumps are included when those bumps happen."""
162162
# Arrange
163163
new_version = None
164164
config, version_config, current_version = get_config_data(
165165
{
166166
"current_version": "1.2.3",
167-
"files": [{"filename": "foo.txt", "valid_bumps": ["major", "minor"]}, {"filename": "bar.txt"}],
167+
"files": [{"filename": "foo.txt", "include_bumps": ["major", "minor"]}, {"filename": "bar.txt"}],
168168
}
169169
)
170170
config.scm_info = SCMInfo()
@@ -184,14 +184,14 @@ def test_includes_files_with_valid_bumps(self, mock_update_config_file, mock_mod
184184

185185
@patch("bumpversion.files.modify_files")
186186
@patch("bumpversion.bump.update_config_file")
187-
def test_excludes_files_with_invalid_bumps(self, mock_update_config_file, mock_modify_files):
188-
"""Files that have invalid_bumps are excluded when those bumps happen."""
187+
def test_excludes_files_with_exclude_bumps(self, mock_update_config_file, mock_modify_files):
188+
"""Files that have exclude_bumps are excluded when those bumps happen."""
189189
# Arrange
190190
new_version = None
191191
config, version_config, current_version = get_config_data(
192192
{
193193
"current_version": "1.2.3",
194-
"files": [{"filename": "foo.txt", "invalid_bumps": ["patch"]}, {"filename": "bar.txt"}],
194+
"files": [{"filename": "foo.txt", "exclude_bumps": ["patch"]}, {"filename": "bar.txt"}],
195195
}
196196
)
197197
config.scm_info = SCMInfo()

tests/test_config/test_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_uses_defaults_for_missing_keys(self, tmp_path: Path):
4444

4545
for key in FileChange.model_fields.keys():
4646
global_key = key if key != "ignore_missing_file" else "ignore_missing_files"
47-
variable_fields = ["filename", "glob", "key_path", "glob_exclude", "valid_bumps", "invalid_bumps"]
47+
variable_fields = ["filename", "glob", "key_path", "glob_exclude", "include_bumps", "exclude_bumps"]
4848

4949
if key not in variable_fields:
5050
file_val = getattr(file_configs[0], key)

0 commit comments

Comments
 (0)