Skip to content

Commit 4bf8ca6

Browse files
marcosdotmeLee-W
authored andcommitted
feat(config_files): add suport for "cz.toml" config file
1 parent 642fe8c commit 4bf8ca6

File tree

6 files changed

+28
-14
lines changed

6 files changed

+28
-14
lines changed

commitizen/defaults.py

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Settings(TypedDict, total=False):
6767
"cz.json",
6868
".cz.yaml",
6969
"cz.yaml",
70+
"cz.toml",
7071
]
7172
encoding: str = "utf-8"
7273

docs/commands/bump.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ regarding if the file is present or not in `version_files`.
408408

409409
Some examples
410410

411-
`pyproject.toml` or `.cz.toml`
411+
`pyproject.toml`, `.cz.toml` or `cz.toml`
412412

413413
```toml
414414
[tool.commitizen]
@@ -441,7 +441,7 @@ defaults to: `bump: version $current_version → $new_version`
441441

442442
Some examples
443443

444-
`pyproject.toml` or `.cz.toml`
444+
`pyproject.toml`, `.cz.toml` or `cz.toml`
445445

446446
```toml
447447
[tool.commitizen]

docs/config.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ Provide extra variables to the changelog template. [Read more][template-customiz
227227

228228
## Configuration file
229229

230-
### pyproject.toml or .cz.toml
230+
### pyproject.toml, .cz.toml or cz.toml
231231

232232
Default and recommended configuration format for a project.
233233
For a **python** project, we recommend adding an entry to your `pyproject.toml`.
234-
You can also create a `.cz.toml` file at the root of your project folder.
234+
You can also create a `.cz.toml` or `cz.toml` file at the root of your project folder.
235235

236236
Example configuration:
237237

@@ -339,7 +339,7 @@ Commitizen provides some version providers for some well known formats:
339339
!!! note
340340
The `scm` provider is meant to be used with `setuptools-scm` or any packager `*-scm` plugin.
341341

342-
An example in your `.cz.toml` would look like this:
342+
An example in your `.cz.toml` or `cz.toml` would look like this:
343343

344344
```toml
345345
[tool.commitizen]

docs/faq.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ They differ a bit in design, not sure if cz-js does any of this, but these are s
5757
- create custom rules, version bumps and changelog generation, by default we use the popular conventional commits (I think cz-js allows this).
5858
- single package, install one thing and it will work (cz-js is a monorepo, but you have to install different dependencies AFAIK)
5959
- pre-commit integration
60-
- works on any language project, as long as you create the `.cz.toml` file.
60+
- works on any language project, as long as you create the `.cz.toml` or `cz.toml` file.
6161

6262
Where do they cross paths?
6363

docs/getting_started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The assistant utility will help you set up everything
88
cz init
99
```
1010

11-
Alternatively, create a file `.cz.toml` in your project's directory.
11+
Alternatively, create a file `.cz.toml` or `cz.toml` in your project's directory.
1212

1313
```toml
1414
[tool.commitizen]

tests/test_conf.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -214,31 +214,44 @@ def test_load_empty_pyproject_toml_from_config_argument(_, tmpdir):
214214
config.read_cfg(filepath="./not_in_root/pyproject.toml")
215215

216216

217+
@pytest.mark.parametrize(
218+
"config_file, exception_string",
219+
[
220+
(".cz.toml", r"\.cz\.toml"),
221+
("cz.toml", r"cz\.toml"),
222+
("pyproject.toml", r"pyproject\.toml"),
223+
],
224+
ids=[".cz.toml", "cz.toml", "pyproject.toml"],
225+
)
217226
class TestTomlConfig:
218-
def test_init_empty_config_content(self, tmpdir):
219-
path = tmpdir.mkdir("commitizen").join(".cz.toml")
227+
def test_init_empty_config_content(self, tmpdir, config_file, exception_string):
228+
path = tmpdir.mkdir("commitizen").join(config_file)
220229
toml_config = config.TomlConfig(data="", path=path)
221230
toml_config.init_empty_config_content()
222231

223232
with open(path, encoding="utf-8") as toml_file:
224233
assert toml_file.read() == "[tool.commitizen]\n"
225234

226-
def test_init_empty_config_content_with_existing_content(self, tmpdir):
235+
def test_init_empty_config_content_with_existing_content(
236+
self, tmpdir, config_file, exception_string
237+
):
227238
existing_content = "[tool.black]\n" "line-length = 88\n"
228239

229-
path = tmpdir.mkdir("commitizen").join(".cz.toml")
240+
path = tmpdir.mkdir("commitizen").join(config_file)
230241
path.write(existing_content)
231242
toml_config = config.TomlConfig(data="", path=path)
232243
toml_config.init_empty_config_content()
233244

234245
with open(path, encoding="utf-8") as toml_file:
235246
assert toml_file.read() == existing_content + "\n[tool.commitizen]\n"
236247

237-
def test_init_with_invalid_config_content(self, tmpdir):
248+
def test_init_with_invalid_config_content(
249+
self, tmpdir, config_file, exception_string
250+
):
238251
existing_content = "invalid toml content"
239-
path = tmpdir.mkdir("commitizen").join(".cz.toml")
252+
path = tmpdir.mkdir("commitizen").join(config_file)
240253

241-
with pytest.raises(InvalidConfigurationError, match=r"\.cz\.toml"):
254+
with pytest.raises(InvalidConfigurationError, match=exception_string):
242255
config.TomlConfig(data=existing_content, path=path)
243256

244257

0 commit comments

Comments
 (0)