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

Use of RawConfigParser makes some configurations impossible to represent #99

Closed jbweston closed 4 years ago

jbweston commented 4 years ago

I am trying to use bump2version to replace a section in a markdown-formatted changelog file when the version is bumped. I want to make the following change:

## [unreleased]
...

goes to

## [unreleased]

## [{new_version}]
...

I have added the following section to .bumpversion.cfg:

[bumpversion:file:CHANGELOG.md]
search = ## [unreleased]
replace = ## [unreleased]
  ## [{new_version}]

This does not work because the final line is interpreted as a comment. The configparser docs note that this is a possibility in the following sentence:

In any circumstances, the only way of storing comment prefix characters at the beginning of a line in multiline values is to interpolate the prefix, for example:

The only way to avoid this is to use a interpolation in .bumpversion.cfg like:

[bumpversion:file:CHANGELOG.md]
h2 = ##
search = %(h2) [unreleased]
replace = %(h2) [unreleased]
  %(h2) [{new_version}]

However bump2version uses a RawConfigParser, and variable substitution is disabled.

Is there a particular reason to use a RawConfigParser over ConfigParser? As far as I understand the ConfigParser's interpolation would not clash with the value interpolation that bump2version uses later because the syntaxes are different (%(...) and ${...} vs {...}).

florisla commented 4 years ago

It seems bump2version uses RawConfigParser for the .bumpversion.cfg file, and uses regular ConfigParser for setup.cfg. Regardless of the reason, it must remain that way for backwards compatibility.

E.g. in setup.cfg values you have to escape % to %%, whereas in .bumpversion.cfg that's not necessary.

Perhaps it's an option to move your configuration to setup.cfg ?

jbweston commented 4 years ago

Ideally I would have preferred to keep the config for bumpversion in it's own file, but if this won't be changed then I'll make do.

Thanks!

FlorianLudwig commented 4 years ago

@jbweston I had the same use case as you but couldn't get it working. I am getting:

TypeError: __init__() got an unexpected keyword argument 'h2'
florisla commented 4 years ago

@FlorianLudwig Are you doing this in setup.cfg? Because it can't work in .bumpversion.cfg.

FlorianLudwig commented 4 years ago

@florisla yes