74
74
DEVELOP_DIST ,
75
75
)
76
76
import pkg_resources
77
- from ..compat import py311
77
+ from ..compat import py39 , py311
78
78
from .._path import ensure_directory
79
79
from ..extern .jaraco .text import yield_lines
80
80
@@ -491,7 +491,7 @@ def check_site_dir(self): # noqa: C901 # is too complex (12) # FIXME
491
491
try :
492
492
if test_exists :
493
493
os .unlink (testfile )
494
- open (testfile , 'w ' ).close ()
494
+ open (testfile , 'wb ' ).close ()
495
495
os .unlink (testfile )
496
496
except OSError :
497
497
self .cant_write_to_target ()
@@ -576,7 +576,7 @@ def check_pth_processing(self):
576
576
_one_liner (
577
577
"""
578
578
import os
579
- f = open({ok_file!r}, 'w')
579
+ f = open({ok_file!r}, 'w', encoding="utf-8" )
580
580
f.write('OK')
581
581
f.close()
582
582
"""
@@ -588,7 +588,8 @@ def check_pth_processing(self):
588
588
os .unlink (ok_file )
589
589
dirname = os .path .dirname (ok_file )
590
590
os .makedirs (dirname , exist_ok = True )
591
- f = open (pth_file , 'w' )
591
+ f = open (pth_file , 'w' , encoding = py39 .LOCALE_ENCODING )
592
+ # ^-- Requires encoding="locale" instead of "utf-8" (python/cpython#77102).
592
593
except OSError :
593
594
self .cant_write_to_target ()
594
595
else :
@@ -872,7 +873,7 @@ def write_script(self, script_name, contents, mode="t", blockers=()):
872
873
ensure_directory (target )
873
874
if os .path .exists (target ):
874
875
os .unlink (target )
875
- with open (target , "w" + mode ) as f :
876
+ with open (target , "w" + mode ) as f : # TODO: is it safe to use utf-8?
876
877
f .write (contents )
877
878
chmod (target , 0o777 - mask )
878
879
@@ -1016,7 +1017,7 @@ def install_exe(self, dist_filename, tmpdir):
1016
1017
1017
1018
# Write EGG-INFO/PKG-INFO
1018
1019
if not os .path .exists (pkg_inf ):
1019
- f = open (pkg_inf , 'w' )
1020
+ f = open (pkg_inf , 'w' ) # TODO: probably it is safe to use utf-8
1020
1021
f .write ('Metadata-Version: 1.0\n ' )
1021
1022
for k , v in cfg .items ('metadata' ):
1022
1023
if k != 'target_version' :
@@ -1087,7 +1088,7 @@ def process(src, dst):
1087
1088
if locals ()[name ]:
1088
1089
txt = os .path .join (egg_tmp , 'EGG-INFO' , name + '.txt' )
1089
1090
if not os .path .exists (txt ):
1090
- f = open (txt , 'w' )
1091
+ f = open (txt , 'w' ) # TODO: probably it is safe to use utf-8
1091
1092
f .write ('\n ' .join (locals ()[name ]) + '\n ' )
1092
1093
f .close ()
1093
1094
@@ -1277,7 +1278,9 @@ def update_pth(self, dist): # noqa: C901 # is too complex (11) # FIXME
1277
1278
filename = os .path .join (self .install_dir , 'setuptools.pth' )
1278
1279
if os .path .islink (filename ):
1279
1280
os .unlink (filename )
1280
- with open (filename , 'wt' ) as f :
1281
+
1282
+ with open (filename , 'wt' , encoding = py39 .LOCALE_ENCODING ) as f :
1283
+ # Requires encoding="locale" instead of "utf-8" (python/cpython#77102).
1281
1284
f .write (self .pth_file .make_relative (dist .location ) + '\n ' )
1282
1285
1283
1286
def unpack_progress (self , src , dst ):
@@ -1503,9 +1506,9 @@ def expand_paths(inputs): # noqa: C901 # is too complex (11) # FIXME
1503
1506
continue
1504
1507
1505
1508
# Read the .pth file
1506
- f = open (os .path .join (dirname , name ))
1507
- lines = list ( yield_lines ( f ))
1508
- f . close ( )
1509
+ with open (os .path .join (dirname , name ), encoding = py39 . LOCALE_ENCODING ) as f :
1510
+ # Requires encoding="locale" instead of "utf-8" (python/cpython#77102).
1511
+ lines = list ( yield_lines ( f ) )
1509
1512
1510
1513
# Yield existing non-dupe, non-import directory lines from it
1511
1514
for line in lines :
@@ -1619,7 +1622,8 @@ def _load_raw(self):
1619
1622
paths = []
1620
1623
dirty = saw_import = False
1621
1624
seen = dict .fromkeys (self .sitedirs )
1622
- f = open (self .filename , 'rt' )
1625
+ f = open (self .filename , 'rt' , encoding = py39 .LOCALE_ENCODING )
1626
+ # ^-- Requires encoding="locale" instead of "utf-8" (python/cpython#77102).
1623
1627
for line in f :
1624
1628
path = line .rstrip ()
1625
1629
# still keep imports and empty/commented lines for formatting
@@ -1690,7 +1694,8 @@ def save(self):
1690
1694
data = '\n ' .join (lines ) + '\n '
1691
1695
if os .path .islink (self .filename ):
1692
1696
os .unlink (self .filename )
1693
- with open (self .filename , 'wt' ) as f :
1697
+ with open (self .filename , 'wt' , encoding = py39 .LOCALE_ENCODING ) as f :
1698
+ # Requires encoding="locale" instead of "utf-8" (python/cpython#77102).
1694
1699
f .write (data )
1695
1700
elif os .path .exists (self .filename ):
1696
1701
log .debug ("Deleting empty %s" , self .filename )
0 commit comments