c4urself / bump2version

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

How can I search and replace timestamp in setup.py? #212

Closed Sarute closed 2 years ago

Sarute commented 3 years ago
[bumpversion]
current_version = 4.1.2-alpha-20210414144038
commit = False
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?(\-(?P<build>\d+))?
serialize = {major}.{minor}.{patch}-{release}-{now:%Y%m%d%H%M%S}
    {major}.{minor}.{patch}-{release}-{now:%Y%m%d%H%M%S}
    {major}.{minor}.{patch}

[bumpversion:part:release]
optional_value = prod
values = 
    alpha
    beta
    prod

[bumpversion:part:build]

[bumpversion:file:setup.py]
search = version='{current_version}'
replace = `version='{new_version}'

When I execute: bump2version patch --allow-dirty

it says: bumpversion.exceptions.VersionNotFoundException: Did not find 'version='4.1.2-alpha-20210416102429'' in file: 'setup.py'

Is it searching the wrong version in the setup.py? Or do I parsing with wrong regex? current_version = 4.1.2-alpha-20210414144038 Did not find 'version='4.1.2-alpha-20210416102429'' in file: 'setup.py

Thank you

florisla commented 3 years ago

It looks like this should work.

But I see two weird things in the config. You have the serialize format {major}.{minor}.{patch}-{release}-{now:%Y%m%d%H%M%S} listed twice. The replace expression starts with a backtick.

Can you post the content of file setup.py? Perhaps you are using double quotes there?

Sarute commented 2 years ago

I've resolved updating the parse rule:

`[bumpversion] current_version = 1.0.5.18891-alpha-202109301426 commit = False tag = False parse = (?P\d+).(?P\d+).(?P\d+).(?P\d+)(-(?P[a-z]+))?(-(?P\d+))? serialize = {major}.{minor}.{patch}.{epoch}-{release}-{now:%Y%m%d%H%M} {major}.{minor}.{patch}

[bumpversion:part:release] optional_value = prod values = alpha beta prod

[bumpversion:part:epoch] values = 18891

[bumpversion:part:build]

[bumpversion:file:setup.py] parse = version=(?P\d+).(?P\d+).(?P\d+).(?P\d+)(-(?P[a-z]+))?(-(?P\d+))? replace = {new_version}`