mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
Docs: Test presence of optional extensions with importlib (#130445)
This commit is contained in:
parent
d8ce092fe4
commit
3cc9e867eb
1 changed files with 14 additions and 15 deletions
29
Doc/conf.py
29
Doc/conf.py
|
@ -6,9 +6,10 @@
|
||||||
# The contents of this file are pickled, so don't put values in the namespace
|
# The contents of this file are pickled, so don't put values in the namespace
|
||||||
# that aren't pickleable (module imports are okay, they're removed automatically).
|
# that aren't pickleable (module imports are okay, they're removed automatically).
|
||||||
|
|
||||||
import importlib
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from importlib import import_module
|
||||||
|
from importlib.util import find_spec
|
||||||
|
|
||||||
# Make our custom extensions available to Sphinx
|
# Make our custom extensions available to Sphinx
|
||||||
sys.path.append(os.path.abspath('tools/extensions'))
|
sys.path.append(os.path.abspath('tools/extensions'))
|
||||||
|
@ -39,19 +40,17 @@ extensions = [
|
||||||
]
|
]
|
||||||
|
|
||||||
# Skip if downstream redistributors haven't installed them
|
# Skip if downstream redistributors haven't installed them
|
||||||
try:
|
_OPTIONAL_EXTENSIONS = (
|
||||||
import notfound.extension # noqa: F401
|
'notfound.extension',
|
||||||
except ImportError:
|
'sphinxext.opengraph',
|
||||||
pass
|
)
|
||||||
else:
|
for optional_ext in _OPTIONAL_EXTENSIONS:
|
||||||
extensions.append('notfound.extension')
|
try:
|
||||||
try:
|
if find_spec(optional_ext) is not None:
|
||||||
import sphinxext.opengraph # noqa: F401
|
extensions.append(optional_ext)
|
||||||
except ImportError:
|
except (ImportError, ValueError):
|
||||||
pass
|
pass
|
||||||
else:
|
del _OPTIONAL_EXTENSIONS
|
||||||
extensions.append('sphinxext.opengraph')
|
|
||||||
|
|
||||||
|
|
||||||
doctest_global_setup = '''
|
doctest_global_setup = '''
|
||||||
try:
|
try:
|
||||||
|
@ -74,7 +73,7 @@ copyright = "2001 Python Software Foundation"
|
||||||
# We look for the Include/patchlevel.h file in the current Python source tree
|
# We look for the Include/patchlevel.h file in the current Python source tree
|
||||||
# and replace the values accordingly.
|
# and replace the values accordingly.
|
||||||
# See Doc/tools/extensions/patchlevel.py
|
# See Doc/tools/extensions/patchlevel.py
|
||||||
version, release = importlib.import_module('patchlevel').get_version_info()
|
version, release = import_module('patchlevel').get_version_info()
|
||||||
|
|
||||||
rst_epilog = f"""
|
rst_epilog = f"""
|
||||||
.. |python_version_literal| replace:: ``Python {version}``
|
.. |python_version_literal| replace:: ``Python {version}``
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue