Skip to content

buildPython*: pass check-related args whenever specified#376060

Merged
mweinelt merged 1 commit intoNixOS:stagingfrom
ShamrockLee:build-python-check-args
May 23, 2025
Merged

buildPython*: pass check-related args whenever specified#376060
mweinelt merged 1 commit intoNixOS:stagingfrom
ShamrockLee:build-python-check-args

Conversation

@ShamrockLee
Copy link
Contributor

@ShamrockLee ShamrockLee commented Jan 23, 2025

Pass

  • disabledTestMarks
  • disabledTestPaths
  • disabledTests
  • enabledTestMarks
  • enabledTestPaths
  • enabledTests
  • pytestFlags
  • pytestFlagsArray
  • unittestFlags
  • unittestFlagsArray

whenever they are specified,
no matter if doCheck is true or if they are empty lists.

This PR simplifies the buildPython* argument handling and brings us closer to deprecating overridePythonAttrs and adopting fixed-point arguments.

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)
    • sandbox = relaxed
    • sandbox = true
  • 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/)
  • 25.05 Release Notes (or backporting 24.11 and 25.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.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added the 6.topic: python Python is a high-level, general-purpose programming language. label Jan 23, 2025
@wolfgangwalther
Copy link
Contributor

Any idea why it was done the way it was done before?

@ShamrockLee
Copy link
Contributor Author

Any idea why it was done the way it was done before?

The doCheck guard is added in #327264, saying it would be "useful when running the tests separately in passthru.tests."

I doubt guarding the flags this way would be as effective as intended, as neither checkPhase (installCheckPhase) nor checkInputs (installCheckInputs) are guarded.

@wolfgangwalther
Copy link
Contributor

wolfgangwalther commented Jan 23, 2025

To achieve the effect, wouldn't we need to guard this on separateChecks somehow?

Edit: Ah, #272177 wasn't even merged. So it seems like the guards will only be useful once that's done, right?

@github-actions github-actions bot added 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Jan 23, 2025
@ShamrockLee
Copy link
Contributor Author

To achieve the effect, wouldn't we need to guard this on separateChecks somehow?

The original PR was an initial effort for #272177, but it was unfortunately closed due to author burnout.

It is more practical to re-work the guard if someone wants to pick up the automatic-passthru-test work.

@ShamrockLee
Copy link
Contributor Author

Edit: Ah, #272177 wasn't even merged. So it seems like the guards will only be useful once that's done, right?

I think so.

@ShamrockLee ShamrockLee marked this pull request as ready for review January 23, 2025 11:34
@nix-owners nix-owners bot requested a review from mweinelt January 23, 2025 11:36
@ShamrockLee
Copy link
Contributor Author

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 376060


x86_64-linux

@natsukium
Copy link
Member

Some Python packages, especially scientific ones, have expensive tests.
Their compilation time is also usually expensive because they are written in C++, Rust, etc.
Therefore, such packages already separate their tests into passthru.tests, even if separateChecks is not implemented.

I doubt guarding the flags this way would be as effective as intended, as neither checkPhase (installCheckPhase) nor checkInputs (installCheckInputs) are guarded.

In python packages, checkPhase is provided by pytestCheckHook in most cases, so it is unlikely to be changed.
While nativeCheckInputs may be worth blocking, I think we already block the attributes we most often change to make tests green.

However, I do not intend to prevent our ideals with these hacks, so I believe we could remove it if necessary.

@ShamrockLee
Copy link
Contributor Author

Therefore, such packages already separate their tests into passthru.tests, even if separateChecks is not implemented.

I understand this as we add such guards as a shorthand to "move" the attributes to passthru.tests so we could write, e.g., passthru.tests.check = self.overridePythonAttrs { doCheck = true; }; without having to manually place all the check-related attributes under the definition of passthru.tests.check. Is that correct?

If so, why do people not just define the check-related attributes under the package test definition (e.g., the passthru.tests.check above)?

@natsukium
Copy link
Member

I understand this as we add such guards as a shorthand to "move" the attributes to passthru.tests so we could write, e.g., passthru.tests.check = self.overridePythonAttrs { doCheck = true; }; without having to manually place all the check-related attributes under the definition of passthru.tests.check. Is that correct?

Yes, absolutely.

If so, why do people not just define the check-related attributes under the package test definition (e.g., the passthru.tests.check above)?

I guess they didn't think to guard the flags, because it was also a known hack to avoid circular imports.
I introduced this guard to avoid checkArgs, an attribute proposed in #272177, but I think it is a good idea to define flags in passthru.tests.

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one person. label Feb 2, 2025
@ShamrockLee
Copy link
Contributor Author

I guess they didn't think to guard the flags because it was also a known hack to avoid circular imports.

This means we must transit all the packages currently using such a hack before merging this PR to avoid breakage.

@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Feb 2, 2025

As the tree-wide transition is unavoidable (even if the total number of affected packages is not necessarily large), I would prefer resuming (re-implementing) #272177 before the migration to make the effort more meaningful.

As for the checkArgs, I prefer an extension-style passthru.overridePythonCheck similar to buildGoModule's overrideModAttrs.

Here's a worked prototype: staging...ShamrockLee:build-python-passthru-check
It depends on #376372 merging and going from master to staging, with three commits that

  • pass the check-related args directly
  • implement optional tests.python-check
  • transit python3Packages.pygments to use tests.python-check

@natsukium @wolfgangwalther Do you think this is a good idea, or should we proceed with the transition directly?

@ShamrockLee ShamrockLee marked this pull request as draft February 2, 2025 23:03
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Feb 15, 2025
@ShamrockLee ShamrockLee marked this pull request as ready for review March 23, 2025 14:50
@ShamrockLee
Copy link
Contributor Author

I guess they didn't think to guard the flags, because it was also a known hack to avoid circular imports.

Performing checks separately avoids circular dependency for test cases, but how does it related to guarding the flags? The flags are mostly plain strings, and has no effect when doCheck = false.

In addition, if the flags cause circular dependency, the evaluation would fail. If the evaluation work, it should be safe to merge this PR.

@ShamrockLee ShamrockLee force-pushed the build-python-check-args branch from ed926ea to 8b87a19 Compare March 23, 2025 15:46
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Mar 23, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. labels Mar 23, 2025
@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Mar 23, 2025

These packages, found with the following find command plus manual filtering, specifies doCheck = false due to cyclic/circular dependencies, and also specifies one of the previously-guarded flags attributes. I think this is enough to check if this PR could be merged without tree-wide package migration.

find pkgs/development/python-modules -type f -name "*.nix" \
  -exec grep -q "doCheck = false" {} \; \
  -exec grep -q "\([Cc]ircular\|[Cc]yclic\)" {} \; \
  -exec grep -q '\(disabledTest\|pytestFlags\|unittestFlags\)' {} \; \
  -print

@ofborg build python3Packages.pygments
@ofborg build python3Packages.torchmetrics
@ofborg build python3Packages.mlflow
@ofborg build python3Packages.libcst
@ofborg build python3Packages.build
@ofborg build python3Packages.opentelemetry-sdk

@ShamrockLee ShamrockLee force-pushed the build-python-check-args branch from 8b87a19 to 90c4e30 Compare March 31, 2025 01:36
@ShamrockLee
Copy link
Contributor Author

@wolfgangwalther, are you still approving this change?

Pass
- disabledTestMarks
- disabledTestPaths
- disabledTests
- enabledTestMarks
- enabledTestPaths
- enabledTests
- pytestFlags
- pytestFlagsArray
- unittestFlags
- unittestFlagsArray

whenever they are specified,
no matter if doCheck is true or if they are empty lists.

Simplify the buildPython* argument handling
and bring us closer to the deprecation of overridePythonAttrs
and the adoption of fixed-point arguments.
@ShamrockLee ShamrockLee force-pushed the build-python-check-args branch from 90c4e30 to 67564e0 Compare April 29, 2025 22:27
@ShamrockLee
Copy link
Contributor Author

@ofborg build python3Packages.pygments
@ofborg build python3Packages.torchmetrics
@ofborg build python3Packages.mlflow
@ofborg build python3Packages.libcst
@ofborg build python3Packages.build
@ofborg build python3Packages.opentelemetry-sdk

@mweinelt mweinelt merged commit 567f0e5 into NixOS:staging May 23, 2025
51 checks passed
@mweinelt
Copy link
Member

Thanks for working on these things!

@ShamrockLee ShamrockLee deleted the build-python-check-args branch October 23, 2025 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: python Python is a high-level, general-purpose programming language. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants