sphinx-jinja2-compat
sphinx-jinja2-compat, current version 0.4.1, is a utility library designed to patch Jinja2 v3, restoring compatibility with earlier Sphinx versions. It also addresses issues to ensure some Sphinx versions function correctly on Python 3.10. This library primarily serves as a compatibility layer to bridge gaps between major versions of its dependencies, rather than providing new user-facing features. Releases are made on an as-needed basis to address specific compatibility challenges.
Warnings
- gotcha This library operates as a low-level patch and does not expose direct user-facing Python imports or functions for common usage. Its effect is passive, modifying the behavior of Jinja2 within Sphinx.
- breaking If your Sphinx project or custom extensions rely on specific Jinja2 v3 behaviors that `sphinx-jinja2-compat` alters to restore compatibility, unintended side effects might occur. This is more likely for highly customized Sphinx setups.
- gotcha The patches applied by `sphinx-jinja2-compat` can be disabled at runtime by setting the environment variable `NO_SPHINX_JINJA2_COMPAT` to `1` before running Sphinx. This might be useful for debugging or when the compatibility layer is not desired.
Install
-
pip install sphinx-jinja2-compat
Quickstart
# Simply install the package. No direct code import or configuration in conf.py is typically needed.
# The patch is applied automatically upon import of related modules within Sphinx.
# To disable the patches, set the environment variable before running Sphinx:
import os
os.environ['NO_SPHINX_JINJA2_COMPAT'] = '1'
# Then run Sphinx as usual, e.g., via command line:
# sphinx-build -b html source build
print("sphinx-jinja2-compat is active once installed, patching Jinja2 for Sphinx compatibility.")