Skip to content

Commit

Permalink
support glob keyword in configfile
Browse files Browse the repository at this point in the history
  • Loading branch information
balrok authored and Carl Mai committed Jul 23, 2020
1 parent 565dd9a commit a96ebf4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -296,7 +296,11 @@ values =

### Configuration file -- File specific configuration

This configuration is in the section: `[bumpversion:file:…]`
This configuration is in the section: `[bumpversion:file:…]` or `[bumpversion:glob:…]`

Both, `file:` and `glob:` are configured the same. Their difference is that
file will match file names directly like `requirements.txt`. While glob also
matches multiple files via wildcards like `**/pom.xml`.

Note: The configuration file format requires each section header to be
unique. If you want to process a certain file multiple times,
Expand Down
11 changes: 8 additions & 3 deletions bumpversion/cli.py
@@ -1,5 +1,6 @@
import argparse
from datetime import datetime
import glob
import io
import itertools
import logging
Expand Down Expand Up @@ -49,7 +50,7 @@
# bumpversion:file ( suffix with spaces):value
RE_DETECT_SECTION_TYPE = re.compile(
r"^bumpversion:"
r"((?P<file>file)(\s*\(\s*(?P<file_suffix>[^\):]+)\)?)?|(?P<part>part)):"
r"((?P<file>file|glob)(\s*\(\s*(?P<file_suffix>[^\):]+)\)?)?|(?P<part>part)):"
r"(?P<value>.+)",
)

Expand Down Expand Up @@ -353,8 +354,12 @@ def _load_configuration(config_file, explicit_config, defaults):
if "replace" not in section_config:
section_config["replace"] = defaults.get("replace", "{new_version}")

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

version_config = VersionConfig(**section_config)
if section_type.get("file") == "glob":
for filename_glob in glob.glob(filename):
files.append(ConfiguredFile(filename_glob, version_config))
else:
files.append(ConfiguredFile(filename, version_config))
return config, config_file_exists, config_newlines, part_configs, files


Expand Down
14 changes: 14 additions & 0 deletions tests/test_cli.py
Expand Up @@ -292,6 +292,20 @@ def test_default_config_files(tmpdir, configfile):
assert "0.10.3" == tmpdir.join("file2").read()


def test_glob_keyword(tmpdir, configfile):
tmpdir.join("file1.txt").write("0.9.34")
tmpdir.join("file2.txt").write("0.9.34")
tmpdir.join(configfile).write("""[bumpversion]
current_version: 0.9.34
new_version: 0.9.35
[bumpversion:glob:*.txt]""")

tmpdir.chdir()
main(["patch"])
assert "0.9.35" == tmpdir.join("file1.txt").read()
assert "0.9.35" == tmpdir.join("file2.txt").read()


def test_file_keyword_with_suffix_is_accepted(tmpdir, configfile, file_keyword):
tmpdir.join("file2").write("0.10.2")
tmpdir.join(configfile).write(
Expand Down

0 comments on commit a96ebf4

Please sign in to comment.