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
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pep517/build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Build a project using PEP 517 hooks.
"""
import argparse
import io
import logging
import os
import toml
Expand Down Expand Up @@ -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.

pyproject_data = toml.load(f)
return pyproject_data['build-system']

Expand Down
3 changes: 2 additions & 1 deletion pep517/check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Check a project and backend by attempting to build using PEP 517 hooks.
"""
import argparse
import io
import logging
import os
from os.path import isfile, join as pjoin
Expand Down Expand Up @@ -141,7 +142,7 @@ def check(source_dir):
return False

try:
with open(pyproject) as f:
with io.open(pyproject, encoding="utf-8") as f:
pyproject_data = toml_load(f)
# Ensure the mandatory data can be loaded
buildsys = pyproject_data['build-system']
Expand Down
6 changes: 5 additions & 1 deletion pep517/envbuild.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Build wheels/sdists by installing build deps to a temporary environment.
"""

import io
import os
import logging
import toml
Expand All @@ -16,7 +17,10 @@


def _load_pyproject(source_dir):
with open(os.path.join(source_dir, 'pyproject.toml')) as f:
with io.open(
os.path.join(source_dir, 'pyproject.toml'),
encoding="utf-8",
) as f:
pyproject_data = toml.load(f)
buildsys = pyproject_data['build-system']
return (
Expand Down
4 changes: 4 additions & 0 deletions tests/samples/pkg1/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[build-system]
requires = ["eg_buildsys"]
build-backend = "buildsys"

[project]
description = "Factory ⸻ A code generator 🏭"
maintainers = [{name = "Łukasz Langa"}]
3 changes: 2 additions & 1 deletion tests/test_call_hooks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io
import os
from os.path import dirname, abspath, join as pjoin
import tarfile
Expand Down Expand Up @@ -28,7 +29,7 @@

def get_hooks(pkg, **kwargs):
source_dir = pjoin(SAMPLES_DIR, pkg)
with open(pjoin(source_dir, 'pyproject.toml')) as f:
with io.open(pjoin(source_dir, 'pyproject.toml'), encoding="utf-8") as f:
data = toml.load(f)
return Pep517HookCaller(
source_dir, data['build-system']['build-backend'], **kwargs
Expand Down
3 changes: 2 additions & 1 deletion tests/test_hook_fallbacks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io
from os.path import dirname, abspath, join as pjoin
import pytest
import toml
Expand All @@ -12,7 +13,7 @@

def get_hooks(pkg):
source_dir = pjoin(SAMPLES_DIR, pkg)
with open(pjoin(source_dir, 'pyproject.toml')) as f:
with io.open(pjoin(source_dir, 'pyproject.toml'), encoding="utf-8") as f:
data = toml.load(f)
return Pep517HookCaller(source_dir, data['build-system']['build-backend'])

Expand Down
3 changes: 2 additions & 1 deletion tests/test_inplace_hooks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io
from os.path import dirname, abspath, join as pjoin
import toml
from testpath import modified_env
Expand All @@ -12,7 +13,7 @@

def get_hooks(pkg, backend=None, path=None):
source_dir = pjoin(SAMPLES_DIR, pkg)
with open(pjoin(source_dir, 'pyproject.toml')) as f:
with io.open(pjoin(source_dir, 'pyproject.toml'), encoding="utf-8") as f:
data = toml.load(f)
if backend is None:
backend = data['build-system']['build-backend']
Expand Down