Skip to content

Commit f3a5dcc

Browse files
authored
Merge pull request #10593 from gousaiyang/fix-missing-encoding-2
2 parents 16d16c8 + 7b6a1ed commit f3a5dcc

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

news/10593.trivial.rst

Whitespace-only changes.

src/pip/_internal/build_env.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ def __init__(self) -> None:
9393
self._site_dir = os.path.join(temp_dir.path, "site")
9494
if not os.path.exists(self._site_dir):
9595
os.mkdir(self._site_dir)
96-
with open(os.path.join(self._site_dir, "sitecustomize.py"), "w") as fp:
96+
with open(
97+
os.path.join(self._site_dir, "sitecustomize.py"), "w", encoding="utf-8"
98+
) as fp:
9799
fp.write(
98100
textwrap.dedent(
99101
"""

src/pip/_internal/configuration.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,13 @@ def _construct_parser(self, fname: str) -> RawConfigParser:
266266
# Doing this is useful when modifying and saving files, where we don't
267267
# need to construct a parser.
268268
if os.path.exists(fname):
269+
locale_encoding = locale.getpreferredencoding(False)
269270
try:
270-
parser.read(fname)
271+
parser.read(fname, encoding=locale_encoding)
271272
except UnicodeDecodeError:
272273
# See https://github.com/pypa/pip/issues/4963
273274
raise ConfigurationFileCouldNotBeLoaded(
274-
reason="contains invalid {} characters".format(
275-
locale.getpreferredencoding(False)
276-
),
275+
reason=f"contains invalid {locale_encoding} characters",
277276
fname=fname,
278277
)
279278
except configparser.Error as error:

0 commit comments

Comments
 (0)