mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Support jinja2-3.0
Since jinja2-3.0, some utility functions like contextfunction and environmentfilter are renamed to new name. This follows the updates to support jinja2-3.0 or above.
This commit is contained in:
parent
f31af4b815
commit
85f58874ec
2
CHANGES
2
CHANGES
@ -4,6 +4,8 @@ Release 4.1.0 (in development)
|
||||
Dependencies
|
||||
------------
|
||||
|
||||
* Support jinja2-3.0
|
||||
|
||||
Incompatible changes
|
||||
--------------------
|
||||
|
||||
|
3
setup.py
3
setup.py
@ -21,8 +21,7 @@ install_requires = [
|
||||
'sphinxcontrib-htmlhelp',
|
||||
'sphinxcontrib-serializinghtml',
|
||||
'sphinxcontrib-qthelp',
|
||||
'Jinja2>=2.3,<3.0',
|
||||
'MarkupSafe<2.0',
|
||||
'Jinja2>=2.3',
|
||||
'Pygments>=2.0',
|
||||
'docutils>=0.14,<0.18',
|
||||
'snowballstemmer>=1.1',
|
||||
|
@ -12,7 +12,7 @@ from os import path
|
||||
from pprint import pformat
|
||||
from typing import TYPE_CHECKING, Any, Callable, Dict, Iterator, List, Tuple, Union
|
||||
|
||||
from jinja2 import BaseLoader, FileSystemLoader, TemplateNotFound, contextfunction
|
||||
from jinja2 import BaseLoader, FileSystemLoader, TemplateNotFound
|
||||
from jinja2.environment import Environment
|
||||
from jinja2.sandbox import SandboxedEnvironment
|
||||
from jinja2.utils import open_if_exists
|
||||
@ -22,6 +22,11 @@ from sphinx.theming import Theme
|
||||
from sphinx.util import logging
|
||||
from sphinx.util.osutil import mtimes_of_files
|
||||
|
||||
try:
|
||||
from jinja2.utils import pass_context # type: ignore # jinja2-3.0 or above
|
||||
except ImportError:
|
||||
from jinja2 import contextfunction as pass_context
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from sphinx.builders import Builder
|
||||
|
||||
@ -101,7 +106,7 @@ class idgen:
|
||||
next = __next__ # Python 2/Jinja compatibility
|
||||
|
||||
|
||||
@contextfunction
|
||||
@pass_context
|
||||
def warning(context: Dict, message: str, *args: Any, **kwargs: Any) -> str:
|
||||
if 'pagename' in context:
|
||||
filename = context.get('pagename') + context.get('file_suffix', '')
|
||||
@ -180,9 +185,9 @@ class BuiltinTemplateLoader(TemplateBridge, BaseLoader):
|
||||
self.environment.filters['toint'] = _toint
|
||||
self.environment.filters['todim'] = _todim
|
||||
self.environment.filters['slice_index'] = _slice_index
|
||||
self.environment.globals['debug'] = contextfunction(pformat)
|
||||
self.environment.globals['debug'] = pass_context(pformat)
|
||||
self.environment.globals['warning'] = warning
|
||||
self.environment.globals['accesskey'] = contextfunction(accesskey)
|
||||
self.environment.globals['accesskey'] = pass_context(accesskey)
|
||||
self.environment.globals['idgen'] = idgen
|
||||
if use_i18n:
|
||||
self.environment.install_gettext_translations(builder.app.translator)
|
||||
|
@ -18,11 +18,17 @@ from docutils.parsers.rst import roles
|
||||
from docutils.parsers.rst.languages import en as english
|
||||
from docutils.statemachine import StringList
|
||||
from docutils.utils import Reporter
|
||||
from jinja2 import Environment, environmentfilter
|
||||
from jinja2 import Environment
|
||||
|
||||
from sphinx.locale import __
|
||||
from sphinx.util import docutils, logging
|
||||
|
||||
try:
|
||||
from jinja2.utils import pass_environment # type: ignore # jinja2-3.0 or above
|
||||
except ImportError:
|
||||
from jinja2 import environmentfilter as pass_environment
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
docinfo_re = re.compile(':\\w+:.*?')
|
||||
@ -51,7 +57,7 @@ def textwidth(text: str, widechars: str = 'WF') -> int:
|
||||
return sum(charwidth(c, widechars) for c in text)
|
||||
|
||||
|
||||
@environmentfilter
|
||||
@pass_environment
|
||||
def heading(env: Environment, text: str, level: int = 1) -> str:
|
||||
"""Create a heading for *level*."""
|
||||
assert level <= 3
|
||||
|
Loading…
Reference in New Issue
Block a user