add config parameter: commit_message

This commit is contained in:
Manuel Barkhau 2020-09-18 19:34:51 +00:00
parent 7febf195ae
commit a8e658d1c4
4 changed files with 102 additions and 53 deletions

View file

@ -392,15 +392,13 @@ def bump(
if dry:
return
# # TODO (mb 2020-09-05): format from config
# commit_message_kwargs = {
# new_version
# old_version
# pep440_new_version
# pep440_old_version
# }
# cfg.commit_message =
commit_message = f"bump version to {new_version}"
commit_message_kwargs = {
'new_version' : new_version,
'old_version' : old_version,
'new_version_pep440': v1version.to_pep440(new_version),
'old_version_pep440': v1version.to_pep440(old_version),
}
commit_message = cfg.commit_message.format(**commit_message_kwargs)
_try_bump(cfg, new_version, commit_message, allow_dirty)

View file

@ -23,6 +23,8 @@ PatternsByGlob = typ.Dict[str, Patterns]
SUPPORTED_CONFIGS = ["setup.cfg", "pyproject.toml", "pycalver.toml"]
DEFAULT_COMMIT_MESSAGE = "bump version to {new_version}"
class ProjectContext(typ.NamedTuple):
"""Container class for project info."""
@ -78,6 +80,7 @@ class Config(typ.NamedTuple):
current_version: str
version_pattern: str
pep440_version : str
commit_message : str
commit: bool
tag : bool
@ -92,6 +95,7 @@ def _debug_str(cfg: Config) -> str:
f"current_version='{cfg.current_version}'",
"version_pattern='{pycalver}'",
f"pep440_version='{cfg.pep440_version}'",
f"commit_message='{cfg.commit_message}'",
f"commit={cfg.commit}",
f"tag={cfg.tag}",
f"push={cfg.push}",
@ -238,6 +242,8 @@ def _parse_config(raw_cfg: RawConfig) -> Config:
version_pattern: str = raw_cfg.get('version_pattern', "{pycalver}")
version_pattern = raw_cfg['version_pattern'] = version_pattern.strip("'\" ")
commit_message: str = raw_cfg.get('commit_message', DEFAULT_COMMIT_MESSAGE)
commit_message = raw_cfg['commit_message'] = commit_message.strip("'\" ")
# NOTE (mb 2019-01-05): Provoke ValueError if version_pattern
# and current_version are not compatible.
version.parse_version_info(version_str, version_pattern)
@ -265,6 +271,7 @@ def _parse_config(raw_cfg: RawConfig) -> Config:
current_version=version_str,
version_pattern=version_pattern,
pep440_version=pep440_version,
commit_message=commit_message,
commit=commit,
tag=tag,
push=push,
@ -333,6 +340,7 @@ DEFAULT_CONFIGPARSER_BASE_TMPL = """
[pycalver]
current_version = "{initial_version}"
version_pattern = "{{pycalver}}"
commit_message = "bump version to {{new_version}}"
commit = True
tag = True
push = True
@ -372,6 +380,7 @@ DEFAULT_TOML_BASE_TMPL = """
[pycalver]
current_version = "{initial_version}"
version_pattern = "{{pycalver}}"
commit_message = "bump version to {{new_version}}"
commit = true
tag = true
push = true

View file

@ -33,7 +33,7 @@ VCS_SUBCOMMANDS_BY_NAME = {
'ls_tags' : "git tag --list",
'status' : "git status --porcelain",
'add_path' : "git add --update {path}",
'commit' : "git commit --file {path}",
'commit' : "git commit --message '{message}'",
'tag' : "git tag --annotate {tag} --message {tag}",
'push_tag' : "git push origin --follow-tags {tag}",
'show_remotes': "git config --get remote.origin.url",
@ -144,20 +144,25 @@ class VCSAPI:
def commit(self, message: str) -> None:
"""Commit added files."""
message_data = message.encode("utf-8")
tmp_file = tempfile.NamedTemporaryFile("wb", delete=False)
assert " " not in tmp_file.name
fobj: typ.IO[bytes]
with tmp_file as fobj:
fobj.write(message_data)
env: Env = os.environ.copy()
env['HGENCODING'] = "utf-8"
self('commit', env=env, path=tmp_file.name)
os.unlink(tmp_file.name)
if self.name == 'git':
self('commit', env=env, message=message)
else:
message_data = message.encode("utf-8")
tmp_file = tempfile.NamedTemporaryFile("wb", delete=False)
try:
assert " " not in tmp_file.name
fobj: typ.IO[bytes]
with tmp_file as fobj:
fobj.write(message_data)
env['HGENCODING'] = "utf-8"
self('commit', env=env, path=tmp_file.name)
finally:
os.unlink(tmp_file.name)
def tag(self, tag_name: str) -> None:
"""Create an annotated tag."""