doc: reshape python-interpreter-table.nix into a normal callPackage
Before, it produced a string, not a derivation.
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
# For debugging, run in this directory:
|
||||
# nix eval --impure --raw --expr 'import ./python-interpreter-table.nix {}'
|
||||
{ pkgs ? (import ../.. { config = { }; overlays = []; }) }:
|
||||
# To run this derivation, `nix-build -A nixpkgs-manual.pythonInterpreterTable`
|
||||
{
|
||||
lib,
|
||||
writeText,
|
||||
pkgs,
|
||||
pythonInterpreters,
|
||||
}:
|
||||
let
|
||||
lib = pkgs.lib;
|
||||
inherit (lib.attrsets) attrNames filterAttrs;
|
||||
inherit (lib.lists) elem filter map naturalSort reverseList;
|
||||
inherit (lib.strings) concatStringsSep;
|
||||
|
||||
isPythonInterpreter = name:
|
||||
/* NB: Package names that don't follow the regular expression:
|
||||
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.
|
||||
@@ -16,7 +17,8 @@ let
|
||||
*/
|
||||
(lib.strings.match "(pypy|python)([[:digit:]]*)" name) != null;
|
||||
|
||||
interpreterName = pname:
|
||||
interpreterName =
|
||||
pname:
|
||||
let
|
||||
cuteName = {
|
||||
cpython = "CPython";
|
||||
@@ -26,16 +28,16 @@ let
|
||||
in
|
||||
"${cuteName.${interpreter.implementation}} ${interpreter.pythonVersion}";
|
||||
|
||||
interpreters = reverseList (naturalSort (
|
||||
filter isPythonInterpreter (attrNames pkgs.pythonInterpreters)
|
||||
));
|
||||
interpreters = lib.reverseList (
|
||||
lib.naturalSort (lib.filter isPythonInterpreter (lib.attrNames pythonInterpreters))
|
||||
);
|
||||
|
||||
aliases = pname:
|
||||
attrNames (
|
||||
filterAttrs (name: value:
|
||||
isPythonInterpreter name
|
||||
&& name != pname
|
||||
&& interpreterName name == interpreterName pname
|
||||
aliases =
|
||||
pname:
|
||||
lib.attrNames (
|
||||
lib.filterAttrs (
|
||||
name: value:
|
||||
isPythonInterpreter name && name != pname && interpreterName name == interpreterName pname
|
||||
) pkgs
|
||||
);
|
||||
|
||||
@@ -45,18 +47,17 @@ let
|
||||
interpreter = interpreterName pname;
|
||||
}) interpreters;
|
||||
|
||||
toMarkdown = data:
|
||||
toMarkdown =
|
||||
data:
|
||||
let
|
||||
line = package: ''
|
||||
| ${package.pname} | ${join ", " package.aliases or [ ]} | ${package.interpreter} |
|
||||
| ${package.pname} | ${lib.concatStringsSep ", " package.aliases or [ ]} | ${package.interpreter} |
|
||||
'';
|
||||
in
|
||||
join "" (map line data);
|
||||
|
||||
join = lib.strings.concatStringsSep;
|
||||
lib.concatStringsSep "" (map line data);
|
||||
|
||||
in
|
||||
''
|
||||
writeText "python-interpreter-table.md" ''
|
||||
| Package | Aliases | Interpeter |
|
||||
|---------|---------|------------|
|
||||
${toMarkdown result}
|
||||
|
||||
Reference in New Issue
Block a user