xref: /aosp_15_r20/external/bazelbuild-rules_python/examples/pip_repository_annotations/WORKSPACE (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
1workspace(name = "pip_repository_annotations_example")
2
3local_repository(
4    name = "rules_python",
5    path = "../..",
6)
7
8load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")
9
10py_repositories()
11
12python_register_toolchains(
13    name = "python39",
14    python_version = "3.9",
15)
16
17load("@rules_python//python:pip.bzl", "package_annotation", "pip_parse")
18
19# Here we can see an example of annotations being applied to an arbitrary
20# package. For details on `package_annotation` and it's uses, see the
21# docs at @rules_python//docs:pip.md`.
22ANNOTATIONS = {
23    # This annotation verifies that annotations work correctly for pip packages with extras
24    # specified, in this case requests[security].
25    "requests": package_annotation(
26        additive_build_content = """\
27load("@bazel_skylib//rules:write_file.bzl", "write_file")
28write_file(
29    name = "generated_file",
30    out = "generated_file.txt",
31    content = ["Hello world from requests"],
32)
33""",
34        data = [":generated_file"],
35    ),
36    "wheel": package_annotation(
37        additive_build_content = """\
38load("@bazel_skylib//rules:write_file.bzl", "write_file")
39write_file(
40    name = "generated_file",
41    out = "generated_file.txt",
42    content = ["Hello world from build content file"],
43)
44""",
45        copy_executables = {"@pip_repository_annotations_example//:data/copy_executable.py": "copied_content/executable.py"},
46        copy_files = {"@pip_repository_annotations_example//:data/copy_file.txt": "copied_content/file.txt"},
47        data = [":generated_file"],
48        data_exclude_glob = ["site-packages/*.dist-info/WHEEL"],
49    ),
50}
51
52# For a more thorough example of `pip_parse`. See `@rules_python//examples/pip_parse`
53pip_parse(
54    name = "pip",
55    annotations = ANNOTATIONS,
56    python_interpreter_target = "@python39_host//:python",
57    requirements_lock = "//:requirements.txt",
58)
59
60load("@pip//:requirements.bzl", "install_deps")
61
62install_deps()
63