File not found when using replace
Closed this issue · 3 comments
- bump-my-version version: 0.24.2
- Python version: 3.12
- Operating System: Windows
Description
I want to run bump-my-version replace patch
and see my pyproject.toml
version updated.
What I Did
Installed and ran bump-my-version sample-config --no-prompt --destination .bumpversion.toml
which successfully created .bumpversion.toml
automatically setting current_version to 0.1.0 from pyproject.toml
Content
[tool.bumpversion]
current_version = "0.1.0"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"]
search = "{current_version}"
replace = "{new_version}"
regex = false
ignore_missing_version = false
ignore_missing_files = false
tag = false
sign_tags = false
tag_name = "v{new_version}"
tag_message = "Bump version: {current_version} → {new_version}"
allow_dirty = false
commit = false
message = "Bump version: {current_version} → {new_version}"
commit_args = ""
Successfully ran bump-my-version bump patch
which bumped ok to 0.1.1
[tool.bumpversion]
current_version = "0.1.1"
Tried running bump-my-version replace patch
and got no file found error
File "c:\Users\David.Budd\Documents\Github\blocksets\.venv\Lib\site-packages\bumpversion\cli.py", line 537, in replace
modify_files(configured_files, version, next_version, ctx, dry_run)
File "c:\Users\David.Budd\Documents\Github\blocksets\.venv\Lib\site-packages\bumpversion\files.py", line 269, in modify_files
f.make_file_change(current_version, new_version, context, dry_run)
File "c:\Users\David.Budd\Documents\Github\blocksets\.venv\Lib\site-packages\bumpversion\files.py", line 187, in make_file_change
raise FileNotFoundError(f"File not found: '{self.file_change.filename}'") # pragma: no-coverage
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: File not found: 'patch'
@daveisagit It sounds like you want to do the change to pyproject.toml at the same time you bump the version.
To do this add this to your configuration:
[[tool.bumpversion.files]]
regex = true
filename = "pyproject.toml"
search = "^version = \"{current_version}\""
replace = "version = \"{new_version}\""
Here is a reference to the search and replace docs for more details.
Thanks, but I still get the same error. It seems to me the replace has trouble finding the file which is odd given the generation of config found it by default with no problem.
Why is it taking the patch option as the filename?
Ok, so this me not understanding how to use it.
For anyone else in a similar mindset, the replace
option is not the way.
Simply use bump
with the version_part
and that will update the pyproject.toml
file if you add the [[tool.bumpversion.files]]
entry as suggested.
In fact you only need to add
[[tool.bumpversion.files]]
filename = "pyproject.toml"