Skip to content

Commit 2b82912

Browse files
committed
Attempt to use UTF-8 with develop command.
This change tries to use UTF-8 when writing `.egg-link` files. When reading other files, we first attempt to use UTF-8 and then fallback for the locale encoding.
1 parent 8a75f99 commit 2b82912

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

setuptools/command/develop.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from setuptools import namespaces
1111
import setuptools
1212

13+
from ..compat import py39
14+
1315

1416
class develop(namespaces.DevelopInstaller, easy_install):
1517
"""Set up package for development"""
@@ -119,7 +121,7 @@ def install_for_development(self):
119121
# create an .egg-link in the installation dir, pointing to our egg
120122
log.info("Creating %s (link to %s)", self.egg_link, self.egg_base)
121123
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:
123125
f.write(self.egg_path + "\n" + self.setup_path)
124126
# postprocess the installed distro, fixing up .pth, installing scripts,
125127
# and handling requirements
@@ -128,9 +130,16 @@ def install_for_development(self):
128130
def uninstall_link(self):
129131
if os.path.exists(self.egg_link):
130132
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+
134143
if contents not in ([self.egg_path], [self.egg_path, self.setup_path]):
135144
log.warn("Link points to %s: uninstall aborted", contents)
136145
return
@@ -156,8 +165,14 @@ def install_egg_scripts(self, dist):
156165
for script_name in self.distribution.scripts or []:
157166
script_path = os.path.abspath(convert_path(script_name))
158167
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+
161176
self.install_script(dist, script_name, script_text, script_path)
162177

163178
return None

0 commit comments

Comments
 (0)