aboutsummaryrefslogtreecommitdiff
path: root/examples/bzlmod/BUILD.bazel
blob: 3db7751f72872e3c26cdfd9d46879fe8bff22245 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Load various rules so that we can have bazel download
# various rulesets and dependencies.
# The `load` statement imports the symbol for the rule, in the defined
# ruleset. When the symbol is loaded you can use the rule.

# The names @pip and @python_39 are values that are repository
# names. Those names are defined in the MODULES.bazel file.
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@pip//:requirements.bzl", "all_data_requirements", "all_requirements", "all_whl_requirements", "requirement")
load("@python_3_9//:defs.bzl", py_test_with_transition = "py_test")
load("@python_versions//3.10:defs.bzl", compile_pip_requirements_3_10 = "compile_pip_requirements")
load("@python_versions//3.9:defs.bzl", compile_pip_requirements_3_9 = "compile_pip_requirements")
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")

# This stanza calls a rule that generates targets for managing pip dependencies
# with pip-compile.
compile_pip_requirements_3_9(
    name = "requirements_3_9",
    extra_args = ["--allow-unsafe"],
    requirements_in = "requirements.in",
    requirements_txt = "requirements_lock_3_9.txt",
    requirements_windows = "requirements_windows_3_9.txt",
)

# This stanza calls a rule that generates targets for managing pip dependencies
# with pip-compile.
compile_pip_requirements_3_10(
    name = "requirements_3_10",
    extra_args = ["--allow-unsafe"],
    requirements_in = "requirements.in",
    requirements_txt = "requirements_lock_3_10.txt",
    requirements_windows = "requirements_windows_3_10.txt",
)

# The rules below are language specific rules defined in
# rules_python. See
# https://bazel.build/reference/be/python

# see https://bazel.build/reference/be/python#py_library
py_library(
    name = "lib",
    srcs = ["lib.py"],
    deps = [
        requirement("pylint"),
        requirement("tabulate"),
        requirement("python-dateutil"),
    ],
)

# see https://bazel.build/reference/be/python#py_binary
py_binary(
    name = "bzlmod",
    srcs = ["__main__.py"],
    main = "__main__.py",
    visibility = ["//:__subpackages__"],
    deps = [
        ":lib",
    ],
)

# see https://bazel.build/reference/be/python#py_test
py_test(
    name = "test",
    srcs = ["test.py"],
    main = "test.py",
    deps = [":lib"],
)

py_test_with_transition(
    name = "test_with_transition",
    srcs = ["test.py"],
    main = "test.py",
    deps = [":lib"],
)

# This example is also used for integration tests within
# rules_python.  We are using
# https://github.com/bazelbuild/bazel-skylib
# to run some of the tests.
# See: https://github.com/bazelbuild/bazel-skylib/blob/main/docs/build_test_doc.md
build_test(
    name = "all_wheels",
    targets = all_whl_requirements,
)

build_test(
    name = "all_data_requirements",
    targets = all_data_requirements,
)

build_test(
    name = "all_requirements",
    targets = all_requirements,
)