-
-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
python.pipInstallHook: avoid producing wrong direct_url.json file #232414
base: staging
Are you sure you want to change the base?
Conversation
hmm, yes, I am not sure whether we can really rely on pname. We need to test this and merge after branch-off. If everything is working well we can always choose to backport to stable. |
This was discussed in https://matrix.to/#/#staging:nixos.org even before the revert happened, but it doesn't solve the whole problem and it seems too late for such changes in 23.05. |
|
For reference, multiple python packages from this list look like suffering from this, at a glance: |
Something weird to me is that #229472 actually got green ✅ CI. There's probably something specific to nixpkgs that I'm misssing, but how am I supposed to know that a PR breaks things before merging (without toasting my laptop)? 🤔 |
These kinds of changes cause rebuild of most packages. That's very expensive; way too much for just a CI. I could set up a separate jobset on hydra.nixos.org for this, so that it can get somewhat stabilized before merging. That is, assuming there's consensus that this is the way to go. |
Though maybe it's an overkill, if it's only expected to be such trivial renames and mostly for packages that fail themselves... in that case I'd expect it could be handled during |
Yes, that's basically the fix. You can see the details in #229472 (comment), but basically, instead of installing the whl file directly, we pass the directory name and the package name, and let python find the correct wheel. That's the official way of getting rid of the buggy I understand the need to be stable at this point, and I don't mind if this doesn't enter 23.05... but I'd just like to ask: How should I proceed now with this fix? Thanks! |
Now that 23.05 has born, I've rebased and cherry-picked bff6c67 again. This should be mergeable now. If there's any way to know if this patch is breaking other packages, please tell me. Otherwise, this one should be ready to merge IIUC. Thanks! |
Hi there! This patch was approved some time ago and merged in #229472. Please read that description if you haven't, to understand how this is important. Then it was reverted in #229472 (comment) due to the release rush. I think there should be a review here now that there's plenty of time until the next release, so we can find and fix any possibly broken builds in the mean time. Would somebody please do the review? Thanks! |
I would like to include this in the python-updates run. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might now have naming conflicts if the internal package name is uppercase like for Twisted, see https:/NixOS/nixpkgs/blob/master/doc/languages-frameworks/python.section.md?plain=1#L1940-L1945
➜ nix build .#python3.pkgs.twisted.dist
➜ ls -lah result-dist
lrwxrwxrwx sandro users 75 B Tue Jul 18 18:42:11 2023 result-dist ⇒ /nix/store/bjc37hqna1g8374d6hp9aq4069dinva9-python3.10-twisted-22.10.0-dist
Also we should really add some helpful error messages otherwise people might be really confused if such a case happens for another package.
Yes, I actually think this is not a good solution. As far as I recall there is no guarantee whatsoever that a package name on PyPI will match with a wheel name. |
When installing many python packages, a `direct_url.json` file appeared in the lib directory. Example: ```sh ➤ nix build nixpkgs/29755fec55e58a315b517d431b2be261772f2b80#python3Packages.flask ➤ cat result/lib/python3.10/site-packages/Flask-2.2.3.dist-info/direct_url.json {"archive_info": {}, "url": "file:///build/Flask-2.2.3/dist/Flask-2.2.3-py3-none-any.whl"}⏎ ``` As you can see, that file contains a wrong reference to `/build`. In https://discuss.python.org/t/pep-610-usage-guidelines-for-linux-distributions/4012/4 there's an explanation on how to avoid this. Here, I'm implementing that change for nixpkgs. @moduon MT-1075
Fix problem detected in NixOS#229472 (comment). Since bff6c67, now pname is expected to match the name of the package that is built by Python standard tools.
This makes sure the problem we're fixing gets fixed.
As seen in NixOS#232414 (review), some packages get built to a different name than nixpkgs' standard pname. Those packages can now use `wheelPname` to get built. Added to Twisted, just to test it out.
I pushed some changes, please review again. Now I have extended the audit tmpdir function. I always wondered why this wasn't detected here:
That test would break almost all python packages if it weren't because I push the fix here too. 😆 But you can run it if you want, to see how Maybe it's not so problematic after all, I'm not sure. According to https://packaging.python.org/en/latest/specifications/direct-url/, it's just metadata. 🤷🏼♂️ But in general I think nothing from /build should land in the drv output. I fixed a couple of derivations, including Twisted, making use of the new |
|
||
disabled = pythonOlder "3.6"; | ||
|
||
src = fetchPypi { | ||
pname = "Twisted"; | ||
pname = wheelPname; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pname = wheelPname; | |
pname = wheelName; |
not sure if that is better or if we should rename the attr in fetchPypi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think wheelPname
is better because it is more intuitive that you need to put the value that you would be putting in pname
and not in name
. The wheel files that are generated include the pname and version (aka name), so here we really care about the pname part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if that is better or if we should rename the attr in fetchPypi
Most times the value will be the same. I can add that attribute there, and assert you're setting only one of both. Since those derivations are FODs, changes there shouldn't produce mass rebuilds.
@@ -22,3 +25,20 @@ if [ -z "${dontUsePipInstall-}" ] && [ -z "${installPhase-}" ]; then | |||
echo "Using pipInstallPhase" | |||
installPhase=pipInstallPhase | |||
fi | |||
|
|||
|
|||
pipAuditTmpdir() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also a tool called pip-audit which makes this a bit confusing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to follow the terminology from here because it's mostly extending that safety net:
auditTmpdir() { |
But just tell me what name you prefer, I can change it, no problem.
We should take a step back here and look at what the problem is that we're trying to solve. PEP 610 describes how frontends should create a The only case we're interested in them, is for PEP 662 editable installations. But that's only when using the phase specific for editable installations. For regular installations, we can still delete the file. Thus, I suggest we always remove the file from the |
It's another possible fix. It just felt more safe for me to let do pip its stuff without interfering. |
Does this still make sense after #248866 was merged? 🤔 |
Fix problem detected in #229472 (comment).
Since bff6c67, now pname is expected to match the name of the package that is built by Python standard tools.
Description of changes
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)