xref: /aosp_15_r20/external/bazelbuild-rules_python/examples/bzlmod/BUILD.bazel (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
1# Load various rules so that we can have bazel download
2# various rulesets and dependencies.
3# The `load` statement imports the symbol for the rule, in the defined
4# ruleset. When the symbol is loaded you can use the rule.
5
6# The names @pip and @python_39 are values that are repository
7# names. Those names are defined in the MODULES.bazel file.
8load("@bazel_skylib//rules:build_test.bzl", "build_test")
9load("@pip//:requirements.bzl", "all_data_requirements", "all_requirements", "all_whl_requirements", "requirement")
10load("@python_3_9//:defs.bzl", py_test_with_transition = "py_test")
11load("@python_versions//3.10:defs.bzl", compile_pip_requirements_3_10 = "compile_pip_requirements")
12load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
13
14# This stanza calls a rule that generates targets for managing pip dependencies
15# with pip-compile for a particular python version.
16compile_pip_requirements_3_10(
17    name = "requirements_3_10",
18    timeout = "moderate",
19    src = "requirements.in",
20    requirements_txt = "requirements_lock_3_10.txt",
21    requirements_windows = "requirements_windows_3_10.txt",
22)
23
24# The rules below are language specific rules defined in
25# rules_python. See
26# https://bazel.build/reference/be/python
27
28# see https://bazel.build/reference/be/python#py_library
29py_library(
30    name = "lib",
31    srcs = ["lib.py"],
32    deps = [
33        requirement("sphinx"),
34        requirement("pylint"),
35        requirement("tabulate"),
36        requirement("python-dateutil"),
37    ],
38)
39
40# see https://bazel.build/reference/be/python#py_binary
41py_binary(
42    name = "bzlmod",
43    srcs = ["__main__.py"],
44    main = "__main__.py",
45    visibility = ["//:__subpackages__"],
46    deps = [
47        ":lib",
48    ],
49)
50
51# see https://bazel.build/reference/be/python#py_test
52py_test(
53    name = "test",
54    srcs = ["test.py"],
55    main = "test.py",
56    deps = [":lib"],
57)
58
59py_test_with_transition(
60    name = "test_with_transition",
61    srcs = ["test.py"],
62    main = "test.py",
63    deps = [":lib"],
64)
65
66# This example is also used for integration tests within
67# rules_python.  We are using
68# https://github.com/bazelbuild/bazel-skylib
69# to run some of the tests.
70# See: https://github.com/bazelbuild/bazel-skylib/blob/main/docs/build_test_doc.md
71build_test(
72    name = "all_wheels",
73    targets = all_whl_requirements,
74)
75
76build_test(
77    name = "all_data_requirements",
78    targets = all_data_requirements,
79)
80
81build_test(
82    name = "all_requirements",
83    targets = all_requirements,
84)
85