From d944ac9c85b13d801ac15b6b3070cb9ffd155424 Mon Sep 17 00:00:00 2001 From: Kyle James Walker Date: Mon, 15 Oct 2018 14:05:38 -0700 Subject: [PATCH] Limit Replacements Option Support --- .gitignore | 2 ++ .travis.yml | 17 +++++++---------- README.rst | 5 +++++ bumpversion/__init__.py | 8 ++++++-- setup.py | 6 +++--- tox.ini | 3 +-- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 83b94e0..b05d9af 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ include/ lib/ .Python bumpversion.egg-info/ +.python-version +__pycache__/ diff --git a/.travis.yml b/.travis.yml index 13248d3..ce46f24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,10 @@ 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 "bumpversion-test-git@travis.ci" - git config --global user.name "Testing Git on Travis CI" @@ -14,8 +12,7 @@ install: - git config --list - echo -e '[ui]\nusername = Testing Mercurial on Travis CI ' > ~/.hgrc - hg --version - - pip install --upgrade pytest tox + - pip install --upgrade pytest tox-travis script: - - tox -e $TOX_ENV - + - tox diff --git a/README.rst b/README.rst index 3505557..eba4fc8 100644 --- a/README.rst +++ b/README.rst @@ -304,6 +304,11 @@ File specific configuration Can be multiple lines, templated using `Python Format String Syntax `_. +``max_replace =`` + **default:** ``-1`` + + How many replacements will be allowed in the given file. + Options ======= diff --git a/bumpversion/__init__.py b/bumpversion/__init__.py index 757e4f7..9d98507 100644 --- a/bumpversion/__init__.py +++ b/bumpversion/__init__.py @@ -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: @@ -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) @@ -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 ( @@ -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: diff --git a/setup.py b/setup.py index 349441f..4785dda 100644 --- a/setup.py +++ b/setup.py @@ -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', ), ) diff --git a/tox.ini b/tox.ini index 0f78c95..f4e1d50 100644 --- a/tox.ini +++ b/tox.ini @@ -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=