diff --git a/CHANGELOG.md b/CHANGELOG.md index e56b306..dd79370 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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=` 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 diff --git a/src/bumpver/config.py b/src/bumpver/config.py index 69ad6c6..52591e0 100644 --- a/src/bumpver/config.py +++ b/src/bumpver/config.py @@ -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, diff --git a/test/fixtures/project_c/pyproject.toml b/test/fixtures/project_c/pyproject.toml index 95b7f3b..6c6bbe2 100644 --- a/test/fixtures/project_c/pyproject.toml +++ b/test/fixtures/project_c/pyproject.toml @@ -1,4 +1,4 @@ -[bumpver] +[tool.bumpver] current_version = "v2017q1.54321" version_pattern = "v{year}q{quarter}.{build_no}" commit = true diff --git a/test/test_cli.py b/test/test_cli.py index 8a8b6b3..9d14602 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -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