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

Multi-line replace doesn't work for lines starting with # #199

Open
marionlb opened this issue Feb 9, 2019 · 2 comments
Open

Multi-line replace doesn't work for lines starting with # #199

marionlb opened this issue Feb 9, 2019 · 2 comments

Comments

@marionlb
Copy link

marionlb commented Feb 9, 2019

Using python 3.6 and bumpversion v0.5.3.

Great tool!

Summary

  1. There seems to be no way to escape the # character to avoid the line being treated as a comment
  2. Using \n in the replace field does not replace the sequence with a newline but with the literal \n

Detail

The following blurb in .bumpversion.cfg should replace the ## vNEXT header in the CHANGELOG.md file with the same header, a new line and a ## v{new_version} line.

[bumpversion:file:CHANGELOG.md]
search = ## vNEXT
replace = ## vNEXT 

  ## v{new_version}

However the CHANGELOG file is not modified and the 2nd and 3rd lines of the replace field in the .bumpversion.cfg file are deleted.

The same .bumpversion.cfg section after running bumpversion minor --no-tag:

[bumpversion:file:CHANGELOG.md]
search = ## vNEXT
replace = ## vNEXT

It's not a multi-line problem since using * instead of # works as expected, e.g. with the following:

[bumpversion:file:CHANGELOG.md]
search = ## vNEXT
replace = ## vNEXT 

  **v{new_version}**

I've tried escaping the # using \# to but that writes the actual \#\# characters in the CHANGELOG.

replace = ## vNEXT

  \#\# v{new_version}

I've tried using a single-line replace with \n for the new line but as before, the actual character \n is what appears in the CHANGELOG.

replace = ## vNEXT \n## v{new_version}

I've tried using {\n} instead but that just raises a KeyError: '\\n'.

Full log:

$ bumpversion --verbose minor --no-tag
Reading config file .bumpversion.cfg:
[bumpversion]
commit = True
tag = True
current_version = 3.6-dev
parse = (?P<major>\d+)\.(?P<minor>\d+)(\-(?P<release>[a-z]+))?
serialize =
	{major}.{minor}-{release}
	{major}.{minor}

[bumpversion:file:src/__init__.py]

[bumpversion:file:CHANGELOG.md]
search = ## vNEXT
replace = ## vNEXT

  ## v{new_version}

[bumpversion:part:release]
optional_value = gamma
values =
	dev
	gamma

Parsing version '3.6-dev' using regexp '(?P<major>\d+)\.(?P<minor>\d+)(\-(?P<release>[a-z]+))?'
Parsed the following values: major=3, minor=6, release=dev
Attempting to increment part 'minor'
Values are now: major=3, minor=7, release=dev
Parsing version '3.7-dev' using regexp '(?P<major>\d+)\.(?P<minor>\d+)(\-(?P<release>[a-z]+))?'
Parsed the following values: major=3, minor=7, release=dev
New version will be '3.7-dev'
Asserting files src/__init__.py, CHANGELOG.md contain the version string:
Found '3.6-dev' in src/__init__.py at line 0: __version__ = "3.6-dev"
Found '## vNEXT' in CHANGELOG.md at line 2: ## vNEXT
Changing file src/__init__.py:
--- a/src/__init__.py
+++ b/src/__init__.py
@@ -1 +1 @@
-__version__ = "3.6-dev"
+__version__ = "3.7-dev"
Not changing file CHANGELOG.md
Writing to config file .bumpversion.cfg:
[bumpversion]
commit = True
tag = True
current_version = 3.7-dev
parse = (?P<major>\d+)\.(?P<minor>\d+)(\-(?P<release>[a-z]+))?
serialize =
	{major}.{minor}-{release}
	{major}.{minor}

[bumpversion:file:src/__init__.py]

[bumpversion:file:CHANGELOG.md]
search = ## vNEXT
replace = ## vNEXT

[bumpversion:part:release]
optional_value = gamma
values =
	dev
	gamma


Preparing Git commit
Adding changes in file 'src/__init__.py' to Git
Adding changes in file 'CHANGELOG.md' to Git
Adding changes in file '.bumpversion.cfg' to Git
Committing to Git with message 'Bump version: 3.6-dev → 3.7-dev'
Would tag 'v3.7-dev' in Git
@jaredsampson
Copy link

I've run into the same issue. Trying to adopt the CHANGELOG.md format from Keep A Changelog and using Markdown headings to delineate versions.

For the time being, I'm using the following as a workaround:

[bumpversion:file:CHANGELOG.md]
search = ## [Unreleased]
replace = ## [Unreleased]
	-
	-## [v{new_version}]

and will plan to simply delete the leading dash manually upon the next edit.

@ichrysou
Copy link

ichrysou commented Jun 23, 2023

This seems to be due to configparser module used by bumpversion. configparser kindly discards all new lines in the replace string beginning with # as comments. For "Keep a Changelog" to be supported as is, one might need a remedy for that.

StuartMacKay added a commit to StuartMacKay/django-daterange-filterspec that referenced this issue Oct 23, 2023
The # in Markdown gets treated as a comment so there is no way to
do multiline search/replace. As a result only a single line with
the version number is replaced. The # Latest headline will have to
be added manually on the next set of changes.

See peritus/bumpversion#199
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants