pypa / pip

The Python package installer
https://pip.pypa.io/
MIT License
9.5k stars 3.01k forks source link

Allow changing build isolation settings in setup.py #12978

Open Martmists-GH opened 2 weeks ago

Martmists-GH commented 2 weeks ago

What's the problem this feature will solve?

I'm working on a tool to target the CPython API with custom languages. For this purpose, an external build tool is used.

Ever since build isolation, everyone will need to add --no-build-isolation when installing a library built with this.

Describe the solution you'd like

If we can toggle the --no-build-isolation flag in setup.py, we can make sure the files configuring the external build system are present.

Alternative Solutions

I have not found a way to tell pip to include the build toolchain (e.g. Gradle) from the current directory to the temporary directory it runs the build step in.

Additional context

Example of a toolchain using Gradle: https://github.com/Martmists-GH/kpy-plugin

Code of Conduct

notatallshaw commented 1 week ago

The interaction between the frontend (in this case Pip) and the backend (in this case setuptools) is defined by PEP 517: https://peps.python.org/pep-0517/#build-backend-interface

My understanding of the design is the communication goes only one way, frontend to backend, so that it easier to reason about. Regardless, any changes to what is communicated between the frontend and the backend, needs to be defined as a new standard, as there are many different tools that can be a frontend and/or a backend that aren't pip or setuptools (e.g. poetry, uv, hatch, pdm, etc...). To discuss a new standard, you would need to make a post here: https://discuss.python.org/c/packaging/14

However, be aware, you can also change the the default option of no-build-isolation to true either via setting it in the config: pip config set global.no-build-isolation true, or setting the environmental variable: PIP_NO_BUILD_ISOLATION=1

Martmists-GH commented 1 week ago

So can I just add os.environ["PIP_NO_BUILD_ISOLATION"] = "1" to my setup.py?

notatallshaw commented 1 week ago

I don't think so, because by the time setuptools calls setup.py it will already be in an isolated build environment.