Skip to content

Commit 3f2c35d

Browse files
committed
CDRIVER-4767 support Sphinx 1.7.6 (#1492)
* import older `DirectoryHTMLBuilder` if needed The import path of `DirectoryHTMLBuilder` was changed from `sphinx.builders.html` to `sphinx.builders.dirhtml` in Sphinx v2.0.0 * import `Directive`, not `SphinxDirective` `SphinxDirective` was added in Sphinx v2.0.0 * do not import Project `Project` was added in Sphinx v2.0.0 * update `needs_sphinx` to 1.7 * error if `add_css_file` is unavailable for HTML builder. But do not error otherwise. This is intended to help build man pages without HTML requirements. `Sphinx.add_css_file` was added in Sphinx v3.5.0 * use `builder-inited` `config-inited` was added in Sphinx v1.8.0 * do not use `external` role `external` role was added in intersphinx extension in v4.4 * do not use `noindexentry` `noindexentry` option was added to C domain in Sphinx v3.2 * remove `name` from `index` directive `name` option was added in Sphinx v3.0 * populate `man_pages` in `setup` instead of event handler The `config-inited` event was added in Sphinx v1.8.0 The `ManualPageBuilder` constructor raises an exception for an empty `man_pages` value. * remove parallel build of man pages To avoid an error observed on Sphinx 1.7.6: ``` AttributeError: Can't pickle local object 'BuildEnvironment._read_parallel.<locals>.merge' ``` * remove unhelpful warning An error is raised at runtime with a message suggesting to install `sphinx-design`. The warning was a source of confusion in CDRIVER-4767 * update NEWS for 1.25.3 * add upcoming NEWS for 1.25.4
1 parent 81abc75 commit 3f2c35d

File tree

8 files changed

+69
-36
lines changed

8 files changed

+69
-36
lines changed

NEWS

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
libmongoc 1.25.4 (Unreleased)
2+
=============================
3+
4+
Fixes:
5+
6+
* Restore support for Sphinx 1.7.6 for man page build.
7+
18
libmongoc 1.25.3
29
================
310

411
Fixes:
512

6-
* Fix data race in `mongoc_cursor_get_host`.
13+
* Disable shared libmongoc targets if `ENABLE_SHARED=OFF`
714
* Fix documentation build with Python 3.9.
815

916
Thanks to everyone who contributed to the development of this release.

build/cmake/SphinxBuild.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ function (sphinx_build_man target_name)
144144
"PYTHONDONTWRITEBYTECODE=1"
145145
${SPHINX_EXECUTABLE}
146146
-qW -b man
147-
-j "${NPROCS}"
148147
-c "${CMAKE_CURRENT_SOURCE_DIR}"
149148
-d "${doctrees_dir}"
150149
"${CMAKE_CURRENT_SOURCE_DIR}"

build/sphinx/mongoc_common.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010

1111
from sphinx.application import Sphinx
1212
from sphinx.application import logger as sphinx_log
13-
from sphinx.builders.dirhtml import DirectoryHTMLBuilder
13+
try:
14+
from sphinx.builders.dirhtml import DirectoryHTMLBuilder
15+
except ImportError:
16+
# Try importing from older Sphinx version path.
17+
from sphinx.builders.html import DirectoryHTMLBuilder
1418
from sphinx.config import Config
15-
from sphinx.project import Project
16-
from sphinx.util.docutils import SphinxDirective
19+
from docutils.parsers.rst import Directive
1720

18-
needs_sphinx = "5.0"
21+
needs_sphinx = "1.7" # Do not require newer sphinx. EPEL packages build man pages with Sphinx 1.7.6. Refer: CDRIVER-4767
1922
author = "MongoDB, Inc"
2023

2124
# -- Options for HTML output ----------------------------------------------
@@ -37,12 +40,9 @@ def _file_man_page_name(fpath: Path) -> str | None:
3740
continue
3841
return mat[1]
3942

40-
41-
def _collect_man(app: Sphinx, config: Config) -> None:
42-
"Populate the man_pages value from the given source directory input"
43+
def _collect_man (app: Sphinx):
4344
# Note: 'app' is partially-formed, as this is called from the Sphinx.__init__
4445
docdir = Path(app.srcdir)
45-
proj = Project(app.srcdir, config.source_suffix)
4646
# Find everything:
4747
children = docdir.rglob("*")
4848
# Find only regular files:
@@ -55,14 +55,17 @@ def _collect_man(app: Sphinx, config: Config) -> None:
5555
pairs: Iterable[tuple[Path, str]] = ((f, m) for f, m in with_man_name if m)
5656
# Populate the man_pages:
5757
for filepath, man_name in pairs:
58-
docname = proj.path2doc(str(filepath))
58+
# Generate the docname.
59+
relative_path = filepath.relative_to(app.srcdir)
60+
# The docname is relative to the source directory, and excludes the suffix.
61+
docname = str(relative_path.parent / filepath.stem)
62+
5963
assert docname, filepath
6064
man_pages.append((docname, man_name, "", [author], 3))
6165

62-
6366
# -- Options for manual page output ---------------------------------------
6467

65-
# NOTE: This starts empty, but we populate it during "config-inited" in _collect_man() (see above)
68+
# NOTE: This starts empty, but we populate it in `setup` in _collect_man() (see above)
6669
man_pages: list[tuple[str, str, str, list[str], int]] = []
6770

6871
# If true, show URL addresses after external links.
@@ -99,7 +102,7 @@ def add_ga_javascript(app: Sphinx, pagename: str, templatename: str, context: di
99102
)
100103

101104

102-
class VersionList(SphinxDirective):
105+
class VersionList(Directive):
103106
"""Custom directive to generate the version list from an environment variable"""
104107

105108
option_spec = {}
@@ -164,9 +167,8 @@ def generate_html_redirs(app: Sphinx, page: str, templatename: str, context: dic
164167
builder.css_files[:] = prev_css
165168
sphinx_log.debug("Wrote redirect: %r -> %r", path, page)
166169

167-
168170
def mongoc_common_setup(app: Sphinx):
169-
app.connect("config-inited", _collect_man)
171+
_collect_man(app)
170172
app.connect("html-page-context", generate_html_redirs)
171173
app.connect("html-page-context", add_ga_javascript)
172174
# Run sphinx-build -D analytics=1 to enable Google Analytics.

src/libbson/NEWS

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
libbson 1.25.4 (Unreleased)
2+
===========================
3+
4+
Fixes:
5+
6+
* Restore support for Sphinx 1.7.6 for man page build.
7+
8+
19
libbson 1.25.3
210
==============
311

src/libmongoc/doc/conf.py

+27-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
from pathlib import Path
77
from typing import Any
88

9-
from sphinx.builders.dirhtml import DirectoryHTMLBuilder
9+
try:
10+
from sphinx.builders.dirhtml import DirectoryHTMLBuilder
11+
except ImportError:
12+
# Try importing from older Sphinx version path.
13+
from sphinx.builders.html import DirectoryHTMLBuilder
14+
1015
from docutils.parsers.rst import directives, Directive
1116
from sphinx.application import Sphinx
1217
from sphinx.application import logger as sphinx_log
@@ -20,7 +25,7 @@
2025
from sphinx_design.dropdown import DropdownDirective
2126
has_sphinx_design = True
2227
except ImportError:
23-
print ("Unable to import sphinx_design. Documentation cannot be built as HTML.")
28+
pass
2429

2530
# Ensure we can import "mongoc" extension module.
2631
this_path = os.path.dirname(__file__)
@@ -77,7 +82,7 @@
7782
_UPDATE_KEY = "update_external_inventories"
7883

7984

80-
def _maybe_update_inventories(app: Sphinx, config: Config):
85+
def _maybe_update_inventories(app: Sphinx):
8186
"""
8287
We save Sphinx inventories for external projects saved within our own project
8388
so that we can support fully-offline builds. This is a convenience function
@@ -87,6 +92,7 @@ def _maybe_update_inventories(app: Sphinx, config: Config):
8792
value is defined.
8893
"""
8994
prefix = "[libmongoc/doc/conf.py]"
95+
config = app.config
9096
if not config[_UPDATE_KEY]:
9197
sphinx_log.info(
9298
"%s Using existing intersphinx inventories. Refresh by running with ‘-D %s=1’",
@@ -168,16 +174,16 @@ def _maybe_update_inventories(app: Sphinx, config: Config):
168174
Offer these substitutions for simpler variable references:
169175
170176
.. |cmvar:CMAKE_BUILD_TYPE| replace::
171-
:external+cmake:cmake:variable:`CMAKE_BUILD_TYPE <variable:CMAKE_BUILD_TYPE>`
177+
:cmake:variable:`CMAKE_BUILD_TYPE <variable:CMAKE_BUILD_TYPE>`
172178
173179
.. |cmvar:CMAKE_INSTALL_PREFIX| replace::
174-
:external+cmake:cmake:variable:`CMAKE_INSTALL_PREFIX <variable:CMAKE_INSTALL_PREFIX>`
180+
:cmake:variable:`CMAKE_INSTALL_PREFIX <variable:CMAKE_INSTALL_PREFIX>`
175181
176182
.. |cmvar:CMAKE_PREFIX_PATH| replace::
177-
:external+cmake:cmake:variable:`CMAKE_PREFIX_PATH <variable:CMAKE_PREFIX_PATH>`
183+
:cmake:variable:`CMAKE_PREFIX_PATH <variable:CMAKE_PREFIX_PATH>`
178184
179185
.. |cmcmd:find_package| replace::
180-
:external+cmake:cmake:command:`find_package() <command:find_package>`
186+
:cmake:command:`find_package() <command:find_package>`
181187
182188
"""
183189

@@ -206,9 +212,14 @@ class EmptyDirective(Directive):
206212
def run(self):
207213
return []
208214

215+
has_add_css_file = True
216+
209217
def check_html_builder_requirements (app):
210-
if isinstance(app.builder, DirectoryHTMLBuilder) and not has_sphinx_design:
211-
raise RuntimeError("The sphinx-design package is required to build HTML documentation but was not detected. Install sphinx-design.")
218+
if isinstance(app.builder, DirectoryHTMLBuilder):
219+
if not has_sphinx_design:
220+
raise RuntimeError("The sphinx-design package is required to build HTML documentation but was not detected. Install sphinx-design.")
221+
if not has_add_css_file:
222+
raise RuntimeError("A newer version of Sphinx is required to build HTML documentation with CSS files. Upgrade Sphinx to v3.5.0 or newer")
212223

213224
def setup(app: Sphinx):
214225
mongoc_common_setup(app)
@@ -219,6 +230,11 @@ def setup(app: Sphinx):
219230
app.add_directive("ad-dropdown", EmptyDirective)
220231
app.add_directive("tab-set", EmptyDirective)
221232
app.connect("html-page-context", add_canonical_link)
222-
app.add_css_file("styles.css")
223-
app.connect("config-inited", _maybe_update_inventories)
233+
if hasattr(app, "add_css_file"):
234+
app.add_css_file("styles.css")
235+
else:
236+
global has_add_css_file
237+
has_add_css_file = False
238+
239+
app.connect("builder-inited", _maybe_update_inventories)
224240
app.add_config_value(_UPDATE_KEY, default=False, rebuild=True, types=[bool])

src/libmongoc/doc/learn/get/docs.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ to be run when the `pyproject.toml` file is changed.
3636
Running Sphinx
3737
**************
3838

39-
Poetry can be used to execute the :external:doc:`man/sphinx-build` command::
39+
Poetry can be used to execute the :std:doc:`man/sphinx-build` command::
4040

4141
$ poetry run sphinx-build -b dirhtml "./src/libmongoc/doc" "./_build/docs/html"
4242

@@ -47,16 +47,16 @@ subdirectory.
4747

4848
Because Sphinx builds many pages, the build may run quite slowly. For faster
4949
builds, it is recommended to use the
50-
:external:option:`--jobs <sphinx-build.--jobs>` command-line option when
51-
invoking :external:doc:`man/sphinx-build`.
50+
:std:option:`--jobs <sphinx:sphinx-build.--jobs>` command-line option when
51+
invoking :std:doc:`sphinx:man/sphinx-build`.
5252

5353

5454
Viewing the Documentation
5555
*************************
5656

5757
To quickly view the rendered HTML pages, a simple local HTTP server can be
5858
spawned on the command line by using Python's built-in
59-
:external:mod:`http.server` module:
59+
:py:mod:`http.server` module:
6060

6161
.. code-block:: sh
6262

src/libmongoc/doc/learn/get/installing.rst

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Installing Prebuilt MongoDB C Driver Libraries
1111
.. _Homebrew: https://brew.sh/
1212

1313
The |libmongoc| and |libbson| libraries are often available in the package
14-
management repositories of `common Linux distributions <installing.linux_>`_ and
15-
`macOS via Homebrew <installing.macos_>`_.
14+
management repositories of :ref:`common Linux distributions <installing.linux>` and
15+
:ref:`macOS via Homebrew <installing.macos>`.
1616

1717
.. note::
1818

@@ -42,7 +42,8 @@ management repositories of `common Linux distributions <installing.linux_>`_ and
4242
package managers; Conan
4343
package managers; vcpkg
4444
pair: installation; package managers
45-
:name: installing.pkgman
45+
46+
.. _installing.pkgman:
4647

4748
Cross Platform Installs Using Library Package Managers
4849
******************************************************
@@ -135,7 +136,8 @@ CMake toolchain file at the initial configure command::
135136

136137
.. index::
137138
! pair: Linux; installation
138-
:name: installing.linux
139+
140+
.. _installing.linux:
139141

140142
Installing in Linux
141143
*******************

src/libmongoc/doc/mongoc_client_encryption_opts_set_kms_credential_provider_callback.rst

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ Parameters
3434
.. rubric:: Related:
3535

3636
.. c:type:: mongoc_kms_credentials_provider_callback_fn
37-
:noindexentry:
3837
3938
.. -
4039
The :noindexentry: prevents a one-off index entry for this item.

0 commit comments

Comments
 (0)