fix gitlab #14 - parse tool.bumpver when using pyproject.toml

This commit is contained in:
Manuel Barkhau 2020-11-01 18:22:19 +00:00
parent 2336bc7ca0
commit 15c7ea00df
4 changed files with 34 additions and 8 deletions

View file

@ -1,11 +1,13 @@
# Changelog for https://github.com/mbarkhau/pycalver
## BumpVer 2020.1105-beta
## BumpVer 2020.1104-beta
- Fix [gitlab#13][gitlab_i13]: Add `--set-version=<VERSION>` to explicitly set version.
- Fix [gitlab#14][gitlab_i14]: Parse `tool.bumpver` when using pyproject.toml as per PEP 518.
[gitlab_i13]:https://gitlab.com/mbarkhau/pycalver/-/issues/13
[gitlab_i13]: https://gitlab.com/mbarkhau/pycalver/-/issues/13
[gitlab_i14]: https://gitlab.com/mbarkhau/pycalver/-/issues/14
## BumpVer 2020.1100-beta

View file

@ -213,7 +213,9 @@ def _parse_toml(cfg_buffer: typ.IO[str]) -> RawConfig:
raw_full_cfg: typ.Any = toml.load(cfg_buffer)
raw_cfg : RawConfig
if 'bumpver' in raw_full_cfg:
if 'tool' in raw_full_cfg and 'bumpver' in raw_full_cfg['tool']:
raw_cfg = raw_full_cfg['tool']['bumpver']
elif 'bumpver' in raw_full_cfg:
raw_cfg = raw_full_cfg['bumpver']
elif 'pycalver' in raw_full_cfg:
raw_cfg = raw_full_cfg['pycalver']
@ -385,6 +387,8 @@ def _parse_current_version_default_pattern(raw_cfg: RawConfig, raw_cfg_text: str
is_config_section = True
elif line.strip() == "[bumpver]":
is_config_section = True
elif line.strip() == "[tool.bumpver]":
is_config_section = True
elif line and line[0] == "[" and line[-1] == "]":
is_config_section = False
@ -497,7 +501,20 @@ README.md =
""".lstrip()
DEFAULT_TOML_BASE_TMPL = """
DEFAULT_PYPROJECT_TOML_BASE_TMPL = """
[tool.bumpver]
current_version = "{initial_version}"
version_pattern = "YYYY.BUILD[-TAG]"
commit_message = "bump version {{old_version}} -> {{new_version}}"
commit = true
tag = true
push = true
[tool.bumpver.file_patterns]
""".lstrip()
DEFAULT_BUMPVER_TOML_BASE_TMPL = """
[bumpver]
current_version = "{initial_version}"
version_pattern = "YYYY.BUILD[-TAG]"
@ -576,7 +593,10 @@ def default_config(ctx: ProjectContext) -> str:
"README.md" : DEFAULT_CONFIGPARSER_README_MD_STR,
}
elif fmt == 'toml':
base_tmpl = DEFAULT_TOML_BASE_TMPL
if ctx.config_filepath.name == "pyproject.toml":
base_tmpl = DEFAULT_PYPROJECT_TOML_BASE_TMPL
else:
base_tmpl = DEFAULT_BUMPVER_TOML_BASE_TMPL
default_pattern_strs_by_filename = {
"pyproject.toml": DEFAULT_TOML_PYPROJECT_STR,

View file

@ -1,4 +1,4 @@
[bumpver]
[tool.bumpver]
current_version = "v2017q1.54321"
version_pattern = "v{year}q{quarter}.{build_no}"
commit = true

View file

@ -299,7 +299,9 @@ def test_novcs_nocfg_init(runner, caplog):
with pl.Path("bumpver.toml").open(mode="r", encoding="utf-8") as fobj:
cfg_content = fobj.read()
base_str = config.DEFAULT_TOML_BASE_TMPL.format(initial_version=config._initial_version())
base_str = config.DEFAULT_BUMPVER_TOML_BASE_TMPL.format(
initial_version=config._initial_version()
)
assert base_str in cfg_content
assert config.DEFAULT_TOML_README_MD_STR in cfg_content
@ -348,7 +350,9 @@ def test_novcs_pyproject_init(runner, caplog):
with pl.Path("pyproject.toml").open(mode="r", encoding="utf-8") as fobj:
cfg_content = fobj.read()
base_str = config.DEFAULT_TOML_BASE_TMPL.format(initial_version=config._initial_version())
base_str = config.DEFAULT_PYPROJECT_TOML_BASE_TMPL.format(
initial_version=config._initial_version()
)
assert base_str in cfg_content
assert config.DEFAULT_TOML_README_MD_STR in cfg_content