Skip to content

Commit 3f8bdf1

Browse files
authored
Allow METADATA file to contain UTF-8 chars (#489)
1 parent daeb157 commit 3f8bdf1

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/wheel/bdist_wheel.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import warnings
1616
from collections import OrderedDict
1717
from email.generator import BytesGenerator, Generator
18+
from email.policy import EmailPolicy
1819
from glob import iglob
1920
from io import BytesIO
2021
from shutil import rmtree
@@ -534,8 +535,13 @@ def adios(p):
534535
adios(dependency_links_path)
535536

536537
pkg_info_path = os.path.join(distinfo_path, "METADATA")
538+
serialization_policy = EmailPolicy(
539+
utf8=True,
540+
mangle_from_=False,
541+
max_line_length=0,
542+
)
537543
with open(pkg_info_path, "w", encoding="utf-8") as out:
538-
Generator(out, mangle_from_=False, maxheaderlen=0).flatten(pkg_info)
544+
Generator(out, policy=serialization_policy).flatten(pkg_info)
539545

540546
for license_path in self.license_paths:
541547
filename = os.path.basename(license_path)

tests/test_bdist_wheel.py

+39
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,45 @@ def test_unicode_record(wheel_paths):
7272
assert "åäö_日本語.py".encode() in record
7373

7474

75+
UTF8_PKG_INFO = """\
76+
Metadata-Version: 2.1
77+
Name: helloworld
78+
Version: 42
79+
Author-email: "John X. Ãørçeč" <john@utf8.org>, Γαμα קּ 東 <gama@utf8.org>
80+
81+
82+
UTF-8 描述 説明
83+
"""
84+
85+
86+
def test_preserve_unicode_metadata(monkeypatch, tmp_path):
87+
monkeypatch.chdir(tmp_path)
88+
egginfo = tmp_path / "dummy_dist.egg-info"
89+
distinfo = tmp_path / "dummy_dist.dist-info"
90+
91+
egginfo.mkdir()
92+
(egginfo / "PKG-INFO").write_text(UTF8_PKG_INFO, encoding="utf-8")
93+
(egginfo / "dependency_links.txt").touch()
94+
95+
class simpler_bdist_wheel(bdist_wheel):
96+
"""Avoid messing with setuptools/distutils internals"""
97+
98+
def __init__(self):
99+
pass
100+
101+
@property
102+
def license_paths(self):
103+
return []
104+
105+
cmd_obj = simpler_bdist_wheel()
106+
cmd_obj.egg2dist(egginfo, distinfo)
107+
108+
metadata = (distinfo / "METADATA").read_text(encoding="utf-8")
109+
assert 'Author-email: "John X. Ãørçeč"' in metadata
110+
assert "Γαμα קּ 東 " in metadata
111+
assert "UTF-8 描述 説明" in metadata
112+
113+
75114
def test_licenses_default(dummy_dist, monkeypatch, tmpdir):
76115
monkeypatch.chdir(dummy_dist)
77116
subprocess.check_call(

0 commit comments

Comments
 (0)