-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
find_ruff_bin does not work as a build dependency with pip #13321
Comments
This doesn't seem like a Ruff bug? It looks like pip isn't installing the build requirement ( zanieb/ruff-find-bin-during-pip-build@2cd719e |
I do not believe what you say is correct. If you check the logs, you can see that Pip actually is installing the package:
And actually the stack trace confirms this:
See ruff is installed into The problem is that Pip does not use virtual environments for building packages, but rather isolated environments. And the discovery mechanism here assumes this is going to be a virtual environment. I will leave it to you to argue with the PIP maintainers if PEP 517 requires a virtual environment or an isolated environment should suffice. Actually, the PEP explicitly calls it out that virtual environments not required: https://peps.python.org/pep-0517/#build-environment
Which then makes it a ruff bug. You enabling PEP-517 is a no op because PEP-517 is enabled by default in pip. |
What is the isolated environment you refer to? How are they creating it? Does it follow a specification somewhere? Can its root be discovered using
Is this true? I think it's enabled by default sometimes, but not always? We get issues every day of people reporting different uv vs pip behavior because pip isn't using build isolation on their system. Just wondering, why are you using Ruff as a build dependency? |
(In general, I don't believe this is true. It's enabled by default for |
I think for all modern packages. Which is the case here too.
Have an app that generates during build some code from a JSON schema, and the library uses ruff afterward to format the generated code.
From the above stack trace:
A pip maintainer would be able to answer these questions better than me. Note, that PEP-517 never requires the isolated environment to be sysconfig discoverable and I assume is not. |
https://github.com/pypa/pip/blob/main/src/pip/_internal/build_env.py#L81-L139 I believe contains the implementation detail answers... perhaps a cheap solution would be to look for |
Thanks for pulling that up. I think we've explicitly avoided finding the Ruff binary on the PATH because we can't really know that it's the correct Ruff executable associated with the module. I'm looking at the |
FWIW using uv over pip fixes the issue, but some of our internal systems are not uv ready yet... |
I guess I'd just recommend using a different strategy to find the Ruff binary in the meantime, like |
I don't control the package doing the generation and this method is name for solving this problem, needing another solution doesn't feels right... |
Yea, pip's isolation is a weird setup that's not quite a virtual environment for $legacy reasons around how things worked with Python 2 and all that IIRC. I've wanted to clean that up for a while but haven't come around to it due to a lack of time. I don't think you can get the information about the isolated environment's paths from |
So @zanieb what is the action plan here? |
@zanieb ping 😊 |
Please don't ping us repeatedly — it's bad form. I don't have an action plan here — it's a weird use case and there's not a clear solution. The upstream package should probably switch from using If there's a heuristic we can use to understand we're in a bespoke pip build environment, I'm all ears. |
How about this close-enough approximation:
We take a ruff from the first entry of If we really want to be safe, we can also check the presence of the Thanks! |
It seems reasonable from a correctness perspective, but a bit dubious for long-term maintenance. I'm not sure. Let me see what other people on the team think. |
FWIW |
I suppose I'm alright with it. (Is that a reliable heuristic on all platforms?) |
Yes, following their implementation of the isolated build environment, this should work reliably on all platforms. |
See reproducible at https://github.com/gaborbernat/ruff-find-bin-during-pip-build/actions/runs/10802198412/job/29963805989
With code gaborbernat/ruff-find-bin-during-pip-build@fd532e8
In this case, the host Python is the installer Python, but the expectation is to find it in the pip isolated environment
cc @pradyunsg I am not sure if this is a pip bug or a uv bug... but the binary gets discovered correctly when installing with uv, but discovers in host Python when using pip.
cc @charliermarsh I believe this is also a bug for uv itself for find_uv_bin...
The text was updated successfully, but these errors were encountered: