Skip to content

Commit 71d21cc

Browse files
committed
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.
1 parent fc6d777 commit 71d21cc

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

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="contains invalid {} characters".format(locale_encoding),
277276
fname=fname,
278277
)
279278
except configparser.Error as error:

0 commit comments

Comments
 (0)