Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tags in docs building to split up requirements #13168

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions docs/html/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,30 @@
sys.path.insert(0, docs_dir)

# -- General configuration ------------------------------------------------------------

extensions = [
# first-party extensions
"sphinx.ext.autodoc",
"sphinx.ext.todo",
"sphinx.ext.intersphinx",
# our extensions
# extensions common to all builds
"pip_sphinxext",
# third-party extensions
"myst_parser",
"sphinx_copybutton",
"sphinx_inline_tabs",
"sphinxcontrib.towncrier",
"sphinx_issues",
]

# 'tags' is a injected by sphinx
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-tags
if "man" not in tags: # type: ignore[name-defined] # noqa: F821
# extensions not needed for building man pages
extensions.extend(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It occurred to me that maybe if the extension loading was to be moved to the setup() entry point, the builder name would already be known by then and so this might not even have to use tags but would rely on the requested builders.

Another approach I used in the past, in a little different context, was scanning for the builder args in sys.argv: sphinx-contrib/spelling#55 (comment) / cherrypy/cheroot@63097fb#diff-85933aa74a2d66c3e4dcdf7a9ad8397f5a7971080d34ef1108296a7c6b69e7e3R12-R15.

(
# first-party extensions
"sphinx.ext.autodoc",
"sphinx.ext.todo",
"sphinx.ext.intersphinx",
# third-party extensions
"myst_parser",
"sphinx_copybutton",
"sphinx_inline_tabs",
Comment on lines +32 to +33

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two seem to be the only genuine 'HTML-only' extensions. Perhaps the condition might be better expressed as 'man' not in tags?

You could also look at the Python docs, where we use a pattern to check if an extension is importable, and if so add it to extensions. Eg

import importlib.util
if importlib.util.find_spec(...):
    extensions.append(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the condition might be better expressed as 'man' not in tags?

👍 this was also suggested above (#13168 (comment)) and I agree it makes this clearer (and simplifies the code!) so trying that: 033c31c

"sphinxcontrib.towncrier",
"sphinx_issues",
),
)

# General information about the project.
project = "pip"
copyright = "The pip developers"
Expand Down
3 changes: 3 additions & 0 deletions news/13168.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Added support for building only the man pages with minimal dependencies using
the sphinx-build ``--tag man`` option. This enables distributors to generate man
pages without requiring HTML documentation dependencies.
2 changes: 2 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ def get_sphinx_build_command(kind: str) -> List[str]:
return [
"sphinx-build",
"--keep-going",
"--tag",
kind,
ichard26 marked this conversation as resolved.
Show resolved Hide resolved
"-W",
"-c", "docs/html", # see note above
"-d", "docs/build/doctrees/" + kind,
Expand Down
Loading