Skip to content

Commit

Permalink
feat(config_files): add suport for "cz.toml" config file
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosdotme authored and Lee-W committed May 22, 2024
1 parent 642fe8c commit 4bf8ca6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions commitizen/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Settings(TypedDict, total=False):
"cz.json",
".cz.yaml",
"cz.yaml",
"cz.toml",
]
encoding: str = "utf-8"

Expand Down
4 changes: 2 additions & 2 deletions docs/commands/bump.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
27 changes: 20 additions & 7 deletions tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,31 +214,44 @@ 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()

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)


Expand Down

0 comments on commit 4bf8ca6

Please sign in to comment.