Repository: pypa/pip
File: docs/html/conf.py (Python)

Code before:

# Add the docs/ directory to sys.path, because pip_sphinxext.py is there.
docs_dir = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, docs_dir)

# -- General configuration ------------------------------------------------------------
extensions = [
    # extensions common to 'man' and 'html' builds
    "pip_sphinxext",
]

# 'tags' is a special object handled by sphinx
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-tags
if "html" in tags or "READTHEDOCS" in os.environ:  # type: ignore[name-defined] # noqa: F821
    # html specific deps
    extensions.extend(
        (
            # first-party extensions
            "sphinx.ext.autodoc",
            "sphinx.ext.todo",
            "sphinx.ext.extlinks",
            "sphinx.ext.intersphinx",
            # third-party extensions
            "myst_parser",
            "sphinx_copybutton",
            "sphinx_inline_tabs",
            "sphinxcontrib.towncrier",
        ),
    )

# General information about the project.
project = "pip"
copyright = "The pip developers"

# 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(docs_dir, "..", "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__
            break
    else:  # AKA no-break
        version = release = "dev"


Review comment (suggestion):
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(...)
```

Code after:

# Add the docs/ directory to sys.path, because pip_sphinxext.py is there.
docs_dir = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, docs_dir)

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

extensions = [
    # extensions common to all builds
    "pip_sphinxext",
]

# '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(
        (
            # first-party extensions
            "sphinx.ext.autodoc",
            "sphinx.ext.todo",
            "sphinx.ext.intersphinx",
            # third-party extensions
            "myst_parser",
            "sphinx_copybutton",
            "sphinx_inline_tabs",
            "sphinxcontrib.towncrier",
            "sphinx_issues",
        ),
    )

# General information about the project.
project = "pip"
copyright = "The pip developers"

# 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(docs_dir, "..", "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__
            break
    else:  # AKA no-break
        version = release = "dev"