-
-
Notifications
You must be signed in to change notification settings - Fork 307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pyproject.toml expected encoding seems inconsistent, bug with hatch test --cover
and special characters
#1677
Comments
I analysed more in detail the issue. My pull requests should fix it. I noticed that the issue also appears with I confirm that some commands are unaffected (e.g |
Not sure if its related, but I'm getting |
Hatch has some problems with UTF chars in `pyproject.toml` on windows. Refs: pypa/hatch#1677
Hatch has some problems with UTF chars in `pyproject.toml` on windows. Refs: pypa/hatch#1677
Hatch has some problems with UTF chars in `pyproject.toml` on windows. Refs: pypa/hatch#1677
Hatch has some problems with UTF chars in `pyproject.toml` on windows. Refs: pypa/hatch#1677
Environment:
How to reproduce
hatch fmt
,hatch test
,hatch test --cover
).# ”
as a comment at the end ofpyproject.toml
. The last character is a 'RIGHT DOUBLE QUOTATION MARK' (U+201D), it is encoded in UTF-8 with bytes 0xE2 0x80 0x9D.hatch test --cover
.Issue description
pyproject.toml
should fail with the same error.hatch test --cover
fails withUnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1645: character maps to <undefined>
, while other commands work fine (e.g.hatch env show
,hatch fmt
,hatch test
).Hatch 1.12.0 (on python 3.12.5, installed with pipx) traceback:
Cause
The issue seems caused by hatch/cli/test/core.py:50
self.user_config_path.read_text()
.self.user_config_path
seems to be a pathlib.Path(), thus.read_text()
should default to encoding "utf-8" on Linux and "windows-1252" on Windows.The same error can be produced by creating e file only containing the triggering character 'RIGHT DOUBLE QUOTATION MARK' (U+201D, UTF-8 0xE2 0x80 0x9D) and reading the file with
pathlib.Path(<file>).read_text(encoding="windows-1252")
.Proposed solution
Change hatch/cli/test/core.py:50
self.user_config_path.read_text()
toself.user_config_path.read_text(encoding="utf-8")
. This seems to solve the issue in the local hatch installation.This should be consistent because
pyproject.toml
specification, which requires the encoding to be "utf-8".Proposed solution possible drawbacks
Possibly, a Windows only project might use windows-1252 for
pyproject.toml
. However, this seems not plausible, because apyproject.toml
with the same character in windows-1252 encoding makes hatch's other commands fail with errorUnicodeDecodeError: 'utf-8' codec can't decode byte 0x94 in position 1643: invalid start byte
. This confirms that the other commands expect the "utf-8" encoding. Moreover, windows-1252 would not be consistent with thepyproject.toml
specification.Notes
Running
grep -n -F ".read_text(" src/**/*.py
(withshopt -s globstar
) in the hatch repository reveals many instances of.read_text()
, many of them without explicit encoding, some of them with explicit "utf-8". It is possible that the same issue extends to those calls.I might work on a patch, but I might need some guidance on how to design an appropriate test.
The text was updated successfully, but these errors were encountered: