mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-08-25 17:55:21 +00:00
python3Packages.pythonMetadataCheckHook: rewrite comparison in Python
This commit is contained in:
@@ -369,6 +369,7 @@ in
|
||||
inherit pythonInterpreter pythonSitePackages;
|
||||
pythonWithPackaging = lib.getExe (pythonOnBuildForHost.withPackages (ps: [ ps.packaging ]));
|
||||
retrieveMetadata = ./python-metadata-check-hook-retrieve.py;
|
||||
compareMetadata = ./python-metadata-check-hook-compare.py;
|
||||
};
|
||||
meta = {
|
||||
maintainers = [ lib.maintainers.dotlambda ];
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
from packaging.version import InvalidVersion, parse, Version
|
||||
from sys import argv, exit
|
||||
|
||||
|
||||
derivation_pname = argv[1]
|
||||
derivation_version = argv[2]
|
||||
metadata_version = argv[3]
|
||||
|
||||
|
||||
try:
|
||||
parse(derivation_version)
|
||||
except InvalidVersion as e:
|
||||
print(e)
|
||||
print('Make sure you follow https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#versioning.')
|
||||
exit(1)
|
||||
|
||||
if Version(derivation_version) != Version(metadata_version):
|
||||
print(f"The '{derivation_pname}' derivation has version '{derivation_version}' but .dist-info/METADATA specifies version '{metadata_version}'.")
|
||||
print('This usually means that the wrong version is hardcoded in pyproject.toml or setup.{py,cfg}.')
|
||||
print("Use the pyprojectVersionPatchHook or patch the version manually so that the project metadata matches the derivation's version.")
|
||||
exit(1)
|
||||
@@ -21,15 +21,7 @@ pythonMetadataCheckPhase() {
|
||||
metadataVersion="$(PYTHONPATH="$pythonMetadataCheckOutput/@pythonSitePackages@:$PYTHONPATH" \
|
||||
@pythonInterpreter@ -P @retrieveMetadata@ "$derivationPname")"
|
||||
|
||||
# check that both versions can be parsed
|
||||
@pythonWithPackaging@ -c "from packaging.version import Version; from sys import argv; Version(argv[1]); Version(argv[2])" "$derivationVersion" "$metadataVersion"
|
||||
|
||||
if @pythonWithPackaging@ -c "from packaging.version import Version; from sys import argv, exit; exit(Version(argv[1]) == Version(argv[2]))" "$derivationVersion" "$metadataVersion"; then
|
||||
echo "The '$derivationPname' derivation has version '$derivationVersion' but .dist-info/METADATA specifies version '$metadataVersion'."
|
||||
echo "This usually means that the wrong version is hardcoded in pyproject.toml or setup.{py,cfg}."
|
||||
echo "Use the pyprojectVersionPatchHook or patch the version manually so that the project metadata matches the derivation's version."
|
||||
exit 1
|
||||
fi
|
||||
@pythonWithPackaging@ @compareMetadata@ "$derivationPname" "$derivationVersion" "$metadataVersion"
|
||||
}
|
||||
|
||||
if [ -z "${dontCheckPythonMetadata-}" ]; then
|
||||
|
||||
Reference in New Issue
Block a user