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

python3Packages: fix Python overriding to make <pkg>.overridePythonAttrs work after <pkg>.overrideAttrs #267296

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ShamrockLee
Copy link
Contributor

@ShamrockLee ShamrockLee commented Nov 13, 2023

Description of changes

This patch updates the <pkg>.overrideAttrs inside makeOverridablePythonPackage (the function that adds <pkg>.overridePythonAttrs). If applied, <pkgs>.overridePythonAttrs will work after applying <pkg>.overrideAttrs to override a Python package built with buildPythonPackage or buildPythonApplication.

This patch also adds corresponding test cases to tests.overriding.

Closes #267293.

Initial effort for #271387.

Cc: @FRidh

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
  • 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/)
  • 23.11 Release Notes (or backporting 23.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
  • Fits CONTRIBUTING.md.

@ShamrockLee ShamrockLee changed the title makeOverridablePythonPackage: fix Python overriding to make <pkg>.overridePythonAttrs work after <pkg>.overrideAttrs python3Packages: fix Python overriding to make <pkg>.overridePythonAttrs work after <pkg>.overrideAttrs Nov 13, 2023
@ShamrockLee ShamrockLee force-pushed the python-overrideattrs-fix branch 2 times, most recently from 205c377 to 2cf1c3c Compare November 13, 2023 21:17
@ShamrockLee ShamrockLee marked this pull request as ready for review November 13, 2023 21:44
@ShamrockLee ShamrockLee requested a review from FRidh as a code owner November 13, 2023 21:44
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 10.rebuild-linux: 1 labels Nov 13, 2023
@ShamrockLee ShamrockLee force-pushed the python-overrideattrs-fix branch 2 times, most recently from e16c5f0 to ac74756 Compare November 19, 2023 22:16
@ShamrockLee ShamrockLee force-pushed the python-overrideattrs-fix branch from ac74756 to 971cac5 Compare November 30, 2023 23:12
@ShamrockLee
Copy link
Contributor Author

@ofborg build tests.overriding

pkgs/test/overriding.nix Outdated Show resolved Hide resolved
pkgs/test/overriding.nix Outdated Show resolved Hide resolved
Comment on lines 40 to 43
if builtins.isAttrs result then result
// lib.optionalAttrs (result ? overrideAttrs) { overrideAttrs = fdrv: overrideResult (drv: drv.overrideAttrs fdrv); }
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need () here or are the redundant?

Copy link
Contributor Author

@ShamrockLee ShamrockLee Dec 2, 2023

Choose a reason for hiding this comment

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

I don't quite get it.

result?overrideAttrs would be true only when result is an attribute. Maybe it would be more readable this way:

if builtins.isAttrs result then
  result // lib.optionalAttrs (result?overrideAttrs) {
    overrideAttrs =...;
  }
else if ...

If you are talking about the let-in construct above the if-then-else construct, it surely doesn't need parenthesis.

nix-repl> let in if 2 + 2 == 5 then "y" else "n"
"n"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't we need () here or are the redundant?

Or do you mean that set?attr has higher precedence over function application and the parenthesis around it is redundant?

@ShamrockLee ShamrockLee force-pushed the python-overrideattrs-fix branch from b2ebd09 to 7928373 Compare December 3, 2023 09:35
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 4, 2024
@ShamrockLee ShamrockLee force-pushed the python-overrideattrs-fix branch from 7928373 to 40ad5e6 Compare August 9, 2024 16:04
@ShamrockLee ShamrockLee requested a review from natsukium as a code owner August 9, 2024 16:04
@ShamrockLee
Copy link
Contributor Author

I rebased the feature branch and resolved the merge conflict.

@SomeoneSerge SomeoneSerge self-requested a review August 10, 2024 00:38
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 10, 2024
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 10, 2024
@ShamrockLee ShamrockLee force-pushed the python-overrideattrs-fix branch from 40ad5e6 to 13aafb0 Compare December 19, 2024 15:35
@nix-owners nix-owners bot requested a review from mweinelt December 19, 2024 15:37
@github-actions github-actions bot added 10.rebuild-darwin: 1-10 and removed 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1 labels Dec 19, 2024
@ShamrockLee ShamrockLee removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Dec 19, 2024
@ShamrockLee ShamrockLee force-pushed the python-overrideattrs-fix branch from 13aafb0 to d77a5ff Compare December 19, 2024 16:08
@ShamrockLee ShamrockLee marked this pull request as draft December 19, 2024 16:12
ShamrockLee and others added 4 commits January 15, 2025 13:18
Test with pip, which is less likely to fail.

Modularize the transforming function and testing function.

Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
Make it possible to mix overridePythonAttrs and overrideAttrs, i.e.
((<pkg>.overrideAttrs (_: { foo = "a"; })).overridePythonAttrs (_: { })).foo now works
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.

<pkg>.overridePythonAttrs doesn't work together with <pkg>.overrideAttrs
3 participants