load("//bindings/pydrake:pydrake.bzl", "add_lint_tests_pydrake")
load("//tools/install:install.bzl", "install")
load(
    "//tools/skylark:drake_cc.bzl",
    "drake_cc_library",
)
load(
    "//tools/skylark:drake_py.bzl",
    "drake_py_binary",
    "drake_py_library",
    "drake_py_unittest",
)
load(
    "//tools/skylark:pybind.bzl",
    "EXTRA_PYBIND_COPTS",
    "get_pybind_package_info",
)

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

# This determines how `PYTHONPATH` is configured, and how to install the
# bindings.
PACKAGE_INFO = get_pybind_package_info("//bindings")

# N.B. The `pydrake.math` module is part of the root module dependency cycle.
# Refer to bindings/pydrake/common/module_cycle.md for details.

drake_cc_library(
    name = "math_py",
    srcs = [
        "math_py_matmul.cc",
        "math_py_operators.cc",
        # TODO(jwnimmer-tri) Split the monolith into pieces.
        "math_py_monolith.cc",
    ],
    hdrs = [
        "math_py.h",
    ],
    copts = EXTRA_PYBIND_COPTS,
    declare_installed_headers = False,
    visibility = [
        "//bindings/pydrake/common:__pkg__",
    ],
    deps = [
        "//bindings/pydrake:autodiff_types_pybind",
        "//bindings/pydrake:documentation_pybind",
        "//bindings/pydrake:math_operators_pybind",
        "//bindings/pydrake:symbolic_types_pybind",
        "//bindings/pydrake/common:cpp_template_pybind",
        "//bindings/pydrake/common:default_scalars_pybind",
        "//bindings/pydrake/common:eigen_pybind",
        "//bindings/pydrake/common:type_pack",
        "//bindings/pydrake/common:value_pybind",
    ],
)

drake_py_library(
    name = "math_extra",
    srcs = ["_math_extra.py"],
    visibility = [
        "//bindings/pydrake/common:__pkg__",
    ],
)

install(
    name = "install",
    targets = [":math_extra"],
    py_dest = PACKAGE_INFO.py_dest,
    visibility = ["//bindings/pydrake:__pkg__"],
)

drake_py_binary(
    name = "math_example",
    srcs = ["math_example.py"],
    add_test_rule = True,
    isolate = True,
    deps = [
        "//bindings/pydrake:module_py",
    ],
)

drake_py_unittest(
    name = "math_test",
    deps = [
        "//bindings/pydrake:module_py",
        "//bindings/pydrake/common/test_utilities",
    ],
)

drake_py_unittest(
    name = "math_overloads_test",
    deps = [
        "//bindings/pydrake:module_py",
    ],
)

drake_py_unittest(
    name = "math_overloads_matrix_test",
    deps = [
        "//bindings/pydrake:module_py",
        "//bindings/pydrake/common/test_utilities:meta_py",
        "//bindings/pydrake/common/test_utilities:numpy_compare_py",
    ],
)

add_lint_tests_pydrake()
