Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ignore_missing_files global option in configuration file #145

Closed
kdeldycke opened this issue Feb 25, 2024 · 2 comments
Closed
Labels
feature-request New feature or request

Comments

@kdeldycke
Copy link
Collaborator

  • bump-my-version version: 0.18.1
  • Python version: 3.12.2
  • Operating System: macOS 14.3.1

Description

Following up on the new --ignore-missing-files feature (see #38 and #138), I can confirm it works well. To make it even more flexible, it would be nice to have a corresponding ignore_missing_files option available in the configuration file.

What I Did

Given this pyproject.toml file in an empty directory:

[tool.bumpversion]
current_version = "3.3.0"

[[tool.bumpversion.files]]
filename = "./citation.cff"
search = "version: {current_version}"
replace = "version: {new_version}"

A call to a bump action fails as expected because there is no ./citation.cff file in sight:

$ bump-my-version bump minor
Traceback (most recent call last):
  File "/Users/kde/.local/bin/bump-my-version", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/rich_click/rich_command.py", line 126, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/bumpversion/cli.py", line 325, in bump
    do_bump(version_part, new_version, config, found_config_file, dry_run)
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/bumpversion/bump.py", line 97, in do_bump
    modify_files(configured_files, version, next_version, ctx, dry_run)
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/bumpversion/files.py", line 264, in modify_files
    f.make_file_change(current_version, new_version, context, dry_run)
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/bumpversion/files.py", line 185, in make_file_change
    raise FileNotFoundError(f"File not found: '{self.file_change.filename}'")  # pragma: no-coverage
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: File not found: './citation.cff'

Using the new --ignore-missing-files parameter help the missing file to be ignored, as intended:

$ bump-my-version --verbose --ignore-missing-files bump minor
Starting BumpVersion 0.18.1                                                                                                                                                                                         
Reading configuration                                                                                                                                                                                               
  Reading config file: /Users/kde/bump_test/pyproject.toml                                                                                                                                                          
  Parsing current version '3.3.0'                                                                                                                                                                                   
  Attempting to increment part 'minor'                                                                                                                                                                              
    Values are now: major=3, minor=4, patch=0                                                                                                                                                                       
  New version will be '3.4.0'                                                                                                                                                                                       
                                                                                                                                                                                                                    
File ./citation.cff: replace `version: {current_version}` with `version: {new_version}`                                                                                                                             
  File not found, but ignoring                                                                                                                                                                                      
                                                                                                                                                                                                                    
Processing config file: /Users/kde/bump_test/pyproject.toml                                                                                                                                                         
  Found '3\.3\.0' at line 1: 3.3.0                                                                                                                                                                                  
  Changing file /Users/kde/bump_test/pyproject.toml:tool.bumpversion.current_version:                                                                                                                               
    *** before /Users/kde/bump_test/pyproject.toml:tool.bumpversion.current_version                                                                                                                                 
    --- after /Users/kde/bump_test/pyproject.toml:tool.bumpversion.current_version                                                                                                                                  
    ***************                                                                                                                                                                                                 
    *** 1 ****                                                                                                                                                                                                      
    ! 3.3.0                                                                                                                                                                                                         
    --- 1 ----                                                                                                                                                                                                      
    ! 3.4.0                                                                                                                                                                                                         
Done. 

Now I would like to transfer the inline --ignore-missing-files parameter to the config file. So I update the pyproject.toml file to:

[tool.bumpversion]
current_version = "3.3.0"
ignore_missing_files = true

[[tool.bumpversion.files]]
filename = "./citation.cff"
search = "version: {current_version}"
replace = "version: {new_version}"

And I expected the CLI to be able to take my new ignore_missing_files = true configuration into account, but it does not, leading to the same issue as if --ignore-missing-files parameter wasn't passed to the CLI:

❯ bump-my-version --verbose bump minor
Starting BumpVersion 0.18.1                                                                                                                                                                                         
Reading configuration                                                                                                                                                                                               
  Reading config file: /Users/kde/bump_test/pyproject.toml                                                                                                                                                          
  Parsing current version '3.3.0'                                                                                                                                                                                   
  Attempting to increment part 'minor'                                                                                                                                                                              
    Values are now: major=3, minor=4, patch=0                                                                                                                                                                       
  New version will be '3.4.0'                                                                                                                                                                                                          
File ./citation.cff: replace `version: {current_version}` with `version: {new_version}`                                                                                                                             
Traceback (most recent call last):
  File "/Users/kde/.local/bin/bump-my-version", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/rich_click/rich_command.py", line 126, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/bumpversion/cli.py", line 325, in bump
    do_bump(version_part, new_version, config, found_config_file, dry_run)
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/bumpversion/bump.py", line 97, in do_bump
    modify_files(configured_files, version, next_version, ctx, dry_run)
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/bumpversion/files.py", line 264, in modify_files
    f.make_file_change(current_version, new_version, context, dry_run)
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/bumpversion/files.py", line 185, in make_file_change
    raise FileNotFoundError(f"File not found: '{self.file_change.filename}'")  # pragma: no-coverage
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: File not found: './citation.cff'
kdeldycke added a commit to kdeldycke/workflows that referenced this issue Feb 25, 2024
@kdeldycke kdeldycke added the feature-request New feature or request label Feb 25, 2024
@coordt
Copy link
Member

coordt commented Mar 2, 2024

I think 0.18.2 fixed this. There was an error in how the flags were interpreted in the CLI.

Can you check?

@kdeldycke
Copy link
Collaborator Author

Yep. Just tested with 0.18.3 and it works! Thanks @coordt for the heads up! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants