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

Dynamically generate an dashed line based on version string length #126

Closed
sdementen opened this issue Jan 25, 2020 · 8 comments
Closed
Labels

Comments

@sdementen
Copy link

I would like to convert the follwing in my changelog with bump2version

(dev)

* my change log item

0.1.13 (2020-01-25)
-------------------

* my change log item

I have tried something like

[bumpversion:file:CHANGELOG.rst]
search = (dev)
replace = {new_version} ({now:%Y-%m-%d})
	"{'-' * len(new_version)}--{'-' * len(now.strftime('%Y-%m-%d'))}-"

but bump2version uses string format and not f-string.

Is there some way to do this ?

@florisla
Copy link
Collaborator

So you want to influence the width of the dashed line based on the width of the version string...

Bump2verson does not use f-strings because we still support Python 3.5.

I don't think there's a way to achieve the desired effect in bump2version itself.

Possible workarounds

  • Serialize the version numbers with fixed width and keep the underline width constant.
 0. 1.13
12.11. 1
  • Calculate the 'width of the underline' externally and supply the underline dashes as an environment variable
    replace = {new_version} ({now:%Y-%m-%d})
        {$VERSION_STRING_UNDERLINE}

@florisla florisla changed the title updating a changelog release date Dynamically generate an dashed line based on version string length Jan 25, 2020
@sdementen
Copy link
Author

Indeed, great workaround.
What is needed to avoid having the current version in the changelog being updated when bumping?

@florisla
Copy link
Collaborator

--dry-run

You can combine it wit --list.

@sdementen
Copy link
Author

Sorry, I wasn't clear.
In the changelog, for each version, there is a list of changes.
If I am at version 1.1.4 and developing for 1.1.5, I write in the changelog, "(dev)" (not 1.1.5.).
When I bump the version, I want (dev) to be converted to 1.1.5 but the old 1.1.4 should stay unchanged.
For the search field, I write "(dev)" and it works as expected if the string "(dev)" is in the changelog file (I.e. "(dev)" is replaced by "1.1.5". However, if the string "(dev)" is not in the changelog, then it is the string "1.1.4" (that should not be changed in the changelog file) that gets updated to "1.1.5"

@florisla
Copy link
Collaborator

Ah yes, if search is not found then it simply searches for {current_version}. There's no way around that currently.

I just opened #127 to fix this.

@sdementen
Copy link
Author

for the record, I finally end up with:

[bumpversion:file:CHANGELOG.rst]
search = (dev)
replace = {new_version:<8} ({now:%Y-%m-%d})
	---------------------

which works (as long as (dev) exists in the changelog, ie not hit by #127 )

@florisla
Copy link
Collaborator

florisla commented Jan 29, 2020

Good find to use <8 formatting.

I guess you can now move the dashed line out of your config file, into the changelog.

@sdementen
Copy link
Author

I keep the dashed line in the config to avoid needing to copy it each time, I just type "(dev)" and I am good to go

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

No branches or pull requests

2 participants