Skip to content

python3Packages.pythonMetadataCheckHook: init - #532778

Merged
mweinelt merged 138 commits into
NixOS:stagingfrom
dotlambda:python3Packages.pythonMetadataCheckHook
Jul 11, 2026
Merged

mweinelt merged 138 commits into
NixOS:stagingfrom
dotlambda:python3Packages.pythonMetadataCheckHook

Conversation

@dotlambda

Copy link
Copy Markdown
Member

This hook is supposed to check (for now) that the version in *.dist-info/METADATA is the same as what's specified in the derivation.
The rationale for this is that a pyproject.toml often specifies dynamic = ["version"] which leads to a version of 0.0.0 unless patched manually.
Since the hook uses importlib.metadata.version("$pname") it also checks that the pname is plausible (it could belong to a dependency instead). But doesn't check whether it's correctly normalized.
In the future the hook can compare even more metadata.

Note that e.g. importlib.metadata.version('flit-core') works because the function normalizes the distribution name to flit_core.

Questions to answer:

  • Should this be part of one of the existing hooks?
  • Do we run it by default after fixing (lots of) breakage on python-updates?
  • Should this rather be implemented like the pythonRuntimeDepsCheckHook which parses METADATA manually?

Things done

@dotlambda
dotlambda requested a review from mweinelt June 17, 2026 20:51

@Sigmanificient Sigmanificient left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i did not know this could be checked. interesting!

@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 6.topic: python Python is a high-level, general-purpose programming language. labels Jun 17, 2026
@mweinelt

Copy link
Copy Markdown
Member

Enabled by default with a knob to disable. These things are important and too easy to miss.

@dotlambda

Copy link
Copy Markdown
Member Author

Enabled by default with a knob to disable.

dontUsePythonMetadataCheck is already implemented.
It could be more fine-grained though, e.g. only disabling the version check (which is the only one right now).

@mweinelt

Copy link
Copy Markdown
Member

I'm super annoyed by the number of dontSomething vars that exist. They are bad UX and should not exist in this unstructured form.

@dotlambda

Copy link
Copy Markdown
Member Author

What would you prefer?

@mweinelt

mweinelt commented Jun 17, 2026 •

Copy link
Copy Markdown
Member

e.g.

disabledHooks.metadataCheck = true

and you get an error, if no such hook exists. And the hooks point to that option to disable them, when it fails.

@dotlambda

dotlambda commented Jun 17, 2026 •

Copy link
Copy Markdown
Member Author

Sounds good to me, but is this the right place to start such a thing?

EDIT: Though making disabledHooks a list might be easier.

@mweinelt

Copy link
Copy Markdown
Member

Nah, it's not. This is just my aversion to these lengthy env vars.

@dotlambda
dotlambda force-pushed the python3Packages.pythonMetadataCheckHook branch from 6b60bee to 001e7bd Compare June 17, 2026 23:37
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 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. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. and removed 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. labels Jun 17, 2026
@dotlambda
dotlambda force-pushed the python3Packages.pythonMetadataCheckHook branch from 001e7bd to 130558d Compare June 18, 2026 00:03
@dotlambda

Copy link
Copy Markdown
Member Author

Should this apply to buildPythonApplication at all? There we don't really need to care about the METADATA being correct.

@dotlambda dotlambda added the 9.needs: help on darwin Also consider pinging @NixOS/darwin-maintainers. label Jun 18, 2026
@mweinelt

Copy link
Copy Markdown
Member

Yeah, makes only really sense for libraries to enforce it.

@dotlambda
dotlambda force-pushed the python3Packages.pythonMetadataCheckHook branch from 130558d to a550a30 Compare June 18, 2026 01:17
@mweinelt

Copy link
Copy Markdown
Member

Should this apply to buildPythonApplication at all? There we don't really need to care about the METADATA being correct.

Which means toPythonModule should add it back, I guess.

@dotlambda

Copy link
Copy Markdown
Member Author

Should the hook be skipped if unstable- is found in the version?

@nixos-discourse

Copy link
Copy Markdown

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

https://discourse.nixos.org/t/bypassing-pythonmetadatacheckphase/79150/2

samagcarr added a commit to samagcarr/nixarr that referenced this pull request Jul 24, 2026
nixos-cuda-channel-updater Bot pushed a commit to nixos-cuda/nixpkgs that referenced this pull request Jul 25, 2026
This change fixes `nix build .#sage`. The regression is due to a new check, pythonMetadataCheckHook,
introduced in NixOS#532778; the check enforces that pname matches the metadata name of the underlying Python
project being built, typically in pyproject.toml; in this case the underlying name is "sagemath".
@linsui linsui mentioned this pull request Jul 25, 2026
3 of 13 tasks
@pbsds

pbsds commented Jul 27, 2026

Copy link
Copy Markdown
Member

@marius851000 marius851000 mentioned this pull request Jul 29, 2026
4 tasks done
moeleak pushed a commit to moeleak/nixpkgs that referenced this pull request Jul 30, 2026
This change fixes `nix build .#sage`. The regression is due to a new check, pythonMetadataCheckHook,
introduced in NixOS#532778; the check enforces that pname matches the metadata name of the underlying Python
project being built, typically in pyproject.toml; in this case the underlying name is "sagemath".
friday pushed a commit to Ulauncher/Ulauncher that referenced this pull request Aug 2, 2026
nixpkgs added validation to check the specified vs built version some ~20 days ago: [NixOS/nixpkgs#532778](NixOS/nixpkgs#532778) 

This change make our version work with it
@lucasew lucasew mentioned this pull request Aug 3, 2026
4 of 13 tasks
@vncsb

vncsb commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Hi @dotlambda
When building netexec, Im getting this error on pythonMetadataCheckPhase of the bloodhound-py dependency.

importlib.metadata.PackageNotFoundError: No package metadata was found for bloodhound-py

I believe this is due to a wrong pname but the error does not happen when building only bloodhound-py. netexec uses buildPythonApplication and bloodhound-py has doCheck = false, is this behavior expected? If yes, could you give me some guidance on how to fix the pname seeing that a package with the pname that would match the metadata (bloodhound) already exists?

@dotlambda

Copy link
Copy Markdown
Member Author

@vncsb python3Packages.bloodhound-py should be called python3Packages.bloodhound and its pname needs to be fixed

dotlambda added a commit that referenced this pull request Oct 8, 2026
dotlambda added a commit that referenced this pull request Oct 9, 2026
mweinelt pushed a commit that referenced this pull request Oct 10, 2026
doronbehar pushed a commit to debtquity/nixpkgs that referenced this pull request Oct 28, 2026
PR NixOS#532778 added `pythonMetadataCheckPhase`, which [raised][1] the mismatch
between upstream's GitHub repository name and the `project.name` they
use in their `pyproject.toml`. They started using `parsnip-cif` [long
ago][2], before the package was [added to nixpkgs][3].

[1]: https://hydra.nixos.org/build/350404512/step/1/log
[2]: glotzerlab/parsnip@6eb4017
[3]: NixOS@f1f6b55
doronbehar pushed a commit to debtquity/nixpkgs that referenced this pull request Oct 28, 2026
PR NixOS#532778 added `pythonMetadataCheckPhase`, which would have raised the
mismatch between upstream's GitHub repository name and the
`project.name` they use in their `pyproject.toml`. They started using
`freud-analysis` first in [3.2.0], so this rename should have been part
of the [3.1.0 -> 3.3.1 version bump][2].

[1]: glotzerlab/freud@486a82c
[2]: NixOS@4c8c77b
sarahec pushed a commit to sarahec/nixpkgs that referenced this pull request Oct 28, 2026
PR NixOS#532778 added `pythonMetadataCheckPhase`, which [raised][1] the mismatch
between upstream's GitHub repository name and the `project.name` they
use in their `pyproject.toml`. They started using `parsnip-cif` [long
ago][2], before the package was [added to nixpkgs][3].

[1]: https://hydra.nixos.org/build/350404512/step/1/log
[2]: glotzerlab/parsnip@6eb4017
[3]: NixOS@f1f6b55
sarahec pushed a commit to sarahec/nixpkgs that referenced this pull request Oct 28, 2026
PR NixOS#532778 added `pythonMetadataCheckPhase`, which would have raised the
mismatch between upstream's GitHub repository name and the
`project.name` they use in their `pyproject.toml`. They started using
`freud-analysis` first in [3.2.0], so this rename should have been part
of the [3.1.0 -> 3.3.1 version bump][2].

[1]: glotzerlab/freud@486a82c
[2]: NixOS@4c8c77b
@TheLimifiedLime TheLimifiedLime mentioned this pull request Nov 13, 2026
5 of 13 tasks
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. 9.needs: help on darwin Also consider pinging @NixOS/darwin-maintainers. 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-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 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. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants