docs/packages/nixpkgs-manual/python-interp-table.nix
dfh d2fed9c4d0 This is dfh@ playing with jj
These are some more descriptions.
2024-09-04 21:44:07 +00:00

76 lines
1.7 KiB
Nix

{
pkgs ? (
import ../.. {
config = { };
overlays = [ ];
}
),
}:
let
inherit (pkgs) lib;
inherit (lib.attrsets) attrNames filterAttrs;
inherit (lib.lists)
filter
map
naturalSort
reverseList
;
isPythonInterpreter =
name:
/*
NB: Package names that don't follow the regular expression:
- `python-cosmopolitan` is not part of `pkgs.pythonInterpreters`.
- `_prebuilt` interpreters are used for bootstrapping internally.
- `python3Minimal` contains python packages, left behind conservatively.
- `rustpython` lacks `pythonVersion` and `implementation`.
*/
(lib.strings.match "(pypy|python)([[:digit:]]*)" name) != null;
interpreterName =
pname:
let
cuteName = {
cpython = "CPython";
pypy = "PyPy";
};
interpreter = pkgs.${pname};
in
"${cuteName.${interpreter.implementation}} ${interpreter.pythonVersion}";
interpreters = reverseList (
naturalSort (filter isPythonInterpreter (attrNames pkgs.pythonInterpreters))
);
aliases =
pname:
attrNames (
filterAttrs (
name: _: isPythonInterpreter name && name != pname && interpreterName name == interpreterName pname
) pkgs
);
result = map (pname: {
inherit pname;
aliases = aliases pname;
interpreter = interpreterName pname;
}) interpreters;
toMarkdown =
data:
let
line = package: ''
| ${package.pname} | ${join ", " package.aliases or [ ]} | ${package.interpreter} |
'';
in
join "" (map line data);
join = lib.strings.concatStringsSep;
in
''
| Package | Aliases | Interpeter |
|---------|---------|------------|
${toMarkdown result}
''