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

build meta wheel does not respect metadata_directory per PEP-517 #1973

Open
2 tasks
thejcannon opened this issue Feb 28, 2024 · 2 comments
Open
2 tasks

build meta wheel does not respect metadata_directory per PEP-517 #1973

thejcannon opened this issue Feb 28, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@thejcannon
Copy link

Bug Description

(similar to pypa/setuptools#1825)

From https://www.python.org/dev/peps/pep-0517/#build-wheel:

If the build frontend has previously called prepare_metadata_for_build_wheel and depends on the wheel resulting from this call to have metadata matching this earlier call, then it should provide the path to the created .dist-info directory as the metadata_directory argument.

Maturin ignores the metadata_directory argument in build_wheel which makes it hard to "wrap" build backends and adjust metadata. (The workaround is to wrap build_wheel as well, and unpack-adjust-rechecksum-repack the wheel)

def _build_wheel(

Your maturin version (maturin --version)

main

Your Python version (python -V)

(unrelated)

Your pip version (pip -V)

(unrelated)

What bindings you're using

None

Does cargo build work?

  • Yes, it works

If on windows, have you checked that you aren't accidentally using unix path (those with the forward slash /)?

  • Yes

Steps to Reproduce

  1. Declare pyproject.toml with an "in-repo" `build-backend
[build-system]
requires = ["maturin>=1.0,<2.0"]
build-backend = "build_hooks"
backend-path = ["."]
  1. Make the hooks file (build_hooks.py):
from maturin import *
import maturin as _maturin

def prepare_metadata_for_build_wheel(metadata_directory, config_settings):
     result = _maturin.prepare_metadata_for_build_wheel(metadata_directory, config_settings)
     with Path(metadata_directory, result, "METADATA").open("a") as metadata_file:
         metadata_file.write("Classifier: Super Special Thanks :: Maturin")
     return result
  1. (Set up a normal maturin project otherwise)

  2. Build the wheel:

python -m pip wheel .
  1. Weep when the wheel doesn't contain our super special thanks. How will folks know we love Maturin?!
@thejcannon thejcannon added the bug Something isn't working label Feb 28, 2024
@konstin
Copy link
Member

konstin commented Feb 28, 2024

Maturin ignores the metadata_directory argument in build_wheel which makes it hard to "wrap" build backends and adjust metadata.

Is changing the metadata outside of the build backend allowed in PEP 517? My read was that the build backend controls the metadata. The prepare call is meant for resolver who want to get dependency information but don't actually want to perform the (potentially expensive) compilation (we may not select this version due to conflicts in the deps we get). The cited region in the spec means that you can take this shortcut and have the guarantee that you can build a wheel for installation that has the deps that were used in the resolution.

What's your use case for changing the metadata outside of maturin?

@thejcannon
Copy link
Author

We have a monorepo at work.

So use use backend-path and point to a relative module, which in turn turns relative (including parent dirs) file:// URIs into absolute file:// URIs.

If it simplifies the mental model, the same thing could be accomplished by us publishing the module as a package, setting requires to both our package and maturin, then using ours as the backend.

We'll probably also reuse this package to add the "private" classifier automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants