bump2version icon indicating copy to clipboard operation
bump2version copied to clipboard

Support dates in replace

Open Gallaecio opened this issue 4 years ago • 8 comments

In order to set the current date in the last release notes entry, where we use a ? in unknown digits of the release date, I would like to use something like:

[bumpversion:file:docs/news.rst]
search = (?<=\()[\d?]{4}-[\d?]{2}-[\d?]\?(?=\))
replace = {now:%Y-%m-%d}

Would it be possible to add now support to replace, or support this scenario some other way?

Gallaecio avatar Feb 28 '20 12:02 Gallaecio

In Python projects, the support of date (current date with datetime.date.today or user-defined date) would be interesting and in harmony with the package metadata which pydoc (and the help function) can display.

For instance, if your package contains:

__version__ = "0.11.0"
__date__ = "2020-06-10"
__author__ = "Mr Robot <[email protected]>"
__credits__ = "(c) F. Society"

The help function would display:

[...]

VERSION
    0.11.0

DATE
    2020-06-10

AUTHOR
    Mr Robot <[email protected]>

CREDITS
    (c) F. Society

That way, a developper can easily have the version number and the date of your package.

So, it wold be great if bump2version could update the version number and the release date at the same time).

Question: does bump2verion support pre-/post-release hook ?

laurent-laporte-pro avatar Jun 11 '20 09:06 laurent-laporte-pro

I want to add that I would also like this feature, in particular to update non-Python files. Specifically, manpages. For example, I would like have this in my .bumpversion.cfg:

[bumpversion:file:man/man1/xdg-env.1]
search = "\d\d\d\d \w\w\w \d\d" "v{current_version}"      ; I could certainly use a better regex...
replace = "{now:%Y %b %d}" "v{new_version}"

It should match this line in my man/man1/xdg-env.1:

.TH man 1 "2020 Jun 13" "v2.3.2" "xdg-env man page"

In the mean time, I have to manually update the date in my manpages. Obviously that's not difficult, but it is a step I tend to forget when I releasing a new version of my code.

deliberist avatar Jun 15 '20 23:06 deliberist

What do people use to achieve this without bump2version? Just an ad-hoc solution, or is there a packaged alternative?

AndreaCensi avatar Sep 26 '20 19:09 AndreaCensi

I do it manually in a commit right before running bump2version.

Gallaecio avatar Sep 30 '20 20:09 Gallaecio

Dates are useful to maintain a Changelog in Keep A Changelog format.

With my particular approach I generate a version like 2023.1.0 and add the current date like 2023-01-09

DXist avatar Jan 09 '23 15:01 DXist

I just found that this is supported via regex searches in bump-my-version. which looks to be this project's actively-maintained successor.

https://github.com/c4urself/bump2version/issues/268 https://github.com/callowayproject/bump-my-version/pull/39/files

MattF-NSIDC avatar Aug 14 '23 20:08 MattF-NSIDC

I appreciate being told about bump-my-version, but I fail to see how it solves this issue, at least at the moment. The problem is being able to get the current date as a replacement, not the use of regular expressions.

Gallaecio avatar Aug 21 '23 13:08 Gallaecio

This functionality requires one or two pieces, depending on what you want to do. If you want to change a date from one date to the current date, e.g. updating citation metadata with a release date, you need (1) find the line with the old date (which, in the original post of this thread, you demonstrated with a regex); (2) replace with the current date.

bump2version can do (2), but not (1), so it can be used for cases like inserting (not replacing) a date in a changelog. Before migrating to bump-my-version, my current project was achieving this with bump2version.

bump-my-version can do both (1) and (2), which enabled us to implement the citation metadata use case after migrating away from bump2version. This looks a lot like your example in the original post!

MattF-NSIDC avatar Aug 21 '23 16:08 MattF-NSIDC