-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
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. |
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... |
Ok, I'll take a stab at that :) |
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. |
You can take a look at https://github.com/pypa/pip/blob/develop/tests/data/packages/wheelbroken-0.1.tar.gz , its
|
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
7a57932
to
7f58c07
Compare
I made a version of |
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 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! |
Poke? |
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Outside of some questioning on the logging, it looks fine to me. |
Looks like everything is fine, could you add a small changelog for this fix ? |
Clean build dir if bdist_wheel fails
I've merged this and will add the changelog. Thanks @tgs for the contribution! |
👍 Thanks :) |
Thanks for your help, I appreciate it! |
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