pypa / setuptools

Official project repository for the Setuptools build system
https://pypi.org/project/setuptools/
MIT License
2.34k stars 1.14k forks source link

[BUG] build_meta: `prepare_metadata_for_build_wheel` hook does not honor `--build-option` #4293

Closed gotmax23 closed 1 month ago

gotmax23 commented 1 month ago

setuptools version

setuptools==69.2.0 and wheel==0.43.0

Python version

Python 3.12

OS

Fedora Linux

Additional environment information

No response

Description

I am trying to run the prepare_metadata_for_build_wheel hook for the https://github.com/Rogdham/pyzstd project as part of the Fedora Linux build process. The project requires passing --dynamic-link-zstd when building without the in-tree zstd copy or else it fails with FileNotFoundError: [Errno 2] No such file or directory: 'zstd/lib/common/'.

I ran

python -c 'from setuptools.build_meta import *; prepare_metadata_for_build_wheel("dist", {"--build-option": "--dynamic-link-zstd"})'

and expected the build backend to pass --dynamic-link-zstd through to the internal setup.py dist_info subcommand that it calls to generate the metadata. Instead, it only passes ['dist_info', '--output-dir', 'dist', '--keep-egg-info'].

Should pyzstd be changed to allow setting this option through a different mechanism (e.g., an environment variable) or can setuptools start honoring --build-option for the prepare_metadata_for_build_wheel hook?

Relates: https://github.com/pypa/setuptools/issues/3896

CC: @Rogdham

Expected behavior

See above

How to Reproduce

Checkout https://github.com/Rogdham/pyzstd without the zstd submodule and run the command mentioned above.

Output

n/a

abravalheri commented 1 month ago

Hi @gotmax23 , setuptools.build_meta was intentionally changed to not pass --build-option to the metadata methods.

This was a decision taken to improve compatibility with pip, see information in the thread starting in https://github.com/pypa/setuptools/issues/2491#issuecomment-1741870404 (key comment: https://github.com/pypa/setuptools/issues/2491#issuecomment-1743723820) for context. I don't think we are going to revert this.

Please also notice that passing parameters via --global-option and --build-option is provided as it is: an experimental attempt to emulate pip's old behaviour, but it is not guaranteed to do exactly what you want (specially because pip's old behaviour is not 100% equivalent/compatible with the build process initially introduced in PEP 517/660).

If you want to pass parameters to commands, the only guaranteed way that works right now is to use configuration files like setup.cfg. See https://setuptools.pypa.io/en/latest/deprecated/distutils/configfile.html for reference.

abravalheri commented 1 month ago

I will go ahead and close this issue now, since this is not a planed feature in setuptools.

If the solution mentioned in https://github.com/pypa/setuptools/issues/4293#issuecomment-2041579801 does not suit the use case, please consider contributing towards https://github.com/pypa/setuptools/discussions/4083.