Commit 3e6a5988 authored by adisbladis's avatar adisbladis
Browse files

pythonInterpreters: Add passthru.pythonABITags

As documented in https://packaging.python.org/en/latest/specifications/platform-compatibility-tags/#abi-tag.

This is useful to check whether a wheel is compatible with a certain interpreter. [Pyproject.nix](https://github.com/pyproject-nix/pyproject.nix) has [functions to perform wheel compatibility checking](https://pyproject-nix.github.io/pyproject.nix/lib/pypa.html#function-library-lib.pypa.isWheelFileCompatible) against a Python interpreter, and has computed interpreter ABI tags itself.
The recent addition of free threading (`python313FreeThreading`) complicates this by not being introspectable:
A GIL Python (non free-threaded) has an ABI tag `cp313` while the free-threaded Python has `cp313t`, but the package doesn't communicate whether `enableGIL` is true or false, leaving no way to compute the tag.
The same goes for if debugging support was added to the derivation: A `d` suffix would need to be added.

Additionally ABI tags has no defined format and can really only be accurately computed by having insight into how the ABI tags are used by a specific interpreter, meaning that the only correct place to compute ABI tags is within the context of a particular Python derivation.

While this has no immediate use within nixpkgs it could be used as a basis to provide compatibility assertions regarding wheel compat at eval time.
parent 245e930d
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -87,6 +87,10 @@ let
      pythonOnBuildForTarget = pkgsBuildTarget.${pythonAttr};
      pythonOnHostForHost = pkgsHostHost.${pythonAttr};
      pythonOnTargetForTarget = pkgsTargetTarget.${pythonAttr} or { };
      pythonABITags = [
        "none"
        "cp${sourceVersion.major}${sourceVersion.minor}"
      ];
    }
    // {
      inherit ucsEncoding;
+6 −0
Original line number Diff line number Diff line
@@ -195,6 +195,12 @@ let
        pythonOnHostForHost
        pythonOnTargetForTarget
        ;

      pythonABITags = [
        "abi3"
        "none"
        "cp${sourceVersion.major}${sourceVersion.minor}${lib.optionalString (!enableGIL) "t"}"
      ];
    };

  version = with sourceVersion; "${major}.${minor}.${patch}${suffix}";
+2 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
  pythonOnHostForHost,
  pythonOnTargetForTarget,
  pythonAttr ? null,
  pythonABITags ? [ "none" ],
  self, # is pythonOnHostForTarget
}:
let
@@ -141,6 +142,7 @@ rec {
  pythonOlder = lib.versionOlder pythonVersion;
  inherit hasDistutilsCxxPatch;
  inherit pythonOnBuildForHost;
  inherit pythonABITags;

  tests = callPackage ./tests.nix {
    python = self;
+5 −0
Original line number Diff line number Diff line
@@ -67,6 +67,11 @@ let
    pythonOnBuildForTarget = pkgsBuildTarget.${pythonAttr};
    pythonOnHostForHost = pkgsHostHost.${pythonAttr};
    pythonOnTargetForTarget = pkgsTargetTarget.${pythonAttr} or { };

    pythonABITags = [
      "none"
      "pypy${lib.concatStrings (lib.take 2 (lib.splitString "." pythonVersion))}_pp${sourceVersion.major}${sourceVersion.minor}"
    ];
  };
  pname = passthru.executable;
  version = with sourceVersion; "${major}.${minor}.${patch}";
+5 −0
Original line number Diff line number Diff line
@@ -48,6 +48,11 @@ let
    pythonOnBuildForTarget = throw "${pname} does not support cross compilation";
    pythonOnHostForHost = throw "${pname} does not support cross compilation";
    pythonOnTargetForTarget = throw "${pname} does not support cross compilation";

    pythonABITags = [
      "none"
      "pypy${lib.concatStrings (lib.take 2 (lib.splitString "." pythonVersion))}_pp${sourceVersion.major}${sourceVersion.minor}"
    ];
  };
  pname = "${passthru.executable}_prebuilt";
  version = with sourceVersion; "${major}.${minor}.${patch}";
Loading