1# To build this derivation, run `nix-build -A nixpkgs-manual.pythonInterpreterTable`
2{
3 lib,
4 writeText,
5 pkgs,
6 pythonInterpreters,
7}:
8let
9 isPythonInterpreter =
10 name:
11 /*
12 NB: Package names that don't follow the regular expression:
13 - `python-cosmopolitan` is not part of `pkgs.pythonInterpreters`.
14 - `_prebuilt` interpreters are used for bootstrapping internally.
15 - `python3Minimal` contains python packages, left behind conservatively.
16 - `rustpython` lacks `pythonVersion` and `implementation`.
17 */
18 (lib.strings.match "(pypy|python)([[:digit:]]*)" name) != null;
19
20 interpreterName =
21 pname:
22 let
23 cuteName = {
24 cpython = "CPython";
25 pypy = "PyPy";
26 };
27 interpreter = pkgs.${pname};
28 in
29 "${cuteName.${interpreter.implementation}} ${interpreter.pythonVersion}";
30
31 interpreters = lib.reverseList (
32 lib.naturalSort (lib.filter isPythonInterpreter (lib.attrNames pythonInterpreters))
33 );
34
35 aliases =
36 pname:
37 lib.attrNames (
38 lib.filterAttrs (
39 name: value:
40 # use tryEval to handle entries in aliases.nix
41 (builtins.tryEval (
42 isPythonInterpreter name && name != pname && interpreterName name == interpreterName pname
43 )).value
44 ) pkgs
45 );
46
47 result = map (pname: {
48 inherit pname;
49 aliases = aliases pname;
50 interpreter = interpreterName pname;
51 }) interpreters;
52
53 toMarkdown =
54 data:
55 let
56 line = package: ''
57 | ${package.pname} | ${lib.concatStringsSep ", " package.aliases or [ ]} | ${package.interpreter} |
58 '';
59 in
60 lib.concatStringsSep "" (map line data);
61
62in
63writeText "python-interpreter-table.md" ''
64 | Package | Aliases | Interpeter |
65 |---------|---------|------------|
66 ${toMarkdown result}
67''