docs/packages/nixpkgs-manual/python-interp-table.nix

76 lines
1.7 KiB
Nix
Raw Normal View History

2024-06-30 22:10:42 +00:00
{
pkgs ? (
import ../.. {
config = { };
overlays = [ ];
}
),
}:
2024-06-30 05:43:43 +00:00
let
inherit (pkgs) lib;
2024-06-30 05:43:43 +00:00
inherit (lib.attrsets) attrNames filterAttrs;
2024-06-30 21:43:38 +00:00
inherit (lib.lists)
filter
map
naturalSort
reverseList
;
2024-06-30 05:43:43 +00:00
2024-06-30 21:43:38 +00:00
isPythonInterpreter =
name:
/*
NB: Package names that don't follow the regular expression:
2024-06-30 05:43:43 +00:00
- `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;
2024-06-30 21:43:38 +00:00
interpreterName =
pname:
2024-06-30 05:43:43 +00:00
let
cuteName = {
cpython = "CPython";
pypy = "PyPy";
};
interpreter = pkgs.${pname};
in
"${cuteName.${interpreter.implementation}} ${interpreter.pythonVersion}";
2024-06-30 21:43:38 +00:00
interpreters = reverseList (
naturalSort (filter isPythonInterpreter (attrNames pkgs.pythonInterpreters))
);
2024-06-30 05:43:43 +00:00
2024-06-30 21:43:38 +00:00
aliases =
pname:
2024-06-30 05:43:43 +00:00
attrNames (
2024-06-30 21:43:38 +00:00
filterAttrs (
name: _: isPythonInterpreter name && name != pname && interpreterName name == interpreterName pname
2024-06-30 05:43:43 +00:00
) pkgs
);
result = map (pname: {
inherit pname;
aliases = aliases pname;
interpreter = interpreterName pname;
}) interpreters;
2024-06-30 21:43:38 +00:00
toMarkdown =
data:
2024-06-30 05:43:43 +00:00
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}
''