• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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("@python39//:defs.bzl", "interpreter")
18load("@rules_python//python:pip.bzl", "package_annotation", "pip_install", "pip_parse")
19
20# Here we can see an example of annotations being applied to an arbitrary
21# package. For details on `package_annotation` and it's uses, see the
22# docs at @rules_python//docs:pip.md`.
23ANNOTATIONS = {
24    # This annotation verifies that annotations work correctly for pip packages with extras
25    # specified, in this case requests[security].
26    "requests": package_annotation(
27        additive_build_content = """\
28load("@bazel_skylib//rules:write_file.bzl", "write_file")
29write_file(
30    name = "generated_file",
31    out = "generated_file.txt",
32    content = ["Hello world from requests"],
33)
34""",
35        data = [":generated_file"],
36    ),
37    "wheel": package_annotation(
38        additive_build_content = """\
39load("@bazel_skylib//rules:write_file.bzl", "write_file")
40write_file(
41    name = "generated_file",
42    out = "generated_file.txt",
43    content = ["Hello world from build content file"],
44)
45""",
46        copy_executables = {"@pip_repository_annotations_example//:data/copy_executable.py": "copied_content/executable.py"},
47        copy_files = {"@pip_repository_annotations_example//:data/copy_file.txt": "copied_content/file.txt"},
48        data = [":generated_file"],
49        data_exclude_glob = ["site-packages/*.dist-info/WHEEL"],
50    ),
51}
52
53# For a more thorough example of `pip_parse`. See `@rules_python//examples/pip_parse`
54pip_parse(
55    name = "pip_parsed",
56    annotations = ANNOTATIONS,
57    python_interpreter_target = interpreter,
58    requirements_lock = "//:requirements.txt",
59)
60
61load("@pip_parsed//:requirements.bzl", install_pip_parse_deps = "install_deps")
62
63install_pip_parse_deps()
64
65# For a more thorough example of `pip_install`. See `@rules_python//examples/pip_install`
66pip_install(
67    name = "pip_installed",
68    annotations = ANNOTATIONS,
69    python_interpreter_target = interpreter,
70    requirements = "//:requirements.txt",
71)
72
73load("@pip_installed//:requirements.bzl", install_pip_install_deps = "install_deps")
74
75install_pip_install_deps()
76