From 23206e1d06bf009614f2e26962e70a048b8730b8 Mon Sep 17 00:00:00 2001 From: Marcos Martins Date: Mon, 20 May 2024 18:34:43 -0300 Subject: [PATCH] feat(config_files): add suport for "cz.toml" config file --- commitizen/defaults.py | 1 + docs/commands/bump.md | 4 ++-- docs/config.md | 6 +++--- docs/faq.md | 2 +- docs/getting_started.md | 2 +- tests/test_conf.py | 27 ++++++++++++++++++++------- 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index a1651ebe8..75162619d 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -67,6 +67,7 @@ class Settings(TypedDict, total=False): "cz.json", ".cz.yaml", "cz.yaml", + "cz.toml", ] encoding: str = "utf-8" diff --git a/docs/commands/bump.md b/docs/commands/bump.md index 5f5590e88..4d370a6a1 100644 --- a/docs/commands/bump.md +++ b/docs/commands/bump.md @@ -408,7 +408,7 @@ regarding if the file is present or not in `version_files`. Some examples -`pyproject.toml` or `.cz.toml` +`pyproject.toml`, `.cz.toml` or `cz.toml` ```toml [tool.commitizen] @@ -441,7 +441,7 @@ defaults to: `bump: version $current_version → $new_version` Some examples -`pyproject.toml` or `.cz.toml` +`pyproject.toml`, `.cz.toml` or `cz.toml` ```toml [tool.commitizen] diff --git a/docs/config.md b/docs/config.md index 398c04533..210b5d7ff 100644 --- a/docs/config.md +++ b/docs/config.md @@ -227,11 +227,11 @@ Provide extra variables to the changelog template. [Read more][template-customiz ## Configuration file -### pyproject.toml or .cz.toml +### pyproject.toml, .cz.toml or cz.toml Default and recommended configuration format for a project. For a **python** project, we recommend adding an entry to your `pyproject.toml`. -You can also create a `.cz.toml` file at the root of your project folder. +You can also create a `.cz.toml` or `cz.toml` file at the root of your project folder. Example configuration: @@ -339,7 +339,7 @@ Commitizen provides some version providers for some well known formats: !!! note The `scm` provider is meant to be used with `setuptools-scm` or any packager `*-scm` plugin. -An example in your `.cz.toml` would look like this: +An example in your `.cz.toml` or `cz.toml` would look like this: ```toml [tool.commitizen] diff --git a/docs/faq.md b/docs/faq.md index 060de78c3..4bcb2bc7c 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -57,7 +57,7 @@ They differ a bit in design, not sure if cz-js does any of this, but these are s - create custom rules, version bumps and changelog generation, by default we use the popular conventional commits (I think cz-js allows this). - single package, install one thing and it will work (cz-js is a monorepo, but you have to install different dependencies AFAIK) - pre-commit integration -- works on any language project, as long as you create the `.cz.toml` file. +- works on any language project, as long as you create the `.cz.toml` or `cz.toml` file. Where do they cross paths? diff --git a/docs/getting_started.md b/docs/getting_started.md index 7ceba2bb6..81da513e0 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -8,7 +8,7 @@ The assistant utility will help you set up everything cz init ``` -Alternatively, create a file `.cz.toml` in your project's directory. +Alternatively, create a file `.cz.toml` or `cz.toml` in your project's directory. ```toml [tool.commitizen] diff --git a/tests/test_conf.py b/tests/test_conf.py index 786f12b36..2a5e727d8 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -214,19 +214,30 @@ def test_load_empty_pyproject_toml_from_config_argument(_, tmpdir): config.read_cfg(filepath="./not_in_root/pyproject.toml") +@pytest.mark.parametrize( + "config_file, exception_string", + [ + (".cz.toml", r"\.cz\.toml"), + ("cz.toml", r"cz\.toml"), + ("pyproject.toml", r"pyproject\.toml"), + ], + ids=[".cz.toml", "cz.toml", "pyproject.toml"], +) class TestTomlConfig: - def test_init_empty_config_content(self, tmpdir): - path = tmpdir.mkdir("commitizen").join(".cz.toml") + def test_init_empty_config_content(self, tmpdir, config_file, exception_string): + path = tmpdir.mkdir("commitizen").join(config_file) toml_config = config.TomlConfig(data="", path=path) toml_config.init_empty_config_content() with open(path, encoding="utf-8") as toml_file: assert toml_file.read() == "[tool.commitizen]\n" - def test_init_empty_config_content_with_existing_content(self, tmpdir): + def test_init_empty_config_content_with_existing_content( + self, tmpdir, config_file, exception_string + ): existing_content = "[tool.black]\n" "line-length = 88\n" - path = tmpdir.mkdir("commitizen").join(".cz.toml") + path = tmpdir.mkdir("commitizen").join(config_file) path.write(existing_content) toml_config = config.TomlConfig(data="", path=path) toml_config.init_empty_config_content() @@ -234,11 +245,13 @@ def test_init_empty_config_content_with_existing_content(self, tmpdir): with open(path, encoding="utf-8") as toml_file: assert toml_file.read() == existing_content + "\n[tool.commitizen]\n" - def test_init_with_invalid_config_content(self, tmpdir): + def test_init_with_invalid_config_content( + self, tmpdir, config_file, exception_string + ): existing_content = "invalid toml content" - path = tmpdir.mkdir("commitizen").join(".cz.toml") + path = tmpdir.mkdir("commitizen").join(config_file) - with pytest.raises(InvalidConfigurationError, match=r"\.cz\.toml"): + with pytest.raises(InvalidConfigurationError, match=exception_string): config.TomlConfig(data=existing_content, path=path)