Skip to content

Commit 56a1224

Browse files
authored
Specify encoding. (#578)
* Specify encoding. Fixes failures when PYTHONWARNDEFAULTENCODING=1. Fixes #577. * Enable default encoding warning where available. See PEP 597.
1 parent bcfcc0a commit 56a1224

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

src/build/env.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def install(self, requirements: Collection[str]) -> None:
130130

131131
# pip does not honour environment markers in command line arguments
132132
# but it does for requirements from a file
133-
with tempfile.NamedTemporaryFile('w', prefix='build-reqs-', suffix='.txt', delete=False) as req_file:
133+
with tempfile.NamedTemporaryFile('w', prefix='build-reqs-', suffix='.txt', delete=False, encoding='utf-8') as req_file:
134134
req_file.write(os.linesep.join(requirements))
135135
try:
136136
cmd = [

tests/test_env.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ def test_isolated_env_log(mocker, caplog, package_test_flit):
120120
def test_default_pip_is_never_too_old():
121121
with build.env.DefaultIsolatedEnv() as env:
122122
version = subprocess.check_output(
123-
[env.python_executable, '-c', 'import pip; print(pip.__version__)'], text=True
123+
[env.python_executable, '-c', 'import pip; print(pip.__version__)'],
124+
text=True,
125+
encoding='utf-8',
124126
).strip()
125127
assert Version(version) >= Version('19.1')
126128

tests/test_projectbuilder.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def test_build_not_dir_outdir(mocker, tmp_dir, package_test_flit):
363363
builder._hook.build_sdist.return_value = 'dist.tar.gz'
364364
out = os.path.join(tmp_dir, 'out')
365365

366-
open(out, 'a').close() # create empty file
366+
open(out, 'a', encoding='utf-8').close() # create empty file
367367

368368
with pytest.raises(build.BuildException):
369369
builder.build('sdist', out)
@@ -410,7 +410,7 @@ def test_build_with_dep_on_console_script(tmp_path, demo_pkg_inline, capfd, mock
410410
'''
411411
)
412412
(tmp_path / 'pyproject.toml').write_text(toml, encoding='UTF-8')
413-
(tmp_path / 'build.py').write_text(code)
413+
(tmp_path / 'build.py').write_text(code, encoding='utf-8')
414414

415415
deps = {str(demo_pkg_inline)} # we patch the requires demo_pkg_inline to refer to the wheel -> we don't need index
416416
mocker.patch('build.ProjectBuilder.build_system_requires', new_callable=mocker.PropertyMock, return_value=deps)
@@ -462,7 +462,7 @@ def test_prepare_not_dir_outdir(mocker, tmp_dir, package_test_flit):
462462
builder = build.ProjectBuilder(package_test_flit)
463463

464464
out = os.path.join(tmp_dir, 'out')
465-
with open(out, 'w') as f:
465+
with open(out, 'w', encoding='utf-8') as f:
466466
f.write('Not a directory')
467467
with pytest.raises(build.BuildException, match='Build path .* exists and is not a directory'):
468468
builder.prepare('wheel', out)

tox.ini

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ setenv =
2323
COVERAGE_FILE = {toxworkdir}/.coverage.{envname}
2424
TEST_STATUS_DIR = {envtmpdir}
2525
PYPY3323BUG = 1
26+
PYTHONWARNDEFAULTENCODING = 1
2627
extras =
2728
test
2829
commands =

0 commit comments

Comments
 (0)