Skip to content

Commit 80bf0d3

Browse files
committed
CDRIVER-4788 do not require sphinx-design for man pages (#1483)
* do not require sphinx-design sphinx-design is not used in the man pages. Do not require sphinx-design to enable building man pages when sphinx-design is not available. * error if building HTML docs without sphinx-design * remove `python3-sphinx` from mock install `python3-sphinx` is listed in BuildRequires of spec file and does not need to be installed separately. * update spec.patch to remove `python3-sphinx-design` Intended to test the RPM build without the `python3-sphinx-design` dependency installed. * commit staged files This is intended to test files changed in a patch build. Patch builds apply changes to index.
1 parent cceb24c commit 80bf0d3

File tree

3 files changed

+56
-17
lines changed

3 files changed

+56
-17
lines changed

.evergreen/etc/spec.patch

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,13 @@
1818
Release: 1%{?dist}
1919
# See THIRD_PARTY_NOTICES
2020
License: Apache-2.0 AND ISC AND MIT AND Zlib
21+
@@ -50,7 +50,8 @@ BuildRequires: perl-interpreter
22+
# From man pages
23+
BuildRequires: python3
24+
BuildRequires: python3-sphinx
25+
-BuildRequires: python3-sphinx-design
26+
+# python3-sphinx-design is intentionally removed to test that the build succeeds without python3-sphinx-design.
27+
+# At present, python3-sphinx-design is not available in EPEL. Refer: CDRIVER-4767
28+
29+
Requires: %{name}-libs%{?_isa} = %{version}-%{release}
30+
# Sub package removed

.evergreen/scripts/build_snapshot_rpm.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ build_dir=$(basename $(pwd))
7676
sudo mock -r ${config} --use-bootstrap-image --isolation=simple --clean
7777
sudo mock -r ${config} --use-bootstrap-image --isolation=simple --init
7878
mock_root=$(sudo mock -r ${config} --use-bootstrap-image --isolation=simple --print-root-path)
79-
sudo mock -r ${config} --use-bootstrap-image --isolation=simple --install rpmdevtools git rpm-build cmake python python3-sphinx gcc openssl-devel
79+
sudo mock -r ${config} --use-bootstrap-image --isolation=simple --install rpmdevtools git rpm-build cmake python gcc openssl-devel
8080
sudo mock -r ${config} --use-bootstrap-image --isolation=simple --copyin "$(pwd)" "$(pwd)/${spec_file}" /tmp
8181
sudo mock -r ${config} --use-bootstrap-image --isolation=simple --cwd "/tmp/${build_dir}" --chroot -- /bin/sh -c "(
8282
python build/calc_release_version.py | sed -E 's/([^-]+).*/\1/' > VERSION_CURRENT ;
@@ -110,6 +110,9 @@ tar_filename=$tar_filestem.tar
110110
tar_filepath="/tmp/$tar_filename"
111111
tgz_filepath="$HOME/rpmbuild/SOURCES/$expect_filename"
112112
echo "Creating source archive [$tgz_filepath]"
113+
# If Evergreen is running a patch build, changes have been git applied to the index.
114+
# Commit the changes to include them in the tarball.
115+
git commit -m "Include applied changes from a patch build" || true
113116
git archive --format=tar --output="$tar_filepath" --prefix="$tar_filestem/" HEAD
114117
mkdir -p "$tar_filestem"
115118
cp VERSION_CURRENT "$tar_filestem/."

src/libmongoc/doc/conf.py

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,21 @@
66
from pathlib import Path
77
from typing import Any
88

9-
from docutils.parsers.rst import directives
9+
from sphinx.builders.dirhtml import DirectoryHTMLBuilder
10+
from docutils.parsers.rst import directives, Directive
1011
from sphinx.application import Sphinx
1112
from sphinx.application import logger as sphinx_log
1213
from sphinx.config import Config
13-
from sphinx_design.dropdown import DropdownDirective
14+
15+
has_sphinx_design = False
16+
try:
17+
# Try to import sphinx-design to include directives for HTML pages (e.g. tabs and dropdowns).
18+
# sphinx-design is not required for building man pages.
19+
# python-sphinx-design is not currently available on EPEL. The package for EPEL includes man pages.
20+
from sphinx_design.dropdown import DropdownDirective
21+
has_sphinx_design = True
22+
except ImportError:
23+
print ("Unable to import sphinx_design. Documentation cannot be built as HTML.")
1424

1525
# Ensure we can import "mongoc" extension module.
1626
this_path = os.path.dirname(__file__)
@@ -29,10 +39,12 @@
2939
# package building.
3040
# "sphinxcontrib.moderncmakedomain",
3141
"cmakerefdomain",
32-
"sphinx_design",
3342
"sphinx.ext.mathjax",
3443
]
3544

45+
if has_sphinx_design:
46+
extensions.append("sphinx_design")
47+
3648
# General information about the project.
3749
project = "libmongoc"
3850
copyright = "2017-present, MongoDB, Inc"
@@ -176,22 +188,36 @@ def add_canonical_link(app: Sphinx, pagename: str, templatename: str, context: d
176188
context["metatags"] = context.get("metatags", "") + link
177189

178190

179-
class AdDropdown(DropdownDirective):
180-
"""A sphinx-design dropdown that can also be an admonition."""
181-
182-
option_spec = DropdownDirective.option_spec | {"admonition": directives.unchanged_required}
183-
184-
def run(self):
185-
adm = self.options.get("admonition")
186-
if adm is not None:
187-
self.options.setdefault("class-container", []).extend(("admonition", adm))
188-
self.options.setdefault("class-title", []).append(f"admonition-title")
189-
return super().run()
190-
191+
if has_sphinx_design:
192+
class AdDropdown(DropdownDirective):
193+
"""A sphinx-design dropdown that can also be an admonition."""
194+
195+
option_spec = DropdownDirective.option_spec | {"admonition": directives.unchanged_required}
196+
197+
def run(self):
198+
adm = self.options.get("admonition")
199+
if adm is not None:
200+
self.options.setdefault("class-container", []).extend(("admonition", adm))
201+
self.options.setdefault("class-title", []).append(f"admonition-title")
202+
return super().run()
203+
else:
204+
class EmptyDirective(Directive):
205+
has_content = True
206+
def run(self):
207+
return []
208+
209+
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.")
191212

192213
def setup(app: Sphinx):
193214
mongoc_common_setup(app)
194-
app.add_directive("ad-dropdown", AdDropdown)
215+
app.connect("builder-inited", check_html_builder_requirements)
216+
if has_sphinx_design:
217+
app.add_directive("ad-dropdown", AdDropdown)
218+
else:
219+
app.add_directive("ad-dropdown", EmptyDirective)
220+
app.add_directive("tab-set", EmptyDirective)
195221
app.connect("html-page-context", add_canonical_link)
196222
app.add_css_file("styles.css")
197223
app.connect("config-inited", _maybe_update_inventories)

0 commit comments

Comments
 (0)