Skip to content

Сommitizen does not read pyproject in utf-8 correctly. #1636

Closed

Description

@le-lapin

Description

I have Windows, and the library is trying to read a CP1251 encoded file, even though my pyproject.toml file is saved in UTF-8 encoding.
the estimated location of the error:

document = tomlkit.parse(self.file.read_text())

Steps to reproduce

Example pyproject.toml

[project]
name = "pythonproject-test"
version = "0.4.1"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []


[tool.commitizen]
name = "cz_customize"
tag_format = "v$version"
version_scheme = "pep440"
version_provider = "uv"
update_changelog_on_bump = true
changelog_start_rev = "v1.1.0"

[tool.commitizen.customize]
message_template = "{{ change_type }}{% if scope != 'none' %}({{ scope }}){% endif %}: {{ message }}"
commit_parser = '^(?P<change_type>feat|fix|refactor|test|perf|misc):\s(?P<message>.*)'
schema_pattern = '(feat|fix|refactor|test|perf|misc)(\((api|core)\))?:\s(.{3,})'
bump_pattern = "^(feat|fix|refactor|test|perf|misc)"
change_type_map = { "feat" = "Новое", "fix" = "Исправление" }

[[tool.commitizen.customize.questions]]
name = "change_type"
type = "list"
message = "Выберите тип изменений"
choices = [
    { value = "feat", name = "feat: Новая функциональность" },
    { value = "fix", name = "fix: Исправление" },
    { value = "refactor", name = "refactor: Рефакторинг" },
    { value = "test", name = "test: Изменение авто-тестов" },
    { value = "perf", name = "perf: Оптимизации" },
    { value = "misc", name = "misc: Другое" },
]

output:

(.venv) ~\PycharmProjects\pythonProject_test git:[master] cz bump
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\LapinVMi\PycharmProjects\pythonProject_test\.venv\Scripts\cz.exe\__main__.py", line 10, in <module>
  File "C:\Users\LapinVMi\PycharmProjects\pythonProject_test\.venv\Lib\site-packages\commitizen\cli.py", line 685, in main
    args.func(conf, arguments)()  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\LapinVMi\PycharmProjects\pythonProject_test\.venv\Lib\site-packages\commitizen\commands\bump.py", line 165, in __call__
    current_version = self.scheme(provider.get_version())
                                  ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\LapinVMi\PycharmProjects\pythonProject_test\.venv\Lib\site-packages\commitizen\providers\base_provider.py", line 80, in get_version
    document = tomlkit.parse(self.file.read_text())
                             ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\LapinVMi\AppData\Local\Programs\Python\Python312\Lib\pathlib.py", line 1028, in read_text
    return f.read()
           ^^^^^^^^
  File "C:\Users\LapinVMi\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1251.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 771: character maps to <undefined>

Current behavior

when entering a command cz bump , i get an error message, as shown above.

Desired behavior

something like this:

(.venv) ~\PycharmProjects\pythonProject_test git:[master] cz bump
bump: version 0.4.1 → 0.4.2
tag to create: v0.4.2
increment detected: PATCH

[master ab992f9] bump: version 0.4.1 → 0.4.2
 2 files changed, 3 insertions(+), 1 deletion(-)

Done!

Screenshots

No response

Environment

Commitizen Version: 4.9.1
Python Version: 3.12.4 (tags/v3.12.4:8e8a4ba, Jun 6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)]
Operating System: Windows

Activity

  1. added a commit that references this issue on Feb 8, 2026
    90c1ad5
  2. bearomorphism commented on Feb 9, 2026

    @bearomorphism
    Collaborator

    Looks like we forget to use the encoding parameter in config in those files.

    We might fix this issue by adding something like encoding=self.config.encoding in all file.read_text(...) and with file.open(...)

  3. woile commented on Feb 9, 2026

    @woile
    Member

    Yes, I think we should use the existing setting to fix this. I think it mainly affects windows users

  4. self-assigned this
    on Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions