-
Notifications
You must be signed in to change notification settings - Fork 128
build: implement metadata preparation hook #217
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
Conversation
I like that |
PEP 517 does not say whether the prepared metadata directory may be reused across multiple It also just occured to me that the PEP says the frontend should only pass the metadata directory into |
Yes, I don't think we need to do anything fancy with the metadata path, nor do I expect that anybody will actually want to pipe the metadata path into |
pip does. And arguably all major backends are implemented incorrectly. According to PEP 517, if a backend implements |
Is that because the prepared metadata becomes stale (e.g. when editing a package locally) or because the prepared metadata is simply incorrect? |
The prepared metadata is incorrect in the particular case (pypa/pip#9446). |
We could check with backend devs to see why this wasn't implemented, if the PEP needs to be modified and if pip wouldn't be better off comparing prepared and built wheel metadata on their end. |
There are issue filed to those backends now (I filed one for Flit just a moment ago): pypa/setuptools#1825 python-poetry/poetry#1078 pypa/flit#389 |
I raised the issue on discussion.python.org, and from the response, I think we should still implement the |
I agree. I think a backend simply ignoring the argument is fine, though I think they should all verify if it's the same metadata if they're gonna rebuild it anyway. |
5a511d9
to
07aeb1f
Compare
8efe23a
to
195f416
Compare
src/build/__init__.py
Outdated
except pep517.wrappers.BackendUnavailable: | ||
raise BuildException("Backend '{}' is not available.".format(self._backend)) | ||
except pep517.wrappers.HookMissing: | ||
return None |
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.
prepare('wheel')
currently returns None
if prepare_metadata_for_build_wheel
is not implemented. Should an exception be raised instead?
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.
Possibly - would that mean exposing pep517
's exceptions or creating our own equivalents?
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.
That is to say, I don't think a generic Build(Backend)Exception
is satisfactory.
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.
Agreed. The exception raised here need to be different, otherwise the caller won’t be able to distinguish an expected code path (prepare_metadata_for_build_wheel
not implemented by the backend) from a legistimate error in the backend (BuildBackendException
) or the build process (BuildException
). So a new exception will be needed if we raise here.
src/build/__init__.py
Outdated
raise BuildBackendException('Backend operation failed: {!r}'.format(e)) | ||
return path | ||
|
||
def build(self, distribution, outdir, metadata_directory=None, config_settings=None): |
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.
metadata_directory
-> metadatadir
or outdir
-> output_directory
for consistency.
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.
PEP 517 names the arguments wheel_directory
and metadata_directory
. Would that work?
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.
Well, build
works both with wheels and sdists, hence 'out' or 'output'.
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.
I’m going with output_directory
.
51a7884
to
3c131e6
Compare
3c131e6
to
02bf104
Compare
2dc409a
to
4af72f9
Compare
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.
@uranusjr made some changes to reduce code duplication, but now looks 👍🏻
7443b1b
to
ae1fa87
Compare
370dc6e
to
2d50531
Compare
Signed-off-by: Bernát Gábor <[email protected]>
2d50531
to
aa3b220
Compare
Fix #130.
I make the function signature require the user to pass in
"wheel"
explicitly. This is of course redundant, but I have a feeling we’re going to have aprepare_metadata_for_sdist
at some point and it’s better to leave room now than having to change things later. Andprepare("wheel")
is arguably more consistent withbuild("wheel")
anyway.Due to the issues mentioned in #130 (comment), I’m not using the
build_wheel
fallback provided bypep517
, and instead returnNone
when the backend does not implementprepare_metadata_for_wheel
. The returned result is stored in a member attribute and popped out whenbuild_wheel
is called.