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

Limit Replacements Option Support #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ include/
lib/
.Python
bumpversion.egg-info/
.python-version
__pycache__/
17 changes: 7 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
language: python

env:
- TOX_ENV=py27
- TOX_ENV=py27-configparser
- TOX_ENV=py32
- TOX_ENV=py33
- TOX_ENV=py34
- TOX_ENV=pypy
python:
- "2.7"
- "3.5"
- "3.6"
- "pypy3.5"
install:
- git config --global user.email "[email protected]"
- git config --global user.name "Testing Git on Travis CI"
- git --version
- git config --list
- echo -e '[ui]\nusername = Testing Mercurial on Travis CI <[email protected]>' > ~/.hgrc
- hg --version
- pip install --upgrade pytest tox
- pip install --upgrade pytest tox-travis

script:
- tox -e $TOX_ENV

- tox
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ File specific configuration
Can be multiple lines, templated using `Python Format String Syntax
<http://docs.python.org/2/library/string.html#format-string-syntax>`_.

``max_replace =``
**default:** ``-1``

How many replacements will be allowed in the given file.

Options
=======

Expand Down
8 changes: 6 additions & 2 deletions bumpversion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def replace(self, current_version, new_version, context, dry_run):
replace_with = self._versionconfig.replace.format(**context)

file_content_after = file_content_before.replace(
search_for, replace_with
search_for, replace_with, int(self._versionconfig.max_replace or -1)
)

if file_content_before == file_content_after:
Expand Down Expand Up @@ -340,7 +340,7 @@ class VersionConfig(object):
Holds a complete representation of a version string
"""

def __init__(self, parse, serialize, search, replace, part_configs=None):
def __init__(self, parse, serialize, search, replace, part_configs=None, max_replace=None):

try:
self.parse_regex = re.compile(parse, re.VERBOSE)
Expand All @@ -356,6 +356,7 @@ def __init__(self, parse, serialize, search, replace, part_configs=None):
self.part_configs = part_configs
self.search = search
self.replace = replace
self.max_replace = max_replace

def _labels_for_format(self, serialize_format):
return (
Expand Down Expand Up @@ -677,6 +678,9 @@ def main(original_args=None):
if not 'replace' in section_config:
section_config['replace'] = defaults.get("replace", '{new_version}')

if not 'max_replace' in section_config:
section_config['max_replace'] = defaults.get("max_replace", -1)

files.append(ConfiguredFile(filename, VersionConfig(**section_config)))

else:
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: PyPy',
),
)
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[tox]
envlist = py34, py33, py32, py27, py27-configparser, pypy
envlist = py36, py35, py27, py27-configparser, pypy3

[testenv]
passenv = HOME
deps=
distribute
pytest
mock
commands=
Expand Down