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

Clean build dir if bdist_wheel fails #3047

Merged
merged 2 commits into from
Sep 29, 2015
Merged

Conversation

tgs
Copy link
Contributor

@tgs tgs commented Aug 21, 2015

When pip tries to build a wheel but fails, setup.py install is run in
the same directory. However, some build files are not compatible
between 'install' and 'bdist_wheel', particularly scripts - the shebang
lines are different. Pip now cleans the build dir after a failed
bdist_wheel so that pip doesn't install broken scripts.

Closes #3006

@xavfernandez
Copy link
Member

On second thoughts, I think I would add a new method 'def _clean' called in _build_one (and not __build_one) if __build_one returns None.

A simple testcase with a package containing scripts and failing on bdist_wheel would also be nice, cf tests/data/packages or tests/data/src for examples.

@pfmoore
Copy link
Member

pfmoore commented Aug 22, 2015

I agree with @xavfernandez - the basic approach is good, but refactoring as suggested would be useful.

For a test, something entirely artificial (e.g., a package that checks argv to see if bdist_wheel is being called, and if so fails) is probably better than supplying an invalid install_requires, in case downstream fixes the issue there...

@tgs
Copy link
Contributor Author

tgs commented Aug 23, 2015

Ok, I'll take a stab at that :)
Maybe Monday.

http://resc.smugmug.com/

@tgs
Copy link
Contributor Author

tgs commented Aug 24, 2015

I refactored the changes to wheel.py and got started testing, but it turns out to be slightly tricky - the wheel build has to fail in just the right place to reproduce the bug, maybe? Will look again tomorrow, but then I'm on vacation for a few days, the next chance I get will be next week.

@xavfernandez
Copy link
Member

You can take a look at https://github.com/pypa/pip/blob/develop/tests/data/packages/wheelbroken-0.1.tar.gz , its setup.py contains:

if sys.argv[1] == 'bdist_wheel':
    raise FakeError('this package designed to fail on bdist_wheel')

tgs added 2 commits September 9, 2015 15:16
When pip tries to build a wheel but fails, setup.py install is run in
the same directory.  However, some build files are not compatible
between 'install' and 'bdist_wheel', particularly scripts - the shebang
lines are different.  Pip now cleans the build dir after a failed
bdist_wheel so that pip doesn't install broken scripts.

Closes pypa#3006
@tgs tgs force-pushed the clean_wheel_build_dir branch from 7a57932 to 7f58c07 Compare September 9, 2015 19:17
@tgs
Copy link
Contributor Author

tgs commented Sep 9, 2015

I made a version of wheelbroken where the raise FakeError comes after the call to setup(), so that it actually makes some build files and things. That did trigger the bug.

@tgs
Copy link
Contributor Author

tgs commented Sep 17, 2015

This is ready for you to take a look again when you get a chance (thanks for the suggestions!)

For ease of web-based review, here's the setup.py of the new test package:

from distutils.core import setup
import sys

class FakeError(Exception):
    pass

setup(name='wheelbrokenafter',
      version='0.1',
      scripts=['script.py'],
      )

if sys.argv[1] == 'bdist_wheel':
    # We fail afterwards so that we leave our build artifacts lying around.
    raise FakeError('this package designed to fail AFTER bdist_wheel')

Let me know what you think!

@tgs
Copy link
Contributor Author

tgs commented Sep 28, 2015

Poke?

@pfmoore
Copy link
Member

pfmoore commented Sep 28, 2015

Looks OK to me. @xavfernandez do you have any further comments?

@@ -668,19 +668,24 @@ def _build_one(self, req, output_dir):
logger.info('Stored in directory: %s', output_dir)
return wheel_path
except:
return None
pass
Copy link
Member

Choose a reason for hiding this comment

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

Even if there was no logging previously I think a logger.debug of the exception could be helpful.

Copy link
Member

Choose a reason for hiding this comment

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

You may be right - presumably even if the package is installed, the user wants to know that the wheel build failed as the implication is that the expected improved performance on repeated installs will be lost. Maybe there should even be a warning "wheel build failed, falling back to source install" as well as the debug info providing the full exception details.

Copy link
Member

Choose a reason for hiding this comment

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

Correction - if the wheel build fails, that results in __build_one returning False. The except clause here is solely if the wheel build succeeded, but the process of moving the wheel into wheel_path (the cache, presumably?) failed.

In that case, agreed a debug of the exception might be useful. But logging at warning level that caching the wheel failed is also probably useful. Both points are independent of this patch, though, so I think they should be dealt with separately.

Copy link
Member

Choose a reason for hiding this comment

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

k, we'll add the missing log in a different PR

@xavfernandez
Copy link
Member

Outside of some questioning on the logging, it looks fine to me.

@xavfernandez
Copy link
Member

Looks like everything is fine, could you add a small changelog for this fix ?
Cf https://github.com/pypa/pip/blob/develop/CHANGES.txt

pfmoore added a commit that referenced this pull request Sep 29, 2015
Clean build dir if bdist_wheel fails
@pfmoore pfmoore merged commit 908d077 into pypa:develop Sep 29, 2015
@pfmoore
Copy link
Member

pfmoore commented Sep 29, 2015

I've merged this and will add the changelog. Thanks @tgs for the contribution!

@xavfernandez
Copy link
Member

👍 Thanks :)

@tgs
Copy link
Contributor Author

tgs commented Sep 29, 2015

Thanks for your help, I appreciate it!

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 3, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants