doc: reshape python-interpreter-table.nix into a normal callPackage

Before, it produced a string, not a derivation.
This commit is contained in:
Philip Taron 2024-07-26 11:21:15 -07:00
parent eac67316dc
commit 2266280af7
No known key found for this signature in database
2 changed files with 35 additions and 32 deletions

View File

@ -14,6 +14,8 @@ let
# NB: This file describes the Nixpkgs manual, which happens to use module docs infra originally developed for NixOS.
optionsDoc = callPackage ./doc-support/options-doc.nix { };
pythonInterpreterTable = pkgs.callPackage ./doc-support/python-interpreter-table.nix {};
in pkgs.stdenv.mkDerivation {
name = "nixpkgs-manual";
@ -39,12 +41,9 @@ in pkgs.stdenv.mkDerivation {
ln -s ${optionsDoc.optionsJSON}/share/doc/nixos/options.json ./config-options.json
'';
pythonInterpreterTable = pkgs.callPackage ./doc-support/python-interpreter-table.nix {};
passAsFile = [ "pythonInterpreterTable" ];
buildPhase = ''
substituteInPlace ./languages-frameworks/python.section.md --subst-var-by python-interpreter-table "$(<"$pythonInterpreterTablePath")"
substituteInPlace ./languages-frameworks/python.section.md \
--subst-var-by python-interpreter-table "$(<"${pythonInterpreterTable}")"
cat \
./functions/library.md.in \
@ -92,7 +91,9 @@ in pkgs.stdenv.mkDerivation {
echo "doc manual $dest nixpkgs-manual.epub" >> $out/nix-support/hydra-build-products
'';
passthru.tests.manpage-urls = with pkgs; testers.invalidateFetcherByDrvHash
passthru = {
inherit pythonInterpreterTable;
tests.manpage-urls = with pkgs; testers.invalidateFetcherByDrvHash
({ name ? "manual_check-manpage-urls"
, script
, urlsFile
@ -113,4 +114,5 @@ in pkgs.stdenv.mkDerivation {
script = ./tests/manpage-urls.py;
urlsFile = ./manpage-urls.json;
};
};
}

View File

@ -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}