When I install sphinx locally it populates two ent...
# general
p
When I install sphinx locally it populates two entrypoints
sphinx-build
and
sphinx-apidoc
is there a way I can target the apidoc entrypoint(?) with a pants
run_shell_command
? I got sphinx-build to work with
Copy code
run_shell_command(
    name="sphinx",
    command="python {chroot}/sphinx.pex --help",
    runnable_dependencies=["//.build/requirements:reqs-dev#sphinx"],
)
1
In good'ol bazel land I can do this with
py_console_script_binary
from rules_python.
Ah. looks like scripts on the pex binary accepts console_scripts
Copy code
pex_binary(
  name="sphinx-apidoc",
  script="sphinx-apidoc",
  dependencies=["//.build/requirements:reqs-dev#sphinx"],
)
👍 1
b
@purple-plastic-57801 so you're able to build sphinx API docs in your builds? I wanna do this too...
p
Yeah.. kind of odd but this works for me
Copy code
python_sources(name="conf")

files(name="index", sources=["index.md"])

"""
Unfortunately, we _cannot_ glob over dependencies, as such we need to explicitly define the dependencies which are required to
build documentation. As such, if you add a new package it will not be included in the documentation unless you add it to the
list below.
"""
DOC_DEPS = [
    ":conf",
    ":index",
    ... all dependencies required for docs
]

SPHINX_DEPS = [
    ".build/requirements:reqs-dev#myst-parser",
    "//.build/requirements:reqs-dev#sphinx",
]

pex_binary(
    name="sphinx-apidoc",
    script="sphinx-apidoc",
    dependencies=SPHINX_DEPS,
)

adhoc_tool(
    name="build-apidoc",
    runnable=":sphinx-apidoc",
    args=[
        "--force",
        "--module-first",
        "--output-dir",
        # NOTE(G3): In later steps, when the output is unfurled.. this places the documentation in the worktree
        # appropriately from the root of the workspace
        "path/docs/source",
        # NOTE(G3): Relative to this BUILD file
        "./../path",
    ],
    execution_dependencies = DOC_DEPS,
    output_directories=["path/docs"],
    root_output_directory="./",
    log_output=True,
)

pex_binary(
    name="sphinx-build",
    script="sphinx-build",
    dependencies=SPHINX_DEPS + DOC_DEPS,
)

adhoc_tool(
    name="build-html",
    runnable=":sphinx-build",
    args=["-M", "html", ".", "_build"],
    execution_dependencies=[":build-apidoc"] + DOC_DEPS,
    output_directories=["_build/html"],
    root_output_directory="./_build/html",
    log_output=True,
)

archive(name="docs", files=[":build-apidoc"], format="zip")
@breezy-mouse-20493
💯 1
Your milage may vary.. I made heavy use of
--keep-sandboxes=always
to figure out the path stuff
b
Yup, understood!