10
10
from setuptools import namespaces
11
11
import setuptools
12
12
13
+ from ..compat import py39
14
+
13
15
14
16
class develop (namespaces .DevelopInstaller , easy_install ):
15
17
"""Set up package for development"""
@@ -119,7 +121,7 @@ def install_for_development(self):
119
121
# create an .egg-link in the installation dir, pointing to our egg
120
122
log .info ("Creating %s (link to %s)" , self .egg_link , self .egg_base )
121
123
if not self .dry_run :
122
- with open (self .egg_link , "w" ) as f :
124
+ with open (self .egg_link , "w" , encoding = "utf-8" ) as f :
123
125
f .write (self .egg_path + "\n " + self .setup_path )
124
126
# postprocess the installed distro, fixing up .pth, installing scripts,
125
127
# and handling requirements
@@ -128,9 +130,16 @@ def install_for_development(self):
128
130
def uninstall_link (self ):
129
131
if os .path .exists (self .egg_link ):
130
132
log .info ("Removing %s (link to %s)" , self .egg_link , self .egg_base )
131
- egg_link_file = open (self .egg_link )
132
- contents = [line .rstrip () for line in egg_link_file ]
133
- egg_link_file .close ()
133
+
134
+ try :
135
+ with open (self .egg_link , encoding = "utf-8" ) as egg_link_file :
136
+ contents = [line .rstrip () for line in egg_link_file ]
137
+ except UnicodeDecodeError : # pragma: no cover
138
+ with open (
139
+ self .egg_link , encoding = py39 .LOCALE_ENCODING
140
+ ) as egg_link_file :
141
+ contents = [line .rstrip () for line in egg_link_file ]
142
+
134
143
if contents not in ([self .egg_path ], [self .egg_path , self .setup_path ]):
135
144
log .warn ("Link points to %s: uninstall aborted" , contents )
136
145
return
@@ -156,8 +165,14 @@ def install_egg_scripts(self, dist):
156
165
for script_name in self .distribution .scripts or []:
157
166
script_path = os .path .abspath (convert_path (script_name ))
158
167
script_name = os .path .basename (script_path )
159
- with open (script_path ) as strm :
160
- script_text = strm .read ()
168
+
169
+ try :
170
+ with open (script_path , encoding = "utf-8" ) as strm :
171
+ script_text = strm .read ()
172
+ except UnicodeDecodeError : # pragma: no cover
173
+ with open (script_path , encoding = py39 .LOCALE_ENCODING ) as strm :
174
+ script_text = strm .read ()
175
+
161
176
self .install_script (dist , script_name , script_text , script_path )
162
177
163
178
return None
0 commit comments