Skip to content

Commit 2675e85

Browse files
committed
Use UTF-8 to write metadata files
1 parent 69f5806 commit 2675e85

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

setuptools/command/bdist_egg.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,9 @@ def run(self): # noqa: C901 # is too complex (14) # FIXME
200200
log.info("writing %s", native_libs)
201201
if not self.dry_run:
202202
ensure_directory(native_libs)
203-
libs_file = open(native_libs, 'wt')
204-
libs_file.write('\n'.join(all_outputs))
205-
libs_file.write('\n')
206-
libs_file.close()
203+
with open(native_libs, 'wt', encoding="utf-8") as libs_file:
204+
libs_file.write('\n'.join(all_outputs))
205+
libs_file.write('\n')
207206
elif os.path.isfile(native_libs):
208207
log.info("removing %s", native_libs)
209208
if not self.dry_run:

setuptools/command/easy_install.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,12 +1023,11 @@ def install_exe(self, dist_filename, tmpdir):
10231023

10241024
# Write EGG-INFO/PKG-INFO
10251025
if not os.path.exists(pkg_inf):
1026-
f = open(pkg_inf, 'w') # TODO: probably it is safe to use utf-8
1027-
f.write('Metadata-Version: 1.0\n')
1028-
for k, v in cfg.items('metadata'):
1029-
if k != 'target_version':
1030-
f.write('%s: %s\n' % (k.replace('_', '-').title(), v))
1031-
f.close()
1026+
with open(pkg_inf, 'w', encoding="utf-8") as f:
1027+
f.write('Metadata-Version: 1.0\n')
1028+
for k, v in cfg.items('metadata'):
1029+
if k != 'target_version':
1030+
f.write('%s: %s\n' % (k.replace('_', '-').title(), v))
10321031
script_dir = os.path.join(_egg_info, 'scripts')
10331032
# delete entry-point scripts to avoid duping
10341033
self.delete_blockers([
@@ -1094,9 +1093,8 @@ def process(src, dst):
10941093
if locals()[name]:
10951094
txt = os.path.join(egg_tmp, 'EGG-INFO', name + '.txt')
10961095
if not os.path.exists(txt):
1097-
f = open(txt, 'w') # TODO: probably it is safe to use utf-8
1098-
f.write('\n'.join(locals()[name]) + '\n')
1099-
f.close()
1096+
with open(txt, 'w', encoding="utf-8") as f:
1097+
f.write('\n'.join(locals()[name]) + '\n')
11001098

11011099
def install_wheel(self, wheel_path, tmpdir):
11021100
wheel = Wheel(wheel_path)

0 commit comments

Comments
 (0)