doc: autogenerate python interpreter table#313408
doc: autogenerate python interpreter table#313408fricklerhandwerk merged 18 commits intoNixOS:masterfrom
Conversation
This serves as a practical example on generating documentation by inspection of the evaluated nixpkgs tree.
| inherit (lib.lists) head length map tail; | ||
| inherit (lib.strings) splitString toInt; | ||
| inherit (lib.versions) splitVersion; |
There was a problem hiding this comment.
| inherit (lib.lists) head length map tail; | |
| inherit (lib.strings) splitString toInt; | |
| inherit (lib.versions) splitVersion; | |
| inherit (lib) head length tail splitString toInt splitVersion; |
There was a problem hiding this comment.
Doesn't that defy the whole purpose of namespacing lib?
There was a problem hiding this comment.
The namespacing is internal to lib, we shouldn't use it outside if there is no good reason.
There was a problem hiding this comment.
No the namespacing into sublibraries isn't internal (if it was, you couldn't access it from the outside!). Most functions are accessible from the top-level namespace though, so it's not a problem to mostly ignore the namespacing unless you need functions that aren't exposed from the top-level, or if you want to make the code a bit clearer.
This might change in the future with a lib namespace refactoring.
doc/doc-support/python-interpreter-table/collect-data/nix/filters.nix
Outdated
Show resolved
Hide resolved
doc/doc-support/python-interpreter-table/collect-data/nix/filters.nix
Outdated
Show resolved
Hide resolved
doc/doc-support/python-interpreter-table/collect-data/interpreters.nix
Outdated
Show resolved
Hide resolved
doc/doc-support/python-interpreter-table/collect-data/default.nix
Outdated
Show resolved
Hide resolved
doc/doc-support/python-interpreter-table/collect-data/interpreters.nix
Outdated
Show resolved
Hide resolved
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
@fricklerhandwerk @alejandrosame What do you two think of the following? Can be checked with I simplified the sorting by doing it when I get the list of interpreters. let
pkgs = import ./. {
config = { };
overlays = [ ];
};
lib = pkgs.lib;
inherit (lib.attrsets) attrNames filterAttrs;
inherit (lib.lists) naturalSort;
inherit (lib.strings) concatStringsSep;
isPythonInterpreter = name: (lib.strings.match "(pypy|python)([[:digit:]]*)" name) != null;
interpreters = naturalSort (
builtins.filter isPythonInterpreter (builtins.attrNames pkgs.pythonInterpreters)
);
getCuteName =
interpreter:
let
cuteName = {
cpython = "CPython";
pypy = "PyPy";
};
pythonInterpreter = pkgs.${interpreter};
in
"${cuteName.${pythonInterpreter.implementation}} ${pythonInterpreter.pythonVersion}";
getAliases =
interpreter:
builtins.attrNames (
filterAttrs (
name: value:
if isPythonInterpreter name then
value.outPath == pkgs.${interpreter}.outPath && name != interpreter
else
false
) pkgs
);
result = builtins.map (interpreter: {
inherit interpreter;
cuteName = getCuteName interpreter;
aliases = getAliases interpreter;
}) interpreters;
toMarkdown =
data:
concatStringsSep "" (
map (interpreter: ''
| ${interpreter.interpreter} | ${
concatStringsSep ", " interpreter.aliases or [ ]
} | ${interpreter.cuteName} |
'') data
);
in
''
| Package | Aliases | Interpeter |
|---------|---------|------------|
${toMarkdown result}
''I get this markdown output Rendered
|
|
@djacu yeah nice! |
|
@djacu Yeah, and checking for outPath also simplifies the code and makes the alias collection more generic |
|
@djacu wait, how did you get past the Python 2.7 EOL error? We have to evaluate derivations if we want to access |
Meh, so still there's the point that going through Is parsing the nixpkgs AST the only truly general solution to discover aliases? (To be clear, it would be out of scope of this PR, but in the end this is the underlying issue that surfaces when traversing |
|
|
|
|
Wow, this got a lot shorter |
| { pkgs ? (import ../.. { config = { }; overlays = []; }) }: | ||
| let | ||
| lib = pkgs.lib; |
There was a problem hiding this comment.
| { pkgs ? (import ../.. { config = { }; overlays = []; }) }: | |
| let | |
| lib = pkgs.lib; | |
| { pkgs ? (import ../.. { config = { }; overlays = []; }), lib ? pkgs.lib }: | |
| let |
| | python313 | | CPython 3.13 | | ||
| | pypy27 | pypy2, pypy | PyPy2.7 | | ||
| | pypy39 | pypy3 | PyPy 3.9 | | ||
| @python-interpreter-table@ |
There was a problem hiding this comment.
| @python-interpreter-table@ | |
| <!-- filled in by doc/doc-support/python-interpreter-table.nix --> | |
| @python-interpreter-table@ |
* doc: autogenerate python interpreter table This serves as a practical example on generating documentation by inspection of the evaluated Nixpkgs tree. Co-authored-by: Valentin Gagarin <[email protected]>
This serves as a practical example on generating documentation by inspection of the evaluated nixpkgs tree.