Skip to content

Commit 5bc9b66

Browse files
authored
Use UTF-8 encoding when parsing pyproject.toml (#1940)
1 parent de42464 commit 5bc9b66

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/tox/_pytestplugin.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,14 @@ def create_files(base, filedefs):
491491
create_files(base.ensure(key, dir=1), value)
492492
elif isinstance(value, six.string_types):
493493
s = textwrap.dedent(value)
494-
base.join(key).write(s)
494+
495+
if not isinstance(s, six.text_type):
496+
if not isinstance(s, six.binary_type):
497+
s = str(s)
498+
else:
499+
s = six.ensure_text(s)
500+
501+
base.join(key).write_text(s, encoding="UTF-8")
495502

496503

497504
@pytest.fixture()

src/tox/config/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import print_function
22

33
import argparse
4+
import io
45
import itertools
56
import json
67
import os
@@ -303,7 +304,7 @@ def parseconfig(args, plugins=()):
303304

304305

305306
def get_py_project_toml(path):
306-
with open(str(path)) as file_handler:
307+
with io.open(str(path), encoding="UTF-8") as file_handler:
307308
config_data = toml.load(file_handler)
308309
return config_data
309310

tests/unit/config/test_config.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding=utf-8
12
import os
23
import re
34
import sys
@@ -3556,7 +3557,10 @@ def test_config_via_pyproject_legacy(initproj):
35563557
initproj(
35573558
"config_via_pyproject_legacy-0.5",
35583559
filedefs={
3559-
"pyproject.toml": '''
3560+
"pyproject.toml": u'''
3561+
[project]
3562+
description = "Factory ⸻ A code generator 🏭"
3563+
authors = [{name = "Łukasz Langa"}]
35603564
[tool.tox]
35613565
legacy_tox_ini = """
35623566
[tox]

0 commit comments

Comments
 (0)