|
| 1 | +workspace(name = "pip_repository_annotations_example") |
| 2 | + |
| 3 | +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") |
| 4 | + |
| 5 | +http_archive( |
| 6 | + name = "rules_python", |
| 7 | + sha256 = "cd6730ed53a002c56ce4e2f396ba3b3be262fd7cb68339f0377a45e8227fe332", |
| 8 | + url = "https://github.com/bazelbuild/rules_python/releases/download/0.5.0/rules_python-0.5.0.tar.gz", |
| 9 | +) |
| 10 | + |
| 11 | +http_archive( |
| 12 | + name = "bazel_skylib", |
| 13 | + sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d", |
| 14 | + urls = [ |
| 15 | + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz", |
| 16 | + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz", |
| 17 | + ], |
| 18 | +) |
| 19 | + |
| 20 | +load("@rules_python//python:pip.bzl", "package_annotation", "pip_install", "pip_parse") |
| 21 | + |
| 22 | +# Here we can see an example of annotations being applied to an arbitrary |
| 23 | +# package. For details on `package_annotation` and it's uses, see the |
| 24 | +# docs at @rules_python//docs:pip.md`. |
| 25 | +ANNOTATIONS = { |
| 26 | + "wheel": package_annotation( |
| 27 | + additive_build_content = """\ |
| 28 | +load("@bazel_skylib//rules:write_file.bzl", "write_file") |
| 29 | +write_file( |
| 30 | + name = "generated_file", |
| 31 | + out = "generated_file.txt", |
| 32 | + content = ["Hello world from build content file"], |
| 33 | +) |
| 34 | +""", |
| 35 | + copy_executables = {"@pip_repository_annotations_example//:data/copy_executable.py": "copied_content/executable.py"}, |
| 36 | + copy_files = {"@pip_repository_annotations_example//:data/copy_file.txt": "copied_content/file.txt"}, |
| 37 | + data = [":generated_file"], |
| 38 | + data_exclude_glob = ["*.dist-info/RECORD"], |
| 39 | + ), |
| 40 | +} |
| 41 | + |
| 42 | +# For a more thorough example of `pip_parse`. See `@rules_python//examples/pip_parse` |
| 43 | +pip_parse( |
| 44 | + name = "pip_parsed", |
| 45 | + annotations = ANNOTATIONS, |
| 46 | + requirements_lock = "//:requirements.txt", |
| 47 | +) |
| 48 | + |
| 49 | +load("@pip_parsed//:requirements.bzl", "install_deps") |
| 50 | + |
| 51 | +install_deps() |
| 52 | + |
| 53 | +# For a more thorough example of `pip_install`. See `@rules_python//examples/pip_install` |
| 54 | +pip_install( |
| 55 | + name = "pip_installed", |
| 56 | + annotations = ANNOTATIONS, |
| 57 | + requirements = "//:requirements.txt", |
| 58 | +) |
0 commit comments