Skip to content

Commit

Permalink
Abort immediately on build failures instead of backtracking
Browse files Browse the repository at this point in the history
This behaviour is more forgiving when a source distribution cannot be
installed (eg: due to missing build dependencies or platform
incompatibility).
  • Loading branch information
pradyunsg committed Dec 10, 2021
1 parent bbc7021 commit 79d1e5f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
4 changes: 4 additions & 0 deletions news/10655.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Stop backtracking on build failures, by instead surfacing them to the
user and failing immediately. This behaviour is more forgiving when
a package cannot be built due to missing build dependencies or platform
incompatibility.
4 changes: 2 additions & 2 deletions src/pip/_internal/resolution/resolvelib/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _make_candidate_from_link(
name=name,
version=version,
)
except (InstallationSubprocessError, MetadataInconsistent) as e:
except MetadataInconsistent as e:
logger.warning("Discarding %s. %s", link, e)
self._build_failures[link] = e
return None
Expand All @@ -205,7 +205,7 @@ def _make_candidate_from_link(
name=name,
version=version,
)
except (InstallationSubprocessError, MetadataInconsistent) as e:
except MetadataInconsistent as e:
logger.warning("Discarding %s. %s", link, e)
self._build_failures[link] = e
return None
Expand Down
19 changes: 19 additions & 0 deletions tests/functional/test_new_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2308,3 +2308,22 @@ def test_new_resolver_respect_user_requested_if_extra_is_installed(
"pkg2",
)
script.assert_installed(pkg3="1.0", pkg2="2.0", pkg1="1.0")


def test_new_resolver_do_not_backtrack_on_build_failure(
script: PipTestEnvironment,
) -> None:
create_basic_sdist_for_package(script, "pkg1", "2.0", fails_egg_info=True)
create_basic_wheel_for_package(script, "pkg1", "1.0")

result = script.pip(
"install",
"--no-cache-dir",
"--no-index",
"--find-links",
script.scratch_path,
"pkg1",
expect_error=True,
)

assert "egg_info" in result.stderr
20 changes: 17 additions & 3 deletions tests/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,22 +1181,36 @@ def create_basic_sdist_for_package(
name: str,
version: str,
extra_files: Optional[Dict[str, str]] = None,
*,
fails_egg_info: bool = False,
fails_bdist_wheel: bool = False,
) -> Path:
files = {
"setup.py": """
"setup.py": f"""\
import sys
from setuptools import find_packages, setup
fails_bdist_wheel = {fails_bdist_wheel!r}
fails_egg_info = {fails_egg_info!r}
if fails_egg_info and "egg_info" in sys.argv:
raise Exception("Simulated failure for generating metadata.")
if fails_bdist_wheel and "bdist_wheel" in sys.argv:
raise Exception("Simulated failure for building a wheel.")
setup(name={name!r}, version={version!r})
""",
}

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

# Replace key-values with formatted values
for key, value in list(files.items()):
del files[key]
key = key.format(name=name)
files[key] = textwrap.dedent(value).format(name=name, version=version).strip()
files[key] = textwrap.dedent(value)

# Add new files after formatting
if extra_files:
Expand Down

0 comments on commit 79d1e5f

Please sign in to comment.