peritus / bumpversion

Version-bump your software with a single command
https://pypi.python.org/pypi/bumpversion
MIT License
1.5k stars 147 forks source link

Support search= with newlines #103

Open buhtz opened 9 years ago

buhtz commented 9 years ago

I am new to bumpversion. When I understand it right, it is only possbile to search for complete version strings, right?

Isn't it possible to handle code like this?

_APPVER_MAJOR = 0
_APPVER_MINOR = 0
_APPVER_REVISION = 1
peritus commented 9 years ago

You could view the above snippet as a complete version string that just happens to be contain newlines :)

I have no idea whether that works with bumpversion now, but in theory that could work.

buhtz commented 9 years ago

Sorry, I don't understand what you mean.

thomasf commented 9 years ago

Just try to define multi line regexps and see if that works.

peritus commented 8 years ago

Ok, so this is how it could work:

vars.py

_APPVER_MAJOR = 0
_APPVER_MINOR = 0
_APPVER_REVISION = 1

.bumpversion.cfg

current_version = 0.0.1

[bumpversion:file:vars.py]
parse = _APPVER_MAJOR = (?P<major>\d+)\n_APPVER_MINOR = (?P<minor>\d+)\n_APPVER_REVISION = (?P<patch>\d+)
serialize = _APPVER_MAJOR = {major}\n_APPVER_MINOR = {minor}\n_APPVER_REVISION = {patch}

However, when executing that, search doesn't support multiline yet:

$> bumpversion major --v
Reading config file .bumpversion.cfg:
[bumpversion]
current_version = 0.0.1

[bumpversion:file:vars.py]
parse = _APPVER_MAJOR = (?P<major>\d+)\n_APPVER_MINOR = (?P<minor>\d+)\n_APPVER_REVISION = (?P<patch>\d+)
serialize = _APPVER_MAJOR = {major}\n_APPVER_MINOR = {minor}\n_APPVER_REVISION = {patch}

Parsing version '0.0.1' using regexp '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)'
Parsed the following values: major=0, minor=0, patch=1
Attempting to increment part 'major'
Values are now: major=1, minor=0, patch=0
Parsing version '1.0.0' using regexp '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)'
Parsed the following values: major=1, minor=0, patch=0
New version will be '1.0.0'
Asserting files vars.py contain the version string:
Traceback (most recent call last):
  File "/usr/local/bin/bumpversion", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/bumpversion/__init__.py", line 912, in main
    f.should_contain_version(current_version, context)
  File "/usr/local/lib/python2.7/dist-packages/bumpversion/__init__.py", line 208, in should_contain_version
    assert self.contains(version.original), msg
AssertionError: Did not find '0.0.1' or '_APPVER_MAJOR = 0\n_APPVER_MINOR = 0\n_APPVER_REVISION = 1' in file vars.py

but it should.

luckydonald commented 8 years ago

Maybe \ at the end of a line, to escape the invisible newline character?

search = _APPVER_MAJOR = 0\
_APPVER_MINOR = 0\
_APPVER_REVISION = 1

Or, wrap text quotes or something similar. So you can explicitly include newlines.

search = "_APPVER_MAJOR = 0
_APPVER_MINOR = 0
_APPVER_REVISION = 1"

Maybe it is another problem, but the current config doesn't need quotes, they even get striped. With that you can't search for "1.0.1" with leaving 1.0.1 alone.