load("//tools/jupyter:jupyter_py.bzl", "drake_jupyter_py_binary")
load("//tools/lint:lint.bzl", "add_lint_tests")
load("//tools/skylark:drake_py.bzl", "drake_py_unittest")
load("//tools/skylark:py.bzl", "py_library")

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

# Note that we do NOT use drake_py_library here, so that our codegen via the
# JUPYTER_PY_TEMPLATE file is as simple and portable as possible. Instead,
# we'll use an `imports = ["."]` to establish a helpful `sys.path`.
py_library(
    name = "jupyter_bazel_py",
    srcs = ["jupyter_bazel.py"],
    imports = ["."],
    visibility = ["//visibility:public"],
)

# Note that we do NOT use drake_py_library here, so that this program is a
# more representative demo of what and end user would experience. Instead,
# we'll use an `imports = ["."]` to establish a helpful `sys.path`.
py_library(
    name = "example_library",
    srcs = ["example_library.py"],
    imports = ["."],
)

drake_jupyter_py_binary(
    name = "example",
    add_test_rule = 1,
    deps = [":example_library"],
)

drake_py_unittest(
    name = "jupyter_notebook_test",
)

# Add example failing notebook.
drake_jupyter_py_binary(
    name = "failing_notebook",
    testonly = 1,
    # Do not test this on its own because it is a negative test fixture for
    # `failing_notebook_test`.
    add_test_rule = 0,
    notebook = "test/failing_notebook.ipynb",
)

# Add example failing notebook due to deprecation.
drake_jupyter_py_binary(
    name = "failing_notebook_deprecation",
    testonly = 1,
    # Do not test this on its own because it is a negative test fixture for
    # `failing_notebook_test`.
    add_test_rule = 0,
    notebook = "test/failing_notebook_deprecation.ipynb",
    deps = [
        # N.B. Use granular target which does not depend on C extensions.
        "//bindings/pydrake/common:deprecation_py",
    ],
)

# Ensure the notebook fails as expected.
drake_py_unittest(
    name = "failing_notebook_test",
    # TODO(eric.cousineau): Reset default flaky value to False once #12536
    # is resolved.
    flaky = 1,
    deps = [
        ":failing_notebook",
        ":failing_notebook_deprecation",
    ],
)

add_lint_tests()
