-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[FR] Design and document a stable mechanism to pass config_settings
to PEP517 backend
#3896
Comments
As a concrete example of something that I'd benefit from being documented: I was trying to figure out how to pass |
I'd use a way to pass options to |
That's what the legacy As you note, since they're not well documented it's a bit hard to piece together how to use them. |
Hello guys, thank you very much for the issue and ping on this topic. I am afraid that what you guys want to achieve right now is not exactly implemented yet. I believe people can right now use something like: python -m build -C--build-option="..." However, by default the same I have been thinking about this for a while and it is a tricky subject to address... Footnotes |
Thanks for the context, after staring (deeply) at various outputs, it seems that passing |
It might as well be, I honestly don't know. My opinion is that Footnotes
|
I think #2491 is related. |
I think once this removal (pypa/pip#11859) goes through, there won't be a way to pass options through. Certainly syntax like |
bump @abravalheri - The pip folks don't have any idea about this and so I think there is some urgency to make sure setuptools works with |
Right now the only documentation that we are able to provide is something along the lines:
Personally, I don't think this is satisfactory. That is why I don't think it is worth including in the docs (I don't want to incentivise people thinking this is stable). To move forward and actually add first class support for
@beckermr or any other person involved in this discussion, would you like to give it a try and propose some PR? It would be nice if we can get help with this topic and that would help to move things forward faster. |
I'd be very very happy to make a PR but I don't actually understand what is happening now, what broke, why it broke, and what needs fixing. :( |
There is nothing really broke. What are options that you want to pass via |
Currently pips global-options passes arbitrary command line switches to the setup.py. This is a common pattern in the wild despite the various PEPs on packaging. I'd like pips config-settings to simply do the same thing. I tried the nested syntax of --config-settings="--global-options=''" and it did not work for me. Idk what the proper behavior is or if something is buggy. |
Probably this happens because --config-settings="--global-options='...'" is passed to all commands when you invoke But there is still the problem using |
Oh hmmmm. In my case, the build command didn't see the arguments at all. I'll cool up some examples and dig in a bit. |
Try |
In Gentoo, we'd really use a way to pass |
Here is my very simple setup.py from setuptools import setup
import sys
print("\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
print(sys.argv)
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n")
setup(
name="blah",
version="0.1.0",
author="MRB",
author_email="MRB@MRB.com",
packages=["blah"],
) And here is what I get $ pip install -vv --config-settings="--build-option=--foo=bar" .
Using pip 23.2.1 from /Users/beckermr/mambaforge/envs/test-fitsio-install/lib/python3.11/site-packages/pip (python 3.11)
Non-user install because site-packages writeable
Created temporary directory: /private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-build-tracker-rcamhhge
Initialized build tracking at /private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-build-tracker-rcamhhge
Created build tracker: /private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-build-tracker-rcamhhge
Entered build tracker: /private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-build-tracker-rcamhhge
Created temporary directory: /private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-install-lb65wn8a
Created temporary directory: /private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-ephem-wheel-cache-rljl7t_9
Processing /Users/beckermr/Desktop/blah
Added file:///Users/beckermr/Desktop/blah to build tracker '/private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-build-tracker-rcamhhge'
DEPRECATION: Config settings are ignored for project file:///Users/beckermr/Desktop/blah. pip 23.3 will enforce this behaviour change. A possible replacement is to use --use-pep517 or add a pyproject.toml file to the project.
Running setup.py (path:/Users/beckermr/Desktop/blah/setup.py) egg_info for package from file:///Users/beckermr/Desktop/blah
Created temporary directory: /private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-pip-egg-info-1cuxrxr_
Running command python setup.py egg_info
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
['/Users/beckermr/Desktop/blah/setup.py', 'egg_info', '--egg-base', '/private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-pip-egg-info-1cuxrxr_']
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
running egg_info
creating /private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-pip-egg-info-1cuxrxr_/blah.egg-info
writing /private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-pip-egg-info-1cuxrxr_/blah.egg-info/PKG-INFO
writing dependency_links to /private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-pip-egg-info-1cuxrxr_/blah.egg-info/dependency_links.txt
writing top-level names to /private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-pip-egg-info-1cuxrxr_/blah.egg-info/top_level.txt
writing manifest file '/private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-pip-egg-info-1cuxrxr_/blah.egg-info/SOURCES.txt'
reading manifest file '/private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-pip-egg-info-1cuxrxr_/blah.egg-info/SOURCES.txt'
writing manifest file '/private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-pip-egg-info-1cuxrxr_/blah.egg-info/SOURCES.txt'
Preparing metadata (setup.py) ... done
Source in /Users/beckermr/Desktop/blah has version 0.1.0, which satisfies requirement blah==0.1.0 from file:///Users/beckermr/Desktop/blah
Removed blah==0.1.0 from file:///Users/beckermr/Desktop/blah from build tracker '/private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-build-tracker-rcamhhge'
Created temporary directory: /private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-unpack-09_cmm5d
Building wheels for collected packages: blah
Created temporary directory: /private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-wheel-r17q4kv3
Building wheel for blah (setup.py) ... Destination directory: /private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-wheel-r17q4kv3
Running command python setup.py bdist_wheel
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
['/Users/beckermr/Desktop/blah/setup.py', 'bdist_wheel', '-d', '/private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-wheel-r17q4kv3']
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
running bdist_wheel
running build
running build_py
/Users/beckermr/mambaforge/envs/test-fitsio-install/lib/python3.11/site-packages/setuptools/_distutils/cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
!!
********************************************************************************
Please avoid running ``setup.py`` directly.
Instead, use pypa/build, pypa/installer or other
standards-based tools.
See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
********************************************************************************
!!
self.initialize_options()
installing to build/bdist.macosx-10.9-x86_64/wheel
running install
running install_lib
creating build/bdist.macosx-10.9-x86_64/wheel
creating build/bdist.macosx-10.9-x86_64/wheel/blah
copying build/lib/blah/__init__.py -> build/bdist.macosx-10.9-x86_64/wheel/blah
running install_egg_info
running egg_info
writing blah.egg-info/PKG-INFO
writing dependency_links to blah.egg-info/dependency_links.txt
writing top-level names to blah.egg-info/top_level.txt
reading manifest file 'blah.egg-info/SOURCES.txt'
writing manifest file 'blah.egg-info/SOURCES.txt'
Copying blah.egg-info to build/bdist.macosx-10.9-x86_64/wheel/blah-0.1.0-py3.11.egg-info
running install_scripts
creating build/bdist.macosx-10.9-x86_64/wheel/blah-0.1.0.dist-info/WHEEL
creating '/private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-wheel-r17q4kv3/blah-0.1.0-py3-none-any.whl' and adding 'build/bdist.macosx-10.9-x86_64/wheel' to it
adding 'blah/__init__.py'
adding 'blah-0.1.0.dist-info/METADATA'
adding 'blah-0.1.0.dist-info/WHEEL'
adding 'blah-0.1.0.dist-info/top_level.txt'
adding 'blah-0.1.0.dist-info/RECORD'
removing build/bdist.macosx-10.9-x86_64/wheel
done
Created wheel for blah: filename=blah-0.1.0-py3-none-any.whl size=1086 sha256=a7cef5949118017121a2b143169ea2831132c09871a27e7365cc60c56cc3d22d
Stored in directory: /private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-ephem-wheel-cache-rljl7t_9/wheels/bd/4f/9e/f4b8cde33b8c6ddebba9ed7b2df0ac3fa4df9736a8c38967c8
Successfully built blah
Installing collected packages: blah
Attempting uninstall: blah
Found existing installation: blah 0.1.0
Uninstalling blah-0.1.0:
Created temporary directory: /Users/beckermr/mambaforge/envs/test-fitsio-install/lib/python3.11/site-packages/~lah-0.1.0.dist-info
Removing file or directory /Users/beckermr/mambaforge/envs/test-fitsio-install/lib/python3.11/site-packages/blah-0.1.0.dist-info/
Created temporary directory: /Users/beckermr/mambaforge/envs/test-fitsio-install/lib/python3.11/site-packages/~lah
Removing file or directory /Users/beckermr/mambaforge/envs/test-fitsio-install/lib/python3.11/site-packages/blah/
Successfully uninstalled blah-0.1.0
Successfully installed blah-0.1.0
Remote version of pip: 23.2.1
Local version of pip: 23.2.1
Was pip installed by pip? False
Removed build tracker: '/private/var/folders/p6/5q6thssj6sx3drv_mrndv1v40000gn/T/pip-build-tracker-rcamhhge' I don't see the flags passed to the subcommands. If I add the |
I see... @beckermr, this is because Since your project does not have a When you add a Once Footnotes
|
Currently there is no support for that due to the open challenges I described in #3896 (comment). The following behaviour is relevant to understand the limitations:
We welcome the community to propose solutions and participate in the implementation that would tackle these challenges. My comment in #3896 (comment) has a few details, but anyone interested in contributing, please feel free to ask questions. The best workaround available today for people interested in using command options would be add/modify the |
I'm afraid I can't add anything that big to my plate. By the way, I wanted to suggest that perhaps using the same mechanism as used to provide |
Currently, options are passed as --flags on sys.argv which are then parsed by a Command object that if I understand correctly expects to own all arguments, fails on unknown ones, and may manually pass known ones on to a subcommand. Maybe a better approach would be for a global option
A Command object would automatically read the global build-options, extract the key it is interested in, and consider that to be the options to parse instead of sys.argv (on the assumption that people won't both use this method and subcommand-options). |
Hi @eli-schwartz thank you very much for the proposal, I like the way it goes!
This might be a bit tricky to pull off, considering that we would need to change the way I wonder if we can have another alternative, e.g.: python setup.py --build-options '{"build_ext.parallel": 8, "bdist_wheel.py_limited_api": "cp311"}' bdist_wheel This might be a bit more straight forward to parse ( Another thing that I was considering is for python setup.py --private-autogenerated-cfg-file /tmp/setuptoos.0183293/build.cfg bdist_wheel Not sure which is better (a JSON/AST-literal string as CLI argument is a bit ugly, but generating a temp file adds a round-trip)... |
I'm not sure there's a particular benefit of json over AST literals (in particular; there's no need for parsing it by non-python code), but there is one pretty annoying downside: if you have a bunch of options to set, and are generating this as a multi-line shell code snippet, it's much easier to use trailing commas for each element. This is totally fine in python dicts, but bizarrely was defined as a syntax error for json.
I think I tried this but could not figure out how to correctly set it, because it protested that there was no such option. I think it's basically equivalent to the setattr approach? The downside of this is that since it doesn't do real option parsing, you rely on the internal attribute name, which at least means that setting "j8" doesn't work, but I notice you suggested "parallel=8" and that does indeed seem to work. It will require additional documentation instead of just saying "the canonical way to pass arguments to subcommands", since only some subcommands work... |
Yeah, right now it is not implemented, I was just mentioning it as brainstorm, hypothetically. The closest you can do nowadays is: export DIST_EXTRA_CONFIG=/tmp/setuptools-build.cfg
echo -e '[build_ext]\nparallel = 8\n[bdist_wheel]\npy_limited_api = cp311' > $DIST_EXTRA_CONFIG
python -m build
The idea was to do something similar to it internally in
I based this on
The CLI parser setuptools uses is inherited from distutils , -j8 is the short-hand version for --parallel=8 (argparse -style). setup.cfg -files accept the long version of the options only.
In terms of implementation I believe that is easier if we bypass the CLI parser... that is why I suggested the simplified |
An author-level workaround for this bug is to follow https://setuptools.pypa.io/en/latest/build_meta.html#dynamic-build-dependencies-and-other-build-meta-tweaks (also the recommended way to customize according to the PEP) and add the following wrapper: # _custom_build/backend.py
from setuptools import build_meta as _orig
from setuptools.build_meta import *
def get_requires_for_build_wheel(config_settings=None):
return _orig.get_requires_for_build_wheel()
def get_requires_for_build_sdist(config_settings=None):
return _orig.get_requires_for_build_sdist()
def get_requires_for_build_editable(config_settings=None):
return _orig. get_requires_for_build_editable() [build-system]
requires = ["setuptools"]
build-backend = "backend"
backend-path = ["_custom_build"] Would it make sense to simply update setuptools itself to ignore |
I fail to see how authors editing their projects to use a custom build backend that silently ignores all config_settings, is a workaround for the bug that was reported by someone who would like to pass options to setuptools, acknowledges it is currently impossible to do safely, and would like to figure out a solution for being able to achieve the desired goal. |
This seems to be the tracking issue in setuptools for the bug that is exposed by fixing the empty The actual issue is just "please document how this is done".
It does not silently ignore all |
config_settings
to PEP517 backend
I am renaming this issue because I believe that only documenting |
config_settings
to PEP517 backendconfig_settings
to PEP517 backend
config_settings
to PEP517 backendconfig_settings
to PEP517 backend
I opened a discussion in #4083 for a possible design. |
Summary
The parameters accepted by the PEP517 build backend don't seem to be documented anywhere. Both
--build-option
and--global-option
are only mentioned inCHANGES.rst
, andbuild_meta.py
code is so convoluted it's hard to figure out how they're supposed to be used correctly.OS / Environment
No response
Additional Information
It would help people use
config_settings
correctly when building via PEP517 backend, and avoid surprises when incorrect uses stop working.Code of Conduct
The text was updated successfully, but these errors were encountered: