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

Allow using special char #135

Merged
merged 1 commit into from Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion bumpversion/cli.py
Expand Up @@ -56,6 +56,7 @@
logger_list = logging.getLogger("bumpversion.list")
logger = logging.getLogger(__name__)
time_context = {"now": datetime.now(), "utcnow": datetime.utcnow()}
special_char_context = {c: c for c in ("#", ";")}


OPTIONAL_ARGUMENTS_THAT_TAKE_VALUES = [
Expand Down Expand Up @@ -93,7 +94,12 @@ def main(original_args=None):
version_config = _setup_versionconfig(known_args, part_configs)
current_version = version_config.parse(known_args.current_version)
context = dict(
itertools.chain(time_context.items(), prefixed_environ().items(), vcs_info.items())
itertools.chain(
time_context.items(),
prefixed_environ().items(),
vcs_info.items(),
special_char_context.items(),
)
)

# calculate the desired new version
Expand Down Expand Up @@ -666,6 +672,7 @@ def _commit_to_vcs(files, context, config_file, config_file_exists, vcs, args,
context.update(prefixed_environ())
context.update({'current_' + part: current_version[part].value for part in current_version})
context.update({'new_' + part: new_version[part].value for part in new_version})
context.update(special_char_context)

commit_message = args.message.format(**context)

Expand Down
31 changes: 27 additions & 4 deletions tests/test_cli.py
Expand Up @@ -1619,6 +1619,18 @@ def test_search_replace_to_avoid_updating_unconcerned_lines(tmpdir):
tmpdir.chdir()

tmpdir.join("requirements.txt").write("Django>=1.5.6,<1.6\nMyProject==1.5.6")
tmpdir.join("CHANGELOG.md").write(dedent("""
# https://keepachangelog.com/en/1.0.0/

## [Unreleased]
### Added
- Foobar

## [0.0.1] - 2014-05-31
### Added
- This CHANGELOG file to hopefully serve as an evolving example of a
standardized open source project CHANGELOG.
"""))

tmpdir.join(".bumpversion.cfg").write(dedent("""
[bumpversion]
Expand All @@ -1627,30 +1639,41 @@ def test_search_replace_to_avoid_updating_unconcerned_lines(tmpdir):
[bumpversion:file:requirements.txt]
search = MyProject=={current_version}
replace = MyProject=={new_version}

[bumpversion:file:CHANGELOG.md]
search = {#}{#} [Unreleased]
replace = {#}{#} [Unreleased]

{#}{#} [{new_version}] - {utcnow:%Y-%m-%d}
""").strip())

with LogCapture() as log_capture:
main(['minor', '--verbose'])

utc_today = datetime.utcnow().strftime("%Y-%m-%d")

log_capture.check(
('bumpversion.cli', 'INFO', 'Reading config file .bumpversion.cfg:'),
('bumpversion.cli', 'INFO', '[bumpversion]\ncurrent_version = 1.5.6\n\n[bumpversion:file:requirements.txt]\nsearch = MyProject=={current_version}\nreplace = MyProject=={new_version}'),
('bumpversion.cli', 'INFO', '[bumpversion]\ncurrent_version = 1.5.6\n\n[bumpversion:file:requirements.txt]\nsearch = MyProject=={current_version}\nreplace = MyProject=={new_version}\n\n[bumpversion:file:CHANGELOG.md]\nsearch = {#}{#} [Unreleased]\nreplace = {#}{#} [Unreleased]\n\n {#}{#} [{new_version}] - {utcnow:%Y-%m-%d}'),
('bumpversion.version_part', 'INFO', "Parsing version '1.5.6' using regexp '(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)'"),
('bumpversion.version_part', 'INFO', 'Parsed the following values: major=1, minor=5, patch=6'),
('bumpversion.cli', 'INFO', "Attempting to increment part 'minor'"),
('bumpversion.cli', 'INFO', 'Values are now: major=1, minor=6, patch=0'),
('bumpversion.version_part', 'INFO', "Parsing version '1.6.0' using regexp '(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)'"),
('bumpversion.version_part', 'INFO', 'Parsed the following values: major=1, minor=6, patch=0'),
('bumpversion.cli', 'INFO', "New version will be '1.6.0'"),
('bumpversion.cli', 'INFO', 'Asserting files requirements.txt contain the version string...'),
('bumpversion.cli', 'INFO', 'Asserting files requirements.txt, CHANGELOG.md contain the version string...'),
('bumpversion.utils', 'INFO', "Found 'MyProject==1.5.6' in requirements.txt at line 1: MyProject==1.5.6"),
('bumpversion.utils', 'INFO', "Found '## [Unreleased]' in CHANGELOG.md at line 3: ## [Unreleased]"),
('bumpversion.utils', 'INFO', 'Changing file requirements.txt:'),
('bumpversion.utils', 'INFO', '--- a/requirements.txt\n+++ b/requirements.txt\n@@ -1,2 +1,2 @@\n Django>=1.5.6,<1.6\n-MyProject==1.5.6\n+MyProject==1.6.0'),
('bumpversion.utils', 'INFO', 'Changing file CHANGELOG.md:'),
('bumpversion.utils', 'INFO', '--- a/CHANGELOG.md\n+++ b/CHANGELOG.md\n@@ -2,6 +2,8 @@\n # https://keepachangelog.com/en/1.0.0/\n \n ## [Unreleased]\n+\n+## [1.6.0] - %s\n ### Added\n - Foobar\n ' % utc_today),
('bumpversion.list', 'INFO', 'current_version=1.5.6'),
('bumpversion.list', 'INFO', 'new_version=1.6.0'),
('bumpversion.cli', 'INFO', 'Writing to config file .bumpversion.cfg:'),
('bumpversion.cli', 'INFO', '[bumpversion]\ncurrent_version = 1.6.0\n\n[bumpversion:file:requirements.txt]\nsearch = MyProject=={current_version}\nreplace = MyProject=={new_version}\n\n')
)
('bumpversion.cli', 'INFO', '[bumpversion]\ncurrent_version = 1.6.0\n\n[bumpversion:file:requirements.txt]\nsearch = MyProject=={current_version}\nreplace = MyProject=={new_version}\n\n[bumpversion:file:CHANGELOG.md]\nsearch = {#}{#} [Unreleased]\nreplace = {#}{#} [Unreleased]\n\t\n\t{#}{#} [{new_version}] - {utcnow:%Y-%m-%d}\n\n')
)

assert 'MyProject==1.6.0' in tmpdir.join("requirements.txt").read()
assert 'Django>=1.5.6' in tmpdir.join("requirements.txt").read()
Expand Down