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

Feature: conditional search and replace blocks #189

Closed
Zeitsperre opened this issue May 10, 2024 · 9 comments · Fixed by #197
Closed

Feature: conditional search and replace blocks #189

Zeitsperre opened this issue May 10, 2024 · 9 comments · Fixed by #197
Labels
feature-request New feature or request

Comments

@Zeitsperre
Copy link

  • bump-my-version version: 0.21.0
  • Python version: Any
  • Operating System: All

Description

I've been running into a problem and was wondering how much of an implementation challenge this would be. In my changelog, I would love to make use of the search and replace functionality for automating the version entries a bit.

An example implementation (from a rendered cookiecutter template):

[[tool.bumpversion.files]]
filename = "CHANGES.rst"
search = """\
`Unreleased <https://github.com/audreyr/python_boilerplate>`_ (latest)
----------------------------------------------------------------------
"""
replace = """\
`Unreleased <https://github.com/audreyr/python_boilerplate>`_ (latest)
----------------------------------------------------------------------

Contributors:

Changes
^^^^^^^
* No change.

Fixes
^^^^^
* No change.

.. _changes_{new_version}:

`v{new_version} <https://github.com/audreyr/python_boilerplate/tree/{new_version}>`_
-----------------------------------------------------------------------------
"""

To break it down, this adds a new entry that for unreleased and replaces the older unreleased entry with the tagged version. My issue is when I'm using SemVer v2.0 (https://semver.org/spec/v2.0.0.html) and bumping the development version on every commit, e.g.:

v1.0.0 
  → 1.0.1-dev0 (bump build)
    → 1.0.1-dev1 (bump build
      → 1.0.1 (bump release)

This triggers the replacement block on every operation, so I end up with multiple changelog blocks for each progressive non-release bump. Not great.

What I'd like to happen

I'd love to see an option under the [[tool.bumpversion.files]] entries to only do a replacement operation if a specific type of bump operation is called (e.g. major, minor, patch, but specifically release in my case), e.g.:

[[tool.bumpversion.files]]
filename = "src/python_boilerplate/__init__.py"
search = "__version__ = \"{current_version}\""
replace = "__version__ = \"{new_version}\""
on = "release"
@Zeitsperre
Copy link
Author

FYI @bzah

@coordt
Copy link
Member

coordt commented May 10, 2024

Your approach is interesting. It might be a bit before I can accomplish it.

What I currently do to avoid this problem is not have bump-my-version commit and tag. Then I can package the dev release but the version changes are not saved.

@wkoot
Copy link
Contributor

wkoot commented Jun 11, 2024

We'd also like to use such a feature, for example in the various replacements for a Quality-time release.
Ideally, the changelog itself should only be altered in case of a "final" release and not for release-candidates.

@coordt
Copy link
Member

coordt commented Jun 12, 2024

@wkoot @Zeitsperre

I have working code in PR #189 . I'm going to update the docs more. I would love some feedback before I merge this.

@wkoot
Copy link
Contributor

wkoot commented Jun 13, 2024

I assume you mean #197, is it possible to publish a release candidate or temp version we can easily fetch from pypi? :)

@coordt
Copy link
Member

coordt commented Jun 13, 2024

@wkoot @Zeitsperre I have a pre-release available.

@Zeitsperre
Copy link
Author

@coordt Thanks so much! I'll have time either today or tomorrow to give this a try!

@wkoot
Copy link
Contributor

wkoot commented Jun 13, 2024

@wkoot @Zeitsperre I have a pre-release available.

Tested, seems to be working! I only used the exclude_bumps option though

@Zeitsperre
Copy link
Author

Can confirm that it works for include-bumps!

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

Successfully merging a pull request may close this issue.

3 participants