Skip to content

Commit

Permalink
Use UTF-8 encoding when parsing pyproject.toml (#1940)
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding authored Mar 3, 2021
1 parent de42464 commit 5bc9b66
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/tox/_pytestplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,14 @@ def create_files(base, filedefs):
create_files(base.ensure(key, dir=1), value)
elif isinstance(value, six.string_types):
s = textwrap.dedent(value)
base.join(key).write(s)

if not isinstance(s, six.text_type):
if not isinstance(s, six.binary_type):
s = str(s)
else:
s = six.ensure_text(s)

base.join(key).write_text(s, encoding="UTF-8")


@pytest.fixture()
Expand Down
3 changes: 2 additions & 1 deletion src/tox/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import print_function

import argparse
import io
import itertools
import json
import os
Expand Down Expand Up @@ -303,7 +304,7 @@ def parseconfig(args, plugins=()):


def get_py_project_toml(path):
with open(str(path)) as file_handler:
with io.open(str(path), encoding="UTF-8") as file_handler:
config_data = toml.load(file_handler)
return config_data

Expand Down
6 changes: 5 additions & 1 deletion tests/unit/config/test_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding=utf-8
import os
import re
import sys
Expand Down Expand Up @@ -3556,7 +3557,10 @@ def test_config_via_pyproject_legacy(initproj):
initproj(
"config_via_pyproject_legacy-0.5",
filedefs={
"pyproject.toml": '''
"pyproject.toml": u'''
[project]
description = "Factory ⸻ A code generator 🏭"
authors = [{name = "Łukasz Langa"}]
[tool.tox]
legacy_tox_ini = """
[tox]
Expand Down

0 comments on commit 5bc9b66

Please sign in to comment.