-
Notifications
You must be signed in to change notification settings - Fork 562
Open
Description
Description
When running cz init on Windows, the command fails with a UnicodeDecodeError due to the default file encoding being 'gbk' instead of 'utf-8'.
Steps to Reproduce
- Create a new Python project on Windows with Chinese system locale
- Install commitizen
- Run
cz init - Select
pyproject.tomlas config file - Select commit rule
Error Message
UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 52: illegal multibyte sequence
Technical Details
The error occurs in commitizen/commands/init.py when checking for poetry configuration:
@property
def is_python_poetry(self) -> bool:
if not self.has_pyproject:
return False
with open("pyproject.toml") as f:
return "[tool.poetry]" in f.read()) # Here the file is opened without specifying encodingExpected Behavior
The file should be opened with UTF-8 encoding explicitly to ensure consistent behavior across different system locales.
Suggested Fix
# In commitizen/commands/init.py
@property
def is_python_poetry(self) -> bool:
if not self.has_pyproject:
return False
with open("pyproject.toml", encoding=self.settings["encoding"]) as f: # self.settings["encoding"] default is utf-8
return "[tool.poetry]" in f.read())Environment
- OS: Windows
- Python Version: 3.12
- Commitizen Version: latest
- System Locale: Chinese (Simplified)
ScreenShot
Metadata
Metadata
Assignees
Labels
No labels
