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

Traceback on --search parameter with plain string #34

Closed
kdeldycke opened this issue Jul 11, 2023 · 4 comments · Fixed by #36
Closed

Traceback on --search parameter with plain string #34

kdeldycke opened this issue Jul 11, 2023 · 4 comments · Fixed by #36
Labels
bug Something isn't working

Comments

@kdeldycke
Copy link
Collaborator

  • bump-my-version version: 0.7.0
  • Python version: 3.11.4
  • Operating System: macOS 13.4

Description

It seems a search and replace operation (without any bump), on a search string that is a constant (i.e. no reference of a version), lead to a traceback.

What I Did

Here is a minimal example to reproduce the issue with this structure:

$ ls
docs.yaml  pyproject.toml

The local ./docs.yaml file contains:

url: https://github.com/kdeldycke/workflows/main/.github/update_mailmap.py

./pyproject.toml contains:

[tool.bumpversion]
current_version = "2.17.7"
allow_dirty = true

I use the latest CLI:

$ bump-my-version --version
bump-my-version, version 0.7.0

The configuration file is sourced correctly with the good defaults:

$ bump-my-version show
{'allow_dirty': True,
 'commit': False,
 'commit_args': None,
 'current_version': '2.17.7',
 'files': [],
 'message': 'Bump version: {current_version} → {new_version}',
 'parse': '(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)',
 'parts': {'major': {'first_value': None,
                     'independent': False,
                     'optional_value': None,
                     'values': None},
           'minor': {'first_value': None,
                     'independent': False,
                     'optional_value': None,
                     'values': None},
           'patch': {'first_value': None,
                     'independent': False,
                     'optional_value': None,
                     'values': None}},
 'replace': '{new_version}',
 'scm_info': SCMInfo(tool=No SCM tool, commit_sha=None, distance_to_latest_tag=None, current_version=None, dirty=None),
 'search': '{current_version}',
 'serialize': ['{major}.{minor}.{patch}'],
 'sign_tags': False,
 'tag': False,
 'tag_message': 'Bump version: {current_version} → {new_version}',
 'tag_name': 'v{new_version}'}

Now if I try to perform a simple search & replace operation on ./docs.yaml with:

$ bump-my-version replace --dry-run --no-configured-files --search "/workflows/main/" --replace "/workflows/v{current_version}/" ./docs.yaml

I get the following traceback:

Traceback (most recent call last):
  File "~/.local/bin/bump-my-version", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File ".../site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/rich_click/rich_group.py", line 21, in main
    rv = super().main(*args, standalone_mode=False, **kwargs)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File ".../site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/bumpversion/cli.py", line 446, in replace
    modify_files(configured_files, version, next_version, ctx, dry_run)
  File ".../site-packages/bumpversion/files.py", line 181, in modify_files
    f.replace_version(current_version, new_version, context, dry_run)
  File ".../site-packages/bumpversion/files.py", line 101, in replace_version
    context["new_version"] = self.version_config.serialize(new_version, context)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/bumpversion/version_part.py", line 306, in serialize
    serialized = self._serialize(version, self._choose_serialize_format(version, context), context)
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/bumpversion/version_part.py", line 271, in _choose_serialize_format
    self._serialize(version, serialize_format, context, raise_if_incomplete=True)
  File ".../site-packages/bumpversion/version_part.py", line 224, in _serialize
    for k in version:
TypeError: 'NoneType' object is not iterable
@coordt
Copy link
Member

coordt commented Jul 11, 2023

@kdeldycke, I love the thoroughness of your issues. Thank you so much for that.

I have a branch and test that reproduces the issue. I think the best course of action is to refactor a bit more and decouple the formatting logic found in the ConfiguredFile class. There appears to be an assumption that every change will contain a version.

I'll work on it today.

@kdeldycke
Copy link
Collaborator Author

Thanks for the feedback! And take your time, there is not rush. 🤗

BTW, if it helps to simplify things, and allows you refactor further, I guess you can now start to break backward-compatibility with bump2version: you already have the 0.1.0 to 0.7.0 version of bump-my-version for anybody to transition. bump-my-version is its own project now and nobody will regret the unmaintained bump2version! 😁

coordt added a commit that referenced this issue Jul 11, 2023
- The `--search` and `--replace` options now completely override any other search and replace logic.

Fixes #34
@coordt coordt linked a pull request Jul 11, 2023 that will close this issue
@kdeldycke
Copy link
Collaborator Author

Can confirm this has been fixed in 0.7.1. Thanks @coordt for the quick fix! 💪

@kdeldycke
Copy link
Collaborator Author

For the record this fix helped my replace some Perl oneliners with bump-my-version: kdeldycke/workflows@b13b6b6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants