Skip to content

Pre-commit check fails when dependency group includes are used in pyproject.toml #1500

Open
@kiinami

Description

@kiinami

Description

When committing a pyproject.toml file that uses dependency group includes and the commitizen pre-commit hook, a tomlkit.exceptions.MixedArrayTypesError is raised, failing the check and preventing the commit.

This happens when using uv as dependency manager, I don't know about others.

Steps to reproduce

  1. Create a blank project with uv init cz-dgi and enter with cd cz-dgi
  2. Add the following pyproject.toml:
    [project]
    name = "czdgi"
    version = "0.1.0"
    description = "Add your description here"
    readme = "README.md"
    requires-python = ">=3.12"
    dependencies = [
        "commitizen>=4.8.2",
        "pre-commit>=4.2.0",
    ]
     
    [dependency-groups]
    nums = [
        "pandas>=2.2.3",
    ]
    test = [
        {include-group = "nums"},
        "pytest>=8.4.0",
    ]
  3. Create a .pre-commit-config.yaml with the following content:
       - pre-commit
       - commit-msg
     repos:
       - repo: https://github.com/commitizen-tools/commitizen
         rev: v1.17.0
         hooks:
           - id: commitizen
             stages: [ commit-msg ]
  4. Run uv run pre-commit install --install-hooks to install hooks
  5. Try to commit

Current behavior

The commit check fails with error:

commitizen check.........................................................Failed
- hook id: commitizen
- exit code: 1

Traceback (most recent call last):
  File "/home/kinami/.cache/pre-commit/repoo6u1swju/py_env-python3/bin/cz", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/kinami/.cache/pre-commit/repoo6u1swju/py_env-python3/lib/python3.12/site-packages/commitizen/cli.py", line 179, in main
    conf = config.read_cfg()
           ^^^^^^^^^^^^^^^^^
  File "/home/kinami/.cache/pre-commit/repoo6u1swju/py_env-python3/lib/python3.12/site-packages/commitizen/config/__init__.py", line 60, in read_cfg
    _conf = TomlConfig(data=data, path=filename)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kinami/.cache/pre-commit/repoo6u1swju/py_env-python3/lib/python3.12/site-packages/commitizen/config/toml_config.py", line 10, in __init__
    self._parse_setting(data)
  File "/home/kinami/.cache/pre-commit/repoo6u1swju/py_env-python3/lib/python3.12/site-packages/commitizen/config/toml_config.py", line 39, in _parse_setting
    doc = parse(data)
          ^^^^^^^^^^^
  File "/home/kinami/.cache/pre-commit/repoo6u1swju/py_env-python3/lib/python3.12/site-packages/tomlkit/api.py", line 51, in parse
    return Parser(string).parse()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kinami/.cache/pre-commit/repoo6u1swju/py_env-python3/lib/python3.12/site-packages/tomlkit/parser.py", line 153, in parse
    key, value = self._parse_table()
                 ^^^^^^^^^^^^^^^^^^^
  File "/home/kinami/.cache/pre-commit/repoo6u1swju/py_env-python3/lib/python3.12/site-packages/tomlkit/parser.py", line 1056, in _parse_table
    item = self._parse_item()
           ^^^^^^^^^^^^^^^^^^
  File "/home/kinami/.cache/pre-commit/repoo6u1swju/py_env-python3/lib/python3.12/site-packages/tomlkit/parser.py", line 302, in _parse_item
    return self._parse_key_value(True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kinami/.cache/pre-commit/repoo6u1swju/py_env-python3/lib/python3.12/site-packages/tomlkit/parser.py", line 387, in _parse_key_value
    val = self._parse_value()
          ^^^^^^^^^^^^^^^^^^^
  File "/home/kinami/.cache/pre-commit/repoo6u1swju/py_env-python3/lib/python3.12/site-packages/tomlkit/parser.py", line 524, in _parse_value
    return self._parse_array()
           ^^^^^^^^^^^^^^^^^^^
  File "/home/kinami/.cache/pre-commit/repoo6u1swju/py_env-python3/lib/python3.12/site-packages/tomlkit/parser.py", line 680, in _parse_array
    raise self.parse_error(MixedArrayTypesError)
tomlkit.exceptions.MixedArrayTypesError: Mixed types found in array at line 19 col 1

Desired behavior

The pyproject.toml gets parsed correctly and no errors appear.

Screenshots

No response

Environment

Commitizen Version: 4.8.2
Python Version: 3.12.10 (main, May 17 2025, 13:50:06) [Clang 20.1.4 ]
Operating System: Linux

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions