Skip to content

Commit e0731c3

Browse files
committed
Added documentation for ignore missing version
1 parent a5bd008 commit e0731c3

12 files changed

+291
-247
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Avoiding incorrect replacements
2+
3+
In files that have multiple version strings, bump-my-version may find the wrong string and replace it. Given this `requirements.txt` for `MyProject`:
4+
5+
```text
6+
Django>=1.5.6,<1.6
7+
MyProject==1.5.6
8+
```
9+
10+
The default search and replace templates will replace the wrong text. Instead of changing `MyProject`'s version from `1.5.6` to `1.6.0`, it changes `Django`'s version:
11+
12+
```text
13+
Django>=1.6.0,<1.6
14+
MyProject==1.5.6
15+
```
16+
17+
Providing search and replace templates for the `requirements.txt` file will avoid this.
18+
19+
This `.bumpversion.toml` will ensure only the line containing `MyProject` will be changed:
20+
21+
```toml
22+
[tool.bumpversion]
23+
current_version = "1.5.6"
24+
25+
[[tool.bumpversion.files]]
26+
filename = "requirements.txt"
27+
search = "MyProject=={current_version}"
28+
replace = "MyProject=={new_version}"
29+
```
30+
31+
If the string to be replaced includes literal quotes, the search and replace patterns must include them to match. Given the file `version.sh`:
32+
33+
MY_VERSION="1.2.3"
34+
35+
Then the following search and replace patterns (including quotes) would be required:
36+
37+
```toml
38+
[[tool.bumpversion.files]]
39+
filename = "version.sh"
40+
search = "MY_VERSION=\"{current_version}\""
41+
replace = "MY_VERSION=\"{new_version}\""
42+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Custom version formats in different files
2+
3+
You can use file configurations to replace the version in multiple files, even if each file has the version formatted differently.
4+
5+
In a module-aware Go project, when you create a major version of your module beyond `v1`, your module name must include the major version number (e.g., `github.com/myorg/myproject/v2`). However, you also have the full version in a YAML file named `release-channels.yaml`.
6+
7+
`go.mod` file:
8+
9+
```go
10+
module github.com/myorg/myproject/v2
11+
12+
go 1.12
13+
14+
require (
15+
...
16+
)
17+
```
18+
19+
`release-channels.yaml` file:
20+
21+
```yaml
22+
stable: "v2.21.4"
23+
```
24+
25+
You can use bump-my-version to maintain the major version number within the `go.mod` file by using the `parse` and `serialize` options, as in this example:
26+
27+
`.bumpversion.toml` file:
28+
29+
```toml
30+
[tool.bumpversion]
31+
current_version = "2.21.4"
32+
33+
[[tool.bumpversion.files]]
34+
filename = "go.mod"
35+
parse = "(?P<major>\\d+)"
36+
serialize = "{major}"
37+
search = "module github.com/myorg/myproject/v{current_version}"
38+
replace = "module github.com/myorg/myproject/v{new_version}"
39+
40+
[[tool.bumpversion.files]]
41+
filename = "release-channels.yaml"
42+
```
43+
44+
While all the version bumps are `minor` or `patch`, the `go.mod` file doesn't change, while the `release-channels.yaml` file will. As soon as you do a `major` version bump, the `go.mod` file now contains this module directive:
45+
46+
```go
47+
module github.com/myorg/myproject/v3
48+
```

docsrc/howtos/index.md

+3
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33

44

55
```{toctree}
6+
avoid-incorrect-replacements
7+
custom-version-formats-by-file
8+
multiple-replacements
69
```
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Multiple replacements within the same file
2+
3+
To make several replacements in the same file, you must configure multiple `[[tool.bumpversion.files]]` sections for the same file with different configuration options.
4+
5+
In this example, the changelog is generated before the version bump. It uses `Unreleased` as the heading and includes a link to GitHub to compare this version (`HEAD`) with the previous version.
6+
7+
To change `Unreleased ` to the current version, we have an entry with `search` set to `Unreleased`. The default `replace` value is `{new_version}`, so changing it is unnecessary.
8+
9+
To change the link, another entry has its `search` set to `{current_version}...HEAD` and the `replace` set to `{current_version}...{new_version}`.
10+
11+
```toml
12+
[[tool.bumpversion.files]]
13+
filename = "CHANGELOG.md"
14+
search = "Unreleased"
15+
16+
[[tool.bumpversion.files]]
17+
filename = "CHANGELOG.md"
18+
search = "{current_version}...HEAD"
19+
replace = "{current_version}...{new_version}"
20+
```

docsrc/reference/bumpversion/bumpversion.cli.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
```
6565
````
6666

67-
````{py:function} bump(args: list, config_file: typing.Optional[str], verbose: int, allow_dirty: typing.Optional[bool], current_version: typing.Optional[str], new_version: typing.Optional[str], parse: typing.Optional[str], serialize: typing.Optional[typing.List[str]], search: typing.Optional[str], replace: typing.Optional[str], no_configured_files: bool, dry_run: bool, commit: typing.Optional[bool], tag: typing.Optional[bool], sign_tags: typing.Optional[bool], tag_name: typing.Optional[str], tag_message: typing.Optional[str], message: typing.Optional[str], commit_args: typing.Optional[str], show_list: bool) -> None
67+
````{py:function} bump(args: list, config_file: typing.Optional[str], verbose: int, allow_dirty: typing.Optional[bool], current_version: typing.Optional[str], new_version: typing.Optional[str], parse: typing.Optional[str], serialize: typing.Optional[typing.List[str]], search: typing.Optional[str], replace: typing.Optional[str], no_configured_files: bool, ignore_missing_version: bool, dry_run: bool, commit: typing.Optional[bool], tag: typing.Optional[bool], sign_tags: typing.Optional[bool], tag_name: typing.Optional[str], tag_message: typing.Optional[str], message: typing.Optional[str], commit_args: typing.Optional[str], show_list: bool) -> None
6868
:canonical: bumpversion.cli.bump
6969
7070
```{autodoc2-docstring} bumpversion.cli.bump
@@ -78,7 +78,7 @@
7878
```
7979
````
8080

81-
````{py:function} replace(files: list, config_file: typing.Optional[str], verbose: int, allow_dirty: typing.Optional[bool], current_version: typing.Optional[str], new_version: typing.Optional[str], parse: typing.Optional[str], serialize: typing.Optional[typing.List[str]], search: typing.Optional[str], replace: typing.Optional[str], no_configured_files: bool, dry_run: bool) -> None
81+
````{py:function} replace(files: list, config_file: typing.Optional[str], verbose: int, allow_dirty: typing.Optional[bool], current_version: typing.Optional[str], new_version: typing.Optional[str], parse: typing.Optional[str], serialize: typing.Optional[typing.List[str]], search: typing.Optional[str], replace: typing.Optional[str], no_configured_files: bool, ignore_missing_version: bool, dry_run: bool) -> None
8282
:canonical: bumpversion.cli.replace
8383
8484
```{autodoc2-docstring} bumpversion.cli.replace

docsrc/reference/bumpversion/bumpversion.config.md

+33
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
:class: autosummary longtable
3636
:align: left
3737
38+
* - {py:obj}`get_all_file_configs <bumpversion.config.get_all_file_configs>`
39+
- ```{autodoc2-docstring} bumpversion.config.get_all_file_configs
40+
:summary:
41+
```
3842
* - {py:obj}`get_configuration <bumpversion.config.get_configuration>`
3943
- ```{autodoc2-docstring} bumpversion.config.get_configuration
4044
:summary:
@@ -229,6 +233,17 @@ Bases: {py:obj}`pydantic.BaseModel`
229233
230234
````
231235
236+
````{py:attribute} ignore_missing_version
237+
:canonical: bumpversion.config.FileConfig.ignore_missing_version
238+
:type: typing.Optional[bool]
239+
:value: >
240+
None
241+
242+
```{autodoc2-docstring} bumpversion.config.FileConfig.ignore_missing_version
243+
```
244+
245+
````
246+
232247
`````
233248

234249
``````{py:class} Config
@@ -294,6 +309,17 @@ Bases: {py:obj}`pydantic.BaseSettings`
294309
295310
````
296311
312+
````{py:attribute} ignore_missing_version
313+
:canonical: bumpversion.config.Config.ignore_missing_version
314+
:type: bool
315+
:value: >
316+
None
317+
318+
```{autodoc2-docstring} bumpversion.config.Config.ignore_missing_version
319+
```
320+
321+
````
322+
297323
````{py:attribute} tag
298324
:canonical: bumpversion.config.Config.tag
299325
:type: bool
@@ -472,6 +498,13 @@ Bases: {py:obj}`pydantic.BaseSettings`
472498
473499
````
474500

501+
````{py:function} get_all_file_configs(config_dict: dict) -> typing.List[bumpversion.config.FileConfig]
502+
:canonical: bumpversion.config.get_all_file_configs
503+
504+
```{autodoc2-docstring} bumpversion.config.get_all_file_configs
505+
```
506+
````
507+
475508
````{py:function} get_configuration(config_file: typing.Union[str, pathlib.Path, None] = None, **overrides) -> bumpversion.config.Config
476509
:canonical: bumpversion.config.get_configuration
477510

docsrc/reference/bumpversion/bumpversion.files.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
7070
````
7171

72-
`````{py:class} ConfiguredFile(file_cfg: bumpversion.config.FileConfig, version_config: bumpversion.version_part.VersionConfig)
72+
`````{py:class} ConfiguredFile(file_cfg: bumpversion.config.FileConfig, version_config: bumpversion.version_part.VersionConfig, search: typing.Optional[str] = None, replace: typing.Optional[str] = None)
7373
:canonical: bumpversion.files.ConfiguredFile
7474
7575
```{autodoc2-docstring} bumpversion.files.ConfiguredFile
@@ -117,7 +117,7 @@
117117
118118
`````
119119

120-
````{py:function} resolve_file_config(files: typing.List[bumpversion.config.FileConfig], version_config: bumpversion.version_part.VersionConfig) -> typing.List[bumpversion.files.ConfiguredFile]
120+
````{py:function} resolve_file_config(files: typing.List[bumpversion.config.FileConfig], version_config: bumpversion.version_part.VersionConfig, search: typing.Optional[str] = None, replace: typing.Optional[str] = None) -> typing.List[bumpversion.files.ConfiguredFile]
121121
:canonical: bumpversion.files.resolve_file_config
122122
123123
```{autodoc2-docstring} bumpversion.files.resolve_file_config
@@ -131,7 +131,7 @@
131131
```
132132
````
133133

134-
````{py:function} get_glob_files(file_cfg: bumpversion.config.FileConfig, version_config: bumpversion.version_part.VersionConfig) -> typing.List[bumpversion.files.ConfiguredFile]
134+
````{py:function} get_glob_files(file_cfg: bumpversion.config.FileConfig, version_config: bumpversion.version_part.VersionConfig, search: typing.Optional[str] = None, replace: typing.Optional[str] = None) -> typing.List[bumpversion.files.ConfiguredFile]
135135
:canonical: bumpversion.files.get_glob_files
136136
137137
```{autodoc2-docstring} bumpversion.files.get_glob_files

docsrc/reference/bumpversion/bumpversion.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bumpversion.__main__
5151
:canonical: bumpversion.__version__
5252
:type: str
5353
:value: >
54-
'0.6.0'
54+
'0.7.1'
5555
5656
```{autodoc2-docstring} bumpversion.__version__
5757
```

docsrc/reference/bumpversion/bumpversion.ui.md

+11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
- ```{autodoc2-docstring} bumpversion.ui.print_error
2424
:summary:
2525
```
26+
* - {py:obj}`print_warning <bumpversion.ui.print_warning>`
27+
- ```{autodoc2-docstring} bumpversion.ui.print_warning
28+
:summary:
29+
```
2630
````
2731

2832
### API
@@ -40,3 +44,10 @@
4044
```{autodoc2-docstring} bumpversion.ui.print_error
4145
```
4246
````
47+
48+
````{py:function} print_warning(msg: str) -> None
49+
:canonical: bumpversion.ui.print_warning
50+
51+
```{autodoc2-docstring} bumpversion.ui.print_warning
52+
```
53+
````

0 commit comments

Comments
 (0)