-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add separate
conf.py
for the different docs types
The goal here is to allow building the `man` pages without all the additional requirements needed for the `html` docs, so that e.g. developers packaging `pip` can also package the man pages with minimal dependencies. Specifically, this should have no impact on the build output of `nox -s docs`, but does allow: sphinx-build \ -c docs/man \ -d docs/build/doctrees/man \ -b man \ docs/man \ docs/build/man to run with only `sphinx` dependency (in addition to `pip`s dependencies). While doing this I also used long-opts to `sphinx-build` in the `noxfile` since I found this more understandable at a glance An `__init__.py` was added under `docs/man` to satisfy `mypy`. If this wasn't added it would error: docs/man/conf.py: error: Duplicate module named "conf" (also at "docs/html/conf.py") docs/man/conf.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info docs/man/conf.py: note: Common resolutions include: a) using `--exclude` to avoid checking one of them, b) adding `__init__.py` somewhere, c) using `--explicit-package-bases` or adjusting MYPYPATH Found 1 error in 1 file (errors prevented further checking) Adding an extra `__init__.py` under `docs/html` would result in a separate error since then the `html` module is local (and not the stdlib one) resulting in a error from `sphinx-build`: Extension error: Could not import extension sphinx.builders.linkcheck (exception: No module named 'html.parser') Issue: #12881 Avoid mypy ignore for docs by just adding one `__init__.py`
- Loading branch information
1 parent
e98cc5c
commit e599386
Showing
10 changed files
with
112 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ sphinx: | |
python: | ||
install: | ||
- requirements: docs/requirements.txt | ||
- requirements: docs/html/requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
import re | ||
from typing import Tuple | ||
|
||
|
||
def read_version() -> Tuple[str, str]: | ||
# Find the version and release information. | ||
# We have a single source of truth for our version number: pip's __init__.py file. | ||
# This next bit of code reads from it. | ||
file_with_version = os.path.join( | ||
os.path.dirname(__file__), "..", "src", "pip", "__init__.py" | ||
) | ||
with open(file_with_version) as f: | ||
for line in f: | ||
m = re.match(r'__version__ = "(.*)"', line) | ||
if m: | ||
__version__ = m.group(1) | ||
# The short X.Y version. | ||
version = ".".join(__version__.split(".")[:2]) | ||
# The full version, including alpha/beta/rc tags. | ||
release = __version__ | ||
return version, release | ||
return "dev", "dev" | ||
|
||
|
||
# General information about the project. | ||
project = "pip" | ||
copyright = "The pip developers" | ||
version, release = read_version() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# currently incompatible with sphinxcontrib-towncrier | ||
# https://github.com/sphinx-contrib/sphinxcontrib-towncrier/issues/92 | ||
towncrier < 24 | ||
furo | ||
myst_parser | ||
sphinx-copybutton | ||
sphinx-inline-tabs | ||
sphinxcontrib-towncrier >= 0.2.0a0 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import glob | ||
import os | ||
import sys | ||
from typing import List, Tuple | ||
|
||
# Add the docs/ directory to sys.path to load the common config | ||
docs_dir = os.path.dirname(os.path.dirname(__file__)) | ||
sys.path.insert(0, docs_dir) | ||
|
||
from common_conf import copyright, project, release, version # noqa: E402, F401 | ||
|
||
extensions = [ | ||
# our extensions | ||
"pip_sphinxext", | ||
] | ||
|
||
print("pip version:", version) | ||
print("pip release:", release) | ||
|
||
|
||
# List of manual pages generated | ||
def determine_man_pages() -> List[Tuple[str, str, str, str, int]]: | ||
"""Determine which man pages need to be generated.""" | ||
|
||
def to_document_name(path: str, base_dir: str) -> str: | ||
"""Convert a provided path to a Sphinx "document name".""" | ||
relative_path = os.path.relpath(path, base_dir) | ||
root, _ = os.path.splitext(relative_path) | ||
return root.replace(os.sep, "/") | ||
|
||
# Crawl the entire man/commands/ directory and list every file with appropriate | ||
# name and details. | ||
man_dir = os.path.join(docs_dir, "man") | ||
raw_subcommands = glob.glob(os.path.join(man_dir, "commands/*.rst")) | ||
if not raw_subcommands: | ||
raise FileNotFoundError( | ||
"The individual subcommand manpages could not be found!" | ||
) | ||
|
||
retval = [ | ||
("index", "pip", "package manager for Python packages", "pip developers", 1), | ||
] | ||
for fname in raw_subcommands: | ||
fname_base = to_document_name(fname, man_dir) | ||
outname = "pip-" + fname_base.split("/")[1] | ||
description = "description of {} command".format(outname.replace("-", " ")) | ||
|
||
retval.append((fname_base, outname, description, "pip developers", 1)) | ||
|
||
return retval | ||
|
||
|
||
man_pages = determine_man_pages() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters