c4urself / bump2version

Version-bump your software with a single command
https://pypi.python.org/pypi/bump2version
MIT License
1.06k stars 134 forks source link

Support dates in replace #133

Open Gallaecio opened 4 years ago

Gallaecio commented 4 years ago

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?

laurent-laporte-pro commented 4 years ago

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 <dark@fsociety.com>"
__credits__ = "(c) F. Society"

The help function would display:

[...]

VERSION
    0.11.0

DATE
    2020-06-10

AUTHOR
    Mr Robot <dark@fsociety.com>

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 ?

deliberist commented 4 years ago

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.

AndreaCensi commented 3 years ago

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

Gallaecio commented 3 years ago

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

DXist commented 1 year ago

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

MattF-NSIDC commented 1 year ago

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

Gallaecio commented 1 year ago

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.

MattF-NSIDC commented 1 year ago

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!