Skip to content

Commit f9710e9

Browse files
authored
Merge pull request #9684 dont-explode-on-failed-distutils-parse
2 parents 1545996 + c5f9bc5 commit f9710e9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

news/8931.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Skip distutils configuration parsing on encoding errors.

src/pip/_internal/locations/_distutils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# The following comment should be removed at some point in the future.
44
# mypy: strict-optional=False
55

6+
import logging
67
import os
78
import sys
89
from distutils.cmd import Command as DistutilsCommand
@@ -17,6 +18,8 @@
1718

1819
from .base import get_major_minor_version
1920

21+
logger = logging.getLogger(__name__)
22+
2023

2124
def _distutils_scheme(
2225
dist_name: str,
@@ -36,7 +39,15 @@ def _distutils_scheme(
3639
dist_args["script_args"] = ["--no-user-cfg"]
3740

3841
d = Distribution(dist_args)
39-
d.parse_config_files()
42+
try:
43+
d.parse_config_files()
44+
except UnicodeDecodeError:
45+
# Typeshed does not include find_config_files() for some reason.
46+
paths = d.find_config_files() # type: ignore
47+
logger.warning(
48+
"Ignore distutils configs in %s due to encoding errors.",
49+
", ".join(os.path.basename(p) for p in paths),
50+
)
4051
obj: Optional[DistutilsCommand] = None
4152
obj = d.get_command_obj("install", create=True)
4253
assert obj is not None

0 commit comments

Comments
 (0)