mirror of https://github.com/pypa/pip
Fix 2 places where encoding is not specified
- In `pip/_internal/configuration.py`, explicitly use locale encoding to parse configuration file - In `pip/_internal/build_env.py`, use UTF-8 when generating `sitecustomize.py` Fixes #10590.
This commit is contained in:
parent
fc6d7778a5
commit
71d21ccaa0
|
@ -93,7 +93,9 @@ class BuildEnvironment:
|
|||
self._site_dir = os.path.join(temp_dir.path, "site")
|
||||
if not os.path.exists(self._site_dir):
|
||||
os.mkdir(self._site_dir)
|
||||
with open(os.path.join(self._site_dir, "sitecustomize.py"), "w") as fp:
|
||||
with open(
|
||||
os.path.join(self._site_dir, "sitecustomize.py"), "w", encoding="utf-8"
|
||||
) as fp:
|
||||
fp.write(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
|
|
|
@ -266,14 +266,13 @@ class Configuration:
|
|||
# Doing this is useful when modifying and saving files, where we don't
|
||||
# need to construct a parser.
|
||||
if os.path.exists(fname):
|
||||
locale_encoding = locale.getpreferredencoding(False)
|
||||
try:
|
||||
parser.read(fname)
|
||||
parser.read(fname, encoding=locale_encoding)
|
||||
except UnicodeDecodeError:
|
||||
# See https://github.com/pypa/pip/issues/4963
|
||||
raise ConfigurationFileCouldNotBeLoaded(
|
||||
reason="contains invalid {} characters".format(
|
||||
locale.getpreferredencoding(False)
|
||||
),
|
||||
reason="contains invalid {} characters".format(locale_encoding),
|
||||
fname=fname,
|
||||
)
|
||||
except configparser.Error as error:
|
||||
|
|
Loading…
Reference in New Issue