Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
@le-lapin

Description

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.10.4.2
tag to create: v0.4.2
increment detected: PATCH
[master ab992f9] bump: version 0.4.10.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

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

        AltStyle によって変換されたページ (->オリジナル) /