• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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("@python_versions//3.9:defs.bzl", compile_pip_requirements_3_9 = "compile_pip_requirements")
13load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
14
15# This stanza calls a rule that generates targets for managing pip dependencies
16# with pip-compile.
17compile_pip_requirements_3_9(
18    name = "requirements_3_9",
19    extra_args = ["--allow-unsafe"],
20    requirements_in = "requirements.in",
21    requirements_txt = "requirements_lock_3_9.txt",
22    requirements_windows = "requirements_windows_3_9.txt",
23)
24
25# This stanza calls a rule that generates targets for managing pip dependencies
26# with pip-compile.
27compile_pip_requirements_3_10(
28    name = "requirements_3_10",
29    extra_args = ["--allow-unsafe"],
30    requirements_in = "requirements.in",
31    requirements_txt = "requirements_lock_3_10.txt",
32    requirements_windows = "requirements_windows_3_10.txt",
33)
34
35# The rules below are language specific rules defined in
36# rules_python. See
37# https://bazel.build/reference/be/python
38
39# see https://bazel.build/reference/be/python#py_library
40py_library(
41    name = "lib",
42    srcs = ["lib.py"],
43    deps = [
44        requirement("pylint"),
45        requirement("tabulate"),
46        requirement("python-dateutil"),
47    ],
48)
49
50# see https://bazel.build/reference/be/python#py_binary
51py_binary(
52    name = "bzlmod",
53    srcs = ["__main__.py"],
54    main = "__main__.py",
55    visibility = ["//:__subpackages__"],
56    deps = [
57        ":lib",
58    ],
59)
60
61# see https://bazel.build/reference/be/python#py_test
62py_test(
63    name = "test",
64    srcs = ["test.py"],
65    main = "test.py",
66    deps = [":lib"],
67)
68
69py_test_with_transition(
70    name = "test_with_transition",
71    srcs = ["test.py"],
72    main = "test.py",
73    deps = [":lib"],
74)
75
76# This example is also used for integration tests within
77# rules_python.  We are using
78# https://github.com/bazelbuild/bazel-skylib
79# to run some of the tests.
80# See: https://github.com/bazelbuild/bazel-skylib/blob/main/docs/build_test_doc.md
81build_test(
82    name = "all_wheels",
83    targets = all_whl_requirements,
84)
85
86build_test(
87    name = "all_data_requirements",
88    targets = all_data_requirements,
89)
90
91build_test(
92    name = "all_requirements",
93    targets = all_requirements,
94)
95