Ignore missing files
Closed this issue · 1 comments
- bump-my-version version:
0.8.0
- Python version:
3.11.4
- Operating System: macOS 13.4
Description
I propose to add a new --ignore-missing-file
, to ignore files that are referenced in the configuration file but not found by bump-my-version
.
Why? Because all files having their own [[tool.bumpversion.files]]
entry in the TOML configuration are required to be present on the file system.
Having this option will allow me to have a collection of search and replace patterns in a TOML that I can share across several projects of different kind. With this new --ignore-missing-file
behaviour, each project will then naturally match patterns that can be apply to them and ignore the others.
The name --ignore-missing-file
I propose is based on the new --ignore-missing-version
that was implemented in #10.
What I Did
Given this minimal project:
$ ls
pyproject.toml
And with ./pyproject.toml
containing:
[tool.bumpversion]
current_version = "2.17.7"
allow_dirty = true
[[tool.bumpversion.files]]
filename = "./citation.cff"
search = "version: {current_version}"
replace = "version: {new_version}"
The following command fails:
$ bump-my-version replace --dry-run ./changelog.md
Specified version (2.17.8) does not match last tagged version (2.17.7)
Traceback (most recent call last):
File "~/.local/bin/bump-my-version", line 8, in <module>
sys.exit(cli())
^^^^^
File ".../click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../rich_click/rich_group.py", line 21, in main
rv = super().main(*args, standalone_mode=False, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../click/core.py", line 1055, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File ".../click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../bumpversion/cli.py", line 498, in replace
modify_files(configured_files, version, next_version, ctx, dry_run)
File ".../bumpversion/files.py", line 193, in modify_files
_check_files_contain_version(files, current_version, context)
File ".../bumpversion/files.py", line 231, in _check_files_contain_version
f.contains_version(current_version, context)
File ".../bumpversion/files.py", line 50, in contains_version
if self.contains(search_expression):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../bumpversion/files.py", line 76, in contains
with open(self.path, "rt", encoding="utf-8") as f:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: './citation.cff'
Instead, with the --ignore-missing-file
, I expect the invokation above to not fail and have bump-my-version only report the citation.cff
was not found and search and replace patterns simply skipped.