Skip to content
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

Use UTF-8 encoding when reading pyproject.toml #120

Merged
merged 4 commits into from
Jul 18, 2021
Merged

Use UTF-8 encoding when reading pyproject.toml #120

merged 4 commits into from
Jul 18, 2021

Conversation

domdfcoding
Copy link
Contributor

This avoids a UnicodeDecodeError when reading pyproject.toml files containing unicode characters on Windows. These characters may be present in a project's metadata, such as its description or an author's name.

>>> from pep517.check import check
>>> check(".")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "lib\site-packages\pep517\check.py", line 145, in check
    pyproject_data = toml_load(f)
  File "lib\site-packages\toml\decoder.py", line 156, in load
    return loads(f.read(), _dict, decoder)
  File "lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 242: character maps to <undefined>

Furthermore, the TOML specification requires files to be encoded in UTF-8.

@@ -31,7 +32,7 @@ def load_system(source_dir):
Load the build system from a source dir (pyproject.toml).
"""
pyproject = os.path.join(source_dir, 'pyproject.toml')
with open(pyproject) as f:
with io.open(pyproject, encoding="utf-8") as f:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

io.open is necessary for Python 2, where builtins.open lacks an "encoding" argument.

@domdfcoding domdfcoding marked this pull request as ready for review July 11, 2021 16:24
@takluyver
Copy link
Member

Just as a reminder, envbuild and all the pieces that depend on it, including pep517.build are deprecated (see #91).

This is a simple enough improvement that I don't mind merging it if you want to resolve the conflicts, though.

@domdfcoding
Copy link
Contributor Author

This is a simple enough improvement that I don't mind merging it if you want to resolve the conflicts, though.

Done

@takluyver takluyver merged commit d834d3b into pypa:master Jul 18, 2021
@takluyver
Copy link
Member

Thanks!

takluyver added a commit that referenced this pull request Jul 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants