Skip to content
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

pythonPackages: ensure all derivations provide python modules #194205

Merged
merged 3 commits into from
Oct 27, 2022

Conversation

FRidh
Copy link
Member

@FRidh FRidh commented Oct 3, 2022

This adds a test to ensure no new uses of buildPythonApplication can be added to python-packages.nix.

Python packages can be grouped into two groups: 1) applications and 2) packages providing importable modules. In python-packages.nix we only want to have 2). 1) should be in the top-level package set.

Description of changes
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.11 Release Notes (or backporting 22.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@mweinelt
Copy link
Member

mweinelt commented Oct 3, 2022

Wondering if the eval failure is the result of the one remaining application package: openrazer-daemon. If so, this is pretty hard to glean from the trace.

#194095

@FRidh
Copy link
Member Author

FRidh commented Oct 3, 2022

Ha, no, this test fails because I forgot about setuphooks. In this case the wrapPython hook:

error: wrapPython should use `buildPythonPackage` or `toPythonModule` if it is to be part of the Python packages set.

I wonder how to exempt those...

We really need types in Nixpkgs so we can check them and filter based on them.

@SuperSandro2000
Copy link
Member

Is there an eval penalty to this? and if so how high would it be?

@FRidh
Copy link
Member Author

FRidh commented Oct 4, 2022

Is there an eval penalty to this? and if so how high would it be?

Additional eval load is negligible for this.

We really need types in Nixpkgs so we can check them and filter based on them.

Other solutions:

  1. whitelist
  2. mark setup hooks as such and allow hooks

Some packages to consider as well:

  • python (the interpreter), I think we could use toPythonModule on it.
  • recursivePthLoader. Should get rid of this.

@FRidh FRidh changed the base branch from staging to master October 25, 2022 11:10
@FRidh FRidh requested a review from jonringer as a code owner October 25, 2022 13:39
@FRidh
Copy link
Member Author

FRidh commented Oct 25, 2022

Cross is broken with this change.

This adds a test to ensure no new uses of `buildPythonApplication` can
be added to `python-packages.nix`.

Python packages can be grouped into two groups: 1) applications and 2)
packages providing importable modules. In `python-packages.nix` we only
want to have 2). 1) should be in the top-level package set.

To achieve this, all setup hooks need to be marked as being a setup hook.
For the setup hooks in the Python packages set this is done by creating
a new builder, `makePythonHook`.

Because there were issues with splicing, the file importing all the hooks
is converted to an extension. All non-packages were moved out of `python-packages.nix`
into `python-packages-base.nix`. The `keep` argument to `makeScopeWithSplicing
was cleaned up as well; there is no need to keep this one manually in sync
reducing the risk of breaking cross-compilation.
@FRidh
Copy link
Member Author

FRidh commented Oct 26, 2022

Everything seems to be OK now. I am surprised to see rebuilds though.

@FRidh
Copy link
Member Author

FRidh commented Oct 27, 2022

Some packages now get a duplicate package in a closure. I guess an incorrect hook is being used.

- Don't call from a different scope
- Disable catching of conflicts because we do get a (installation-time
only) conflict due to overrides in awscli.
This is the recommended way. It won't actually matter here though.
@FRidh
Copy link
Member Author

FRidh commented Oct 27, 2022

Bytecode has differences in filenames, but that would be fixed if we would build wheels as intermediate step and use CA then.

@ofborg ofborg bot requested a review from zaninime October 27, 2022 07:48
@FRidh FRidh merged commit 0c5c895 into NixOS:master Oct 27, 2022
@FRidh FRidh deleted the ensure branch October 27, 2022 08:03
@andrevmatos
Copy link
Member

This seems to have broken neovim-remote on the stdenv call in doCheck.

@FRidh
Copy link
Member Author

FRidh commented Oct 28, 2022

This seems to have broken neovim-remote on the stdenv call in doCheck.

#198281

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/i-cant-update-my-system-due-to-buildpythonpackage/22886/7

gador pushed a commit to gador/nixpkgs that referenced this pull request Nov 4, 2022
@Artturin
Copy link
Member

Artturin commented Nov 6, 2022

this broke the fix i did in #196052 (comment)

before 33d12e5:

nix-repl> pkgsCross.aarch64-multiplatform.python3Packages.xpybutil.nativeBuildInputs
[ «derivation /nix/store/hvb9yxgv1133cfhxxd869sibldvv2vdx-python3-3.10.7.drv» «derivation /nix/store/v880cnh4ml7czmivfbk3cdh93hz9yvbn-hook.drv» «derivation /nix/store/f243ab7wv92gqsmc9h7gr0qcnj0xcgdb-hook.drv» «derivation /nix/store/880lf8895bzn8d94lrr2y7ilgkxq0lc4-python-remove-tests-dir-hook.drv» «derivation /nix/store/fzjnhawfs1wpw58hcd1vxd9y750dc08y-python-remove-bin-bytecode-hook.drv» «derivation /nix/store/n8l59iparx98yfw8g5ydqmzmk3fdic75-setuptools-setup-hook.drv» «derivation /nix/store/7vyhynlaxlva1rpvfl0hpdl3qywi9qmc-pip-install-hook.drv» «derivation /nix/store/0l76r5pf69smrl631qa801sjkyb8isk6-python-namespaces-hook.sh.drv» «derivation /nix/store/zipz2sj6ncyllb2z53p0fmsirq601rj7-python-output-dist-hook.drv» ]

after 33d12e5:

nix-repl> pkgsCross.aarch64-multiplatform.python3Packages.xpybutil.nativeBuildInputs
[ «derivation /nix/store/bhz39ds4v02hn6x4py4mzjyilw4a589h-python3-aarch64-unknown-linux-gnu-3.10.7.drv» «derivation /nix/store/q0pdz5z18bfra7841qwdqq9i3g5na3w7-hook.drv» «derivation /nix/store/f243ab7wv92gqsmc9h7gr0qcnj0xcgdb-hook.drv» «derivation /nix/store/880lf8895bzn8d94lrr2y7ilgkxq0lc4-python-remove-tests-dir-hook.drv» «derivation /nix/store/fzjnhawfs1wpw58hcd1vxd9y750dc08y-python-remove-bin-bytecode-hook.drv» «derivation /nix/store/x9b2q51spifxvzsxj90if1h4nb617pys-setuptools-setup-hook.drv» «derivation /nix/store/zsh90vnqf3zblmrlyh8py5hxky2bk78a-pip-install-hook.drv» «derivation /nix/store/a4cyp1fcsnlppzrwwbk1ka5xhbj52hnm-python-namespaces-hook.sh.drv» «derivation /nix/store/2hc97nsdi375cv13014c4lardpxk2mgw-python-output-dist-hook.drv» ]

inherit toPythonModule toPythonApplication;
inherit buildSetupcfg;

python = toPythonModule python;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toPythonModule is probably discarding the splicing and that's why the fix is broken

Will test later

@Artturin Artturin mentioned this pull request Apr 14, 2023
12 tasks
Artturin added a commit to Artturin/nixpkgs that referenced this pull request Jul 26, 2023
`lib.extends hooks pythonPackagesFun` includes python which we want to
splice

what this fixes:
```
nix-repl> lib.elemAt pkgsCross.aarch64-multiplatform.python3Packages.xpybutil.nativeBuildInputs 0
«derivation /nix/store/39dkb51rciw6zwg0c2c44gpmpjapddxc-python3-aarch64-unknown-linux-gnu-3.10.12.drv»
```
to
```
nix-repl> lib.elemAt pkgsCross.aarch64-multiplatform.python3Packages.xpybutil.nativeBuildInputs 0
«derivation /nix/store/21ldw2dp26xvv9iyxn9x77a8yh4waqz5-python3-3.10.12.drv»
```

Before NixOS#194205 The keep python used to work by accident because self was passed from
__splicedPackages https://github.com/NixOS/nixpkgs/pull/196052/files#diff-44ce3495c4f983ce64dd47c86a9d3e77bad210b2709c098a3806998dcd9b000bR213
But now it does not work because overrideAttrs is used on python in
python-packages-base.nix

Preferably we would [ splice the hooks too ](NixOS#228139) but we cannot do that until [Package sets within derivations (i.e. python3.pkgs) are not spliced](NixOS#211340) is fixed, because people often use `python3.pkgs.wrapPython` in `nativeBuildInputs` (it's correct but python3.pkgs should be python3Packages to get splicing.
rtimush pushed a commit to rtimush/nixpkgs that referenced this pull request Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants