Skip to content

Commit 2905226

Browse files
committed
Abort immediately on metadata generation failure instead of backtracking
This behaviour is more forgiving when a source distribution cannot be installed (eg: due to missing build dependencies or platform incompatibility) and favours early eager failures instead of trying to ensure that a package is installed regardless of the amount of effort it takes.
1 parent bbc7021 commit 2905226

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

news/10655.bugfix.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Stop backtracking on build failures, by instead surfacing them to the
2+
user and failing immediately. This behaviour is more forgiving when
3+
a package cannot be built due to missing build dependencies or platform
4+
incompatibility.

src/pip/_internal/resolution/resolvelib/factory.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from pip._internal.exceptions import (
2828
DistributionNotFound,
2929
InstallationError,
30-
InstallationSubprocessError,
3130
MetadataInconsistent,
3231
UnsupportedPythonVersion,
3332
UnsupportedWheel,
@@ -190,7 +189,7 @@ def _make_candidate_from_link(
190189
name=name,
191190
version=version,
192191
)
193-
except (InstallationSubprocessError, MetadataInconsistent) as e:
192+
except MetadataInconsistent as e:
194193
logger.warning("Discarding %s. %s", link, e)
195194
self._build_failures[link] = e
196195
return None
@@ -205,7 +204,7 @@ def _make_candidate_from_link(
205204
name=name,
206205
version=version,
207206
)
208-
except (InstallationSubprocessError, MetadataInconsistent) as e:
207+
except MetadataInconsistent as e:
209208
logger.warning("Discarding %s. %s", link, e)
210209
self._build_failures[link] = e
211210
return None

tests/functional/test_new_resolver.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,3 +2308,22 @@ def test_new_resolver_respect_user_requested_if_extra_is_installed(
23082308
"pkg2",
23092309
)
23102310
script.assert_installed(pkg3="1.0", pkg2="2.0", pkg1="1.0")
2311+
2312+
2313+
def test_new_resolver_do_not_backtrack_on_build_failure(
2314+
script: PipTestEnvironment,
2315+
) -> None:
2316+
create_basic_sdist_for_package(script, "pkg1", "2.0", fails_egg_info=True)
2317+
create_basic_wheel_for_package(script, "pkg1", "1.0")
2318+
2319+
result = script.pip(
2320+
"install",
2321+
"--no-cache-dir",
2322+
"--no-index",
2323+
"--find-links",
2324+
script.scratch_path,
2325+
"pkg1",
2326+
expect_error=True,
2327+
)
2328+
2329+
assert "egg_info" in result.stderr

tests/lib/__init__.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,22 +1181,36 @@ def create_basic_sdist_for_package(
11811181
name: str,
11821182
version: str,
11831183
extra_files: Optional[Dict[str, str]] = None,
1184+
*,
1185+
fails_egg_info: bool = False,
1186+
fails_bdist_wheel: bool = False,
11841187
) -> Path:
11851188
files = {
1186-
"setup.py": """
1189+
"setup.py": f"""\
1190+
import sys
11871191
from setuptools import find_packages, setup
1192+
1193+
fails_bdist_wheel = {fails_bdist_wheel!r}
1194+
fails_egg_info = {fails_egg_info!r}
1195+
1196+
if fails_egg_info and "egg_info" in sys.argv:
1197+
raise Exception("Simulated failure for generating metadata.")
1198+
1199+
if fails_bdist_wheel and "bdist_wheel" in sys.argv:
1200+
raise Exception("Simulated failure for building a wheel.")
1201+
11881202
setup(name={name!r}, version={version!r})
11891203
""",
11901204
}
11911205

11921206
# Some useful shorthands
1193-
archive_name = "{name}-{version}.tar.gz".format(name=name, version=version)
1207+
archive_name = f"{name}-{version}.tar.gz"
11941208

11951209
# Replace key-values with formatted values
11961210
for key, value in list(files.items()):
11971211
del files[key]
11981212
key = key.format(name=name)
1199-
files[key] = textwrap.dedent(value).format(name=name, version=version).strip()
1213+
files[key] = textwrap.dedent(value)
12001214

12011215
# Add new files after formatting
12021216
if extra_files:

0 commit comments

Comments
 (0)