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