Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build directory assertion for a PEP 517/518 world #6171

Merged
merged 3 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/6158.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a crash when using --no-cache-dir with PEP 517 distributions
1 change: 1 addition & 0 deletions news/6171.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a crash when using --no-cache-dir with PEP 517 distributions
13 changes: 7 additions & 6 deletions src/pip/_internal/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,12 +840,6 @@ def build(
newly built wheel, in preparation for installation.
:return: True if all the wheels built correctly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(unrelated to this PR but the docstring seems obsolete :) )

"""
# TODO: This check fails if --no-cache-dir is set. And yet we
# might be able to build into the ephemeral cache, surely?
building_is_possible = self._wheel_dir or (
autobuilding and self.wheel_cache.cache_dir
)
assert building_is_possible

buildset = []
format_control = self.finder.format_control
Expand Down Expand Up @@ -884,6 +878,13 @@ def build(
if not buildset:
return []

# Is any wheel build not using the ephemeral cache?
if any(not ephem_cache for _, ephem_cache in buildset):
have_directory_for_build = self._wheel_dir or (
autobuilding and self.wheel_cache.cache_dir
)
assert have_directory_for_build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, it looks like an alternative way to do this would be to calculate a needs_ephem_cache variable (or similarly defined variable) prior to the for loop above. And then check that ephem_cache is true inside the for loop prior to appending to the buildset (depending on whether needs_ephem_cache is true). That would give you more information if the condition ever fails, and let you raise an exception with more specific, contextual info (as well as fail faster).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, this worked and I decided "good is better than perfect" wrt code cleanup here. :)


# TODO by @pradyunsg
# Should break up this method into 2 separate methods.

Expand Down
8 changes: 8 additions & 0 deletions tests/functional/test_install_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,11 @@ def test_wheel_compile_syntax_error(script, data):
result = script.pip('install', '--compile', package, '--no-index')
assert 'yield from' not in result.stdout
assert 'SyntaxError: ' not in result.stdout


def test_wheel_install_with_no_cache_dir(script, tmpdir, data):
"""Check wheel installations work, even with no cache.
"""
package = data.packages.join("simple.dist-0.1-py2.py3-none-any.whl")
result = script.pip('install', '--no-cache-dir', '--no-index', package)
result.assert_installed('simpledist', editable=False)
14 changes: 14 additions & 0 deletions tests/functional/test_pep517.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,17 @@ def test_pep517_backend_requirements_already_satisfied(script, tmpdir, data):
project_dir,
)
assert 'Installing backend dependencies:' not in result.stdout


def test_pep517_install_with_no_cache_dir(script, tmpdir, data):
"""Check builds with a custom backends work, even with no cache.
"""
project_dir = make_project(
tmpdir, requires=['test_backend'],
backend="test_backend"
)
result = script.pip(
'install', '--no-cache-dir', '--no-index', '-f', data.backends,
project_dir,
)
result.assert_installed('project', editable=False)