Skip to content

Commit 3070b7c

Browse files
authored
Explain how to add an extension module (#1350)
* explain how to add modules * Update extension-modules.rst * Update extension-modules.rst * Update extension-modules.rst * Update extension-modules.rst * Update extension-modules.rst * Update extension-modules.rst * Update extension-modules.rst * Update extension-modules.rst * Update extension-modules.rst * Address Hugo's feedback * Update extension-modules.rst * Update extension-modules.rst * improvements - use distinct names for files to highlight differences in configurations - be more precise on the terminology of an extension module - explain how to build a required module (always built-in) vs an optional module (built-in or dynamic) - address Ezio's review * fixup! sphinx * fixup! indents * fixup! warnings * improve sections * fix markup * improve titles * improve presentation * fixup! markup * simplify snippets * improvements * improvements * some rewordings and cleanups * simplify wording * address Erlend's review * fix indents? * add ref to clinic everywhere when needed * fix typos * address encukou's review * improve the page flow * use sentence case (that's the reason why the previous title felt wrong to me!) * add podman tip * address rest of the review * address Alyssa's review * add details * address review - Add details on `Py_BUILD_CORE_*` macros - Add tips for `Py_LIMITED_API` * Make it easier to update the required ubuntu version * fixup! * fixup! * improve comment * use double quotes instead of single quotes * Address Carol's review.
1 parent 89254a9 commit 3070b7c

File tree

3 files changed

+703
-5
lines changed

3 files changed

+703
-5
lines changed

_extensions/ubuntu_version.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Sphinx extension to update the required Ubuntu version.
2+
3+
The required Ubuntu version should be specified in conf.py by::
4+
5+
configure_ubuntu_version = "MAJOR.MINOR" # e.g., "22.04"
6+
7+
The version must match the one used to regenerate the configure script in
8+
https://github.com/python/cpython/blob/main/Tools/build/regen-configure.sh.
9+
"""
10+
11+
from sphinx.errors import ExtensionError
12+
13+
14+
def replace_ubuntu_version(app, docname, source):
15+
"""Replace all occurrences of $CONFIGURE_UBUNTU_VERSION$.
16+
17+
This is needed since RST replacement via ``|...|`` is not supported
18+
in code-blocks directives.
19+
"""
20+
if (ubuntu_version := app.config.configure_ubuntu_version) is None:
21+
raise ExtensionError("configure_ubuntu_version is not set in conf.py")
22+
source[0] = source[0].replace("$CONFIGURE_UBUNTU_VERSION$", ubuntu_version)
23+
24+
25+
def setup(app):
26+
app.add_config_value("configure_ubuntu_version", None, "env", types=(str,))
27+
app.connect("source-read", replace_ubuntu_version)
28+
return {"parallel_read_safe": True, "parallel_write_safe": True}

conf.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import sys
12
import time
23

4+
sys.path.insert(0, '_extensions')
5+
36
extensions = [
7+
'ubuntu_version',
48
'notfound.extension',
59
'sphinx.ext.extlinks',
610
'sphinx.ext.intersphinx',
@@ -194,3 +198,7 @@
194198
copybutton_prompt_text = "$ "
195199
# https://sphinx-copybutton.readthedocs.io/en/latest/use.html#honor-line-continuation-characters-when-copying-multline-snippets
196200
copybutton_line_continuation_character = "\\"
201+
202+
# Must be synchronized with the Ubuntu image version in
203+
# https://github.com/python/cpython/blob/main/Tools/build/regen-configure.sh
204+
configure_ubuntu_version = "22.04"

0 commit comments

Comments
 (0)