# -*- python -*-

package(default_visibility = ["//visibility:private"])

load(
    "@drake//tools/skylark:drake_py.bzl",
    "drake_py_binary",
    "drake_py_library",
)
load(
    "//doc:defs.bzl",
    "DEFAULT_BINARY_TAGS",
    "DEFAULT_TEST_TAGS",
)
load("//bindings/pydrake:pydrake.bzl", "add_lint_tests_pydrake")

drake_py_library(
    name = "sphinx_base",
    srcs = ["sphinx_base.py"],
    tags = DEFAULT_BINARY_TAGS,
    deps = ["@rules_python//python/runfiles"],
)

# TODO(eric.cousineau): Add a smaller stub library stub to test this extension.
drake_py_library(
    name = "pydrake_sphinx_extension_py",
    srcs = ["pydrake_sphinx_extension.py"],
    deps = [
        ":sphinx_base",
        "//bindings/pydrake/common:cpp_template_py",
        "//bindings/pydrake/common:deprecation_py",
        "//doc/doxygen_cxx:system_doxygen",
    ],
)

drake_py_binary(
    name = "gen_sphinx",
    srcs = [
        "gen_sphinx.py",
    ],
    add_test_rule = 1,
    data = [
        "_static/css/custom.css",
        "conf.py",
    ],
    imports = ["."],
    main = "gen_sphinx.py",
    tags = DEFAULT_BINARY_TAGS,
    test_rule_args = ["--out_dir=<test>"],
    test_rule_size = "medium",
    test_rule_tags = DEFAULT_TEST_TAGS,
    visibility = ["//doc:__pkg__"],
    deps = [
        ":pydrake_sphinx_extension_py",
        ":sphinx_base",
        "//bindings/pydrake",  # We must import `pydrake` to document it.
    ],
)

drake_py_binary(
    name = "serve_sphinx",
    srcs = ["serve_sphinx.py"],
    data = [":gen_sphinx"],
    tags = DEFAULT_BINARY_TAGS,
    visibility = ["//doc:__pkg__"],
    deps = [":sphinx_base"],
)

add_lint_tests_pydrake(
    python_lint_exclude = [":conf.py"],
)
