Open codersasha opened 1 year ago
I figured out a way to include the az binary in Bazel, as a python target. If I get time I'll write up a PR to add it to this repo -- otherwise, here's all the Bazel code you need to run bazel run azur-cli :)
az
bazel run azur-cli
WORKSPACE:
WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "rules_python", sha256 = "8c8fe44ef0a9afc256d1e75ad5f448bb59b81aba149b8958f02f7b3a98f5d9b4", strip_prefix = "rules_python-0.13.0", url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.13.0.tar.gz", ) load("@rules_python//python:repositories.bzl", "python_register_toolchains") python_register_toolchains( name = "python3_9", python_version = "3.9", ) load("@python3_9//:defs.bzl", "interpreter") load("@rules_python//python:pip.bzl", "pip_parse") pip_parse( name = "pip", python_interpreter_target = interpreter, requirements_lock = "//:requirements_lock.txt", ) load("@pip//:requirements.bzl", "install_deps") install_deps()
BUILD.bazel:
BUILD.bazel
load("@rules_python//python:defs.bzl", "py_binary") load("@rules_python//python:pip.bzl", "compile_pip_requirements") compile_pip_requirements( name = "requirements", extra_args = ["--allow-unsafe"], requirements_in = "requirements.in", requirements_txt = "requirements_lock.txt", ) py_binary( name = "azure-cli", srcs = ["@pip_azure_cli//:site-packages/azure/cli/__main__.py"], main = "@pip_azure_cli//:site-packages/azure/cli/__main__.py", deps = ["@pip_azure_cli//:pkg"], )
requirements.in:
requirements.in
azure-cli==2.40.0
requirements_lock.txt:
requirements_lock.txt
<starts out blank, run bazel run requirements.update to generate>
bazel run requirements.update
You could also probably tweak it to move requirements.in to a write_file command, and then generate requirements.txt from a genrule.
write_file
requirements.txt
This is amazing! Now we don't need to have the Azure CLI pre-installed to use these rules. Incredible!!
I figured out a way to include the
az
binary in Bazel, as a python target. If I get time I'll write up a PR to add it to this repo -- otherwise, here's all the Bazel code you need to runbazel run azur-cli
:)WORKSPACE
:BUILD.bazel
:requirements.in
:requirements_lock.txt
:<starts out blank, run
bazel run requirements.update
to generate>You could also probably tweak it to move
requirements.in
to awrite_file
command, and then generaterequirements.txt
from a genrule.