File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515import warnings
1616from collections import OrderedDict
1717from email .generator import BytesGenerator , Generator
18+ from email .policy import EmailPolicy
1819from glob import iglob
1920from io import BytesIO
2021from 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 )
Original file line number Diff line number Diff 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+
75114def test_licenses_default (dummy_dist , monkeypatch , tmpdir ):
76115 monkeypatch .chdir (dummy_dist )
77116 subprocess .check_call (
You can’t perform that action at this time.
0 commit comments