python3.pkgs.jinja2: build offline documentation

This commit is contained in:
Dmitry Bogatov 2023-04-01 13:39:50 -04:00 committed by Yt
parent e724676838
commit 7e4594a5d2
4 changed files with 44 additions and 2 deletions

View File

@ -52,7 +52,7 @@ let
doCheck = false; doCheck = false;
}); });
# Required by flask-1.1 # Required by flask-1.1
jinja2 = super.jinja2.overridePythonAttrs (old: rec { jinja2 = (super.jinja2.override { enableDocumentation = false; }).overridePythonAttrs (old: rec {
version = "2.11.3"; version = "2.11.3";
src = old.src.override { src = old.src.override {
inherit version; inherit version;

View File

@ -6,11 +6,17 @@
, babel , babel
, markupsafe , markupsafe
, pytestCheckHook , pytestCheckHook
, sphinxHook
, pallets-sphinx-themes
, sphinxcontrib-log-cabinet
, sphinx-issues
, enableDocumentation ? true
}: }:
buildPythonPackage rec { buildPythonPackage rec {
pname = "Jinja2"; pname = "Jinja2";
version = "3.1.2"; version = "3.1.2";
outputs = [ "out" ] ++ lib.optional enableDocumentation "doc";
disabled = pythonOlder "3.7"; disabled = pythonOlder "3.7";
@ -19,11 +25,20 @@ buildPythonPackage rec {
hash = "sha256-MTUacCpAip51laj8YVD8P0O7a/fjGXcMvA2535Q36FI="; hash = "sha256-MTUacCpAip51laj8YVD8P0O7a/fjGXcMvA2535Q36FI=";
}; };
patches = lib.optionals enableDocumentation [ ./patches/import-order.patch ];
propagatedBuildInputs = [ propagatedBuildInputs = [
babel babel
markupsafe markupsafe
]; ];
nativeBuildInputs = lib.optionals enableDocumentation [
sphinxHook
sphinxcontrib-log-cabinet
pallets-sphinx-themes
sphinx-issues
];
# Multiple tests run out of stack space on 32bit systems with python2. # Multiple tests run out of stack space on 32bit systems with python2.
# See https://github.com/pallets/jinja/issues/1158 # See https://github.com/pallets/jinja/issues/1158
doCheck = !stdenv.is32bit; doCheck = !stdenv.is32bit;

View File

@ -0,0 +1,27 @@
Sphinx changed something between sphinx=4.5.0 and sphinx=5.3 that broke
"sphinxcontrib.log_cabinet" plugin.
When Sphinx tries to importlib.import_module("sphinxcontrib.log_cabinet"), it
has couple other sphinxcontrib.* libraries in sys.path, and they seem to cause
conflict. So here I purge sys.path from sphixcontrib-related things, import
log_cabinet and put everything back, so when Sphinx will do "import_module",
"sphinxcontrib.log_cabinet" will be already imported and cached.
All this is quite hacky, but we are talking about merely building documentation
here. If resulting html looks good, what happened in Nix sandbox stays in Nix
sandbox.
--- a/docs/conf.py 1970-01-01 00:00:00.000000000 -0000
+++ b/docs/conf.py 1970-01-01 00:00:00.000000000 -0000
@@ -1,5 +1,12 @@
from pallets_sphinx_themes import get_version
from pallets_sphinx_themes import ProjectLink
+import importlib
+import sys
+
+saved_path = sys.path
+sys.path = [x for x in sys.path if "sphinxcontrib" not in x or "cabinet" in x]
+import sphinxcontrib.log_cabinet
+sys.path = saved_path
# Project --------------------------------------------------------------

View File

@ -64,7 +64,7 @@ buildPythonPackage rec {
alabaster alabaster
docutils docutils
imagesize imagesize
jinja2 (jinja2.override { enableDocumentation = false; })
packaging packaging
pygments pygments
requests requests