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

Does not abort if `search` string is not found. #120

Open luckydonald opened 8 years ago

luckydonald commented 8 years ago

.bumpversion.cfg:

[bumpversion]
current_version = 0.4.2

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

setup.py:

setup(
    name='foobar',
    version="0.4.2",
    # and stuff
    install_requires=["something>=0.4.2"],
)

Now it does:

bumpversion patch --dry-run --verbose --allow-dirty
Reading config file .bumpversion.cfg:
[bumpversion]
current_version = 0.4.2

[bumpversion:file:setup.py]
search  = version="{current_version}""
replace = version="{new_version}"
Parsing version '0.4.2' using regexp '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)'
Parsed the following values: major=0, minor=4, patch=2
Attempting to increment part 'patch'
Values are now: major=0, minor=4, patch=3
Dry run active, won't touch any files.
Parsing version '0.4.3' using regexp '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)'
Parsed the following values: major=0, minor=4, patch=3
New version will be '0.4.3'
Asserting files setup.py contain the version string:
Found '0.4.2' in setup.py at line 2:    version="0.4.2",
Would change file setup.py:
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
 setup(
        name='foobar',
-       version="0.4.2",
+       version="version="0.4.3"",
        # and stuff
-       install_requires=["something>=0.4.2"],
+       install_requires=["something>=version="0.4.3""],
 )
Would write to config file .bumpversion.cfg:
[bumpversion]
current_version = 0.4.3

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

Would prepare Git commit
Would add changes in file 'setup.py' to Git
Would add changes in file '.bumpversion.cfg' to Git
Would commit to Git with message 'Bump version: 0.4.2 → 0.4.3'
Would tag 'v0.4.3' in Git
luckydonald commented 8 years ago

It changes the wrong part (install_requires=["something>=0.4.2"],) and also introduces an additional " quotes chatacter.

luckydonald commented 8 years ago

The reason probably is that my search was wrong, and not found. It should abort when the search string is not found!

Instead, currently it replaces all findings of the plain version number.

garyjohnson commented 8 years ago

This one just bit me hard. We're on an embedded project where the version number is a single decimal (i.e., 1-255) and we can't use semantic versioning because of it. Search failed and silently replaced all instances of the number "2" with the full replace string, totally mangling the file. If search fails I'd like an option to simply exit with a non-zero code (IMO this should be the default behavior). Happy to submit a pull request if you agree this is an appropriate solution, either by default or via a flag to stay backwards compatible. Since the replace string is used I can't imagine anyone would be relying on the current behavior.

luckydonald commented 8 years ago

I'm not sure if this project is still active...

garyjohnson commented 8 years ago

@peritus Are you still accepting pull requests and maintaining this project? Are you looking for any help with maintenance?

peritus commented 8 years ago

@garyjohnson Yes, still accepting pull requests on this one.

I currently don't have the time to, after pull requests to write tests for the submitted code, write docs for the submitted code, think the feature through to the end with regard to backward compatibility and future direction of this project / coaching people to submitting their first pull request etc.

Well tested / documented pull requests will be merged soonish, promise.

garyjohnson commented 8 years ago

Thanks for the clarification. Do you consider this behavior a bug or by design? That will inform how I handle the PR.

peritus commented 8 years ago

It's a bug. And yes, it should abort with a non-zero exit code.