Avoid incorrect replacements¶
In files that have multiple version strings, Bump My Version may find the wrong string and replace it. Given this requirements.txt
for MyProject
:
Django>=1.5.6,<1.6
MyProject==1.5.6
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:
Django>=1.6.0,<1.6
MyProject==1.5.6
Providing search and replace templates for the requirements.txt
file will avoid this.
This .bumpversion.toml
will ensure only the line containing MyProject
will be changed:
[tool.bumpversion]
current_version = "1.5.6"
[[tool.bumpversion.files]]
filename = "requirements.txt"
search = "MyProject=={current_version}"
replace = "MyProject=={new_version}"
If the string to be replaced includes literal quotes, the search and replace patterns must include them to match. Given the file version.sh
:
MY_VERSION="1.2.3"
Then the following search and replace patterns (including quotes) would be required:
[[tool.bumpversion.files]]
filename = "version.sh"
search = "MY_VERSION=\"{current_version}\""
replace = "MY_VERSION=\"{new_version}\""