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

added option to disable comments in config files #221

Closed
wants to merge 7 commits into from
Closed

added option to disable comments in config files #221

wants to merge 7 commits into from

Conversation

manfred-kaiser
Copy link

@manfred-kaiser manfred-kaiser commented Jul 14, 2021

I'm using bum2version to update my changelog. This changelog uses markdown and headers are defined by a multiple of #
The ConfigParser's default settings is, that # and ; are used as comment prefix.

This pull request introduces a new command line argument --disable-config-comments. When this argument is used, the comment prefixes for the config parser are set to None. This allows using # in multiline search and replace options.

Example Changelog:

## [Unreleased]

### Added

- new config option

## [0.5.12] - 2021-07-13

### Fixed

- handle subsystem errors in sftp server

[Unreleased]: https://github.com/ssh-mitm/ssh-mitm/compare/0.5.12...develop
[0.5.12]: https://github.com/ssh-mitm/ssh-mitm/compare/0.5.11...0.5.12

I want to use bump2version to update ## [Unreleased] to the current version and the link [Unreleased]: https://github.com/ssh-mitm/ssh-mitm/compare/0.5.12...develop to match the latest version. bum2version should also add a new unreleased link, so there is no need to add it after a version update.

Used config file:

[bumpversion]
current_version = 0.5.12

[bumpversion:file (compare vesions):CHANGELOG.md]
search = [Unreleased]: https://github.com/ssh-mitm/ssh-mitm/compare/{current_version}...develop
replace = [Unreleased]: https://github.com/ssh-mitm/ssh-mitm/compare/{new_version}...develop
	[{new_version}]: https://github.com/ssh-mitm/ssh-mitm/compare/{current_version}...{new_version}

[bumpversion:file (release changes):CHANGELOG.md]
search = ## [Unreleased]
replace = ## [Unreleased]
	
	## [{new_version}] - {now:%Y-%m-%d}

Without disabling the comment prefixes, the line ## [{current_version}] - {now:%Y-%m-%d} will be removed, because of the # at the beginning, which will interpreted as comment.

When the new argument --disable-config-comments is used it works as expected.

Updated Changelog:

## [Unreleased]

## [0.5.13] - 2021-07-14

### Added

- new config option

## [0.5.12] - 2021-07-13

### Fixed

- handle subsystem errors in sftp server

[Unreleased]: https://github.com/ssh-mitm/ssh-mitm/compare/0.5.13...develop
[0.5.13]: https://github.com/ssh-mitm/ssh-mitm/compare/0.5.12...0.5.13
[0.5.12]: https://github.com/ssh-mitm/ssh-mitm/compare/0.5.11...0.5.12

@florisla
Copy link
Collaborator

I think this is a sensible feature to support comment characters. The alternative would be to replace keywords such as {hash} with a comment character #.

This will require a thorough review though.

@manfred-kaiser
Copy link
Author

I know, that the new option can break config files, when you are using comments as values.
If you forgot the new argument, second line will be interpreted as a comment. This is getting more worse, if you are using auto commit.

As an alternative, it's possible to use a wrapper script:

from configparser import ConfigParser, RawConfigParser
from bumpversion.cli import main

@property
def comment_prefixes(self):
    return ()

@comment_prefixes.setter
def comment_prefixes(self, value):
    pass

RawConfigParser._comment_prefixes = comment_prefixes
ConfigParser._comment_prefixes = comment_prefixes

main()

@hukkin
Copy link

hukkin commented Jul 21, 2021

An alternative proposal: How about allowing configuration in .bumpversion.toml (and preferring that over the cfg file if it exists, perhaps slowly deprecating the cfg)?

TOML overcomes this and other flaws of the ini format that lacks specification.

@hukkin
Copy link

hukkin commented Jul 21, 2021

An added note: tbump (mentioned in RELATED.md uses a tbump.toml so should already be able to do what OP wants.

EDIT: or perhaps not, haven't used it 😄 the conf structure seems to be different from bumpversion

@FredM
Copy link

FredM commented May 30, 2022

I had the same issue but it can be alleviated by using {#} each time you need to represent # in a multiline comment. In the initial example this would give (first line can be omitted):

[bumpversion:file (release changes):CHANGELOG.md]
search = ## [Unreleased]
replace = ## [Unreleased]
	
	{#}{#} [{new_version}] - {now:%Y-%m-%d}

I found the mention of it in this thread: #199

@manfred-kaiser
Copy link
Author

I had the same issue but it can be alleviated by using {#} each time you need to represent # in a multiline comment. In the initial example this would give (first line can be omitted):

[bumpversion:file (release changes):CHANGELOG.md]
search = ## [Unreleased]
replace = ## [Unreleased]
	
	{#}{#} [{new_version}] - {now:%Y-%m-%d}

I found the mention of it in this thread: #199

@FredM thanks for the solution, this is the better option to work with markdown files 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants