This generator can be called from Bazel, which is a recommended way of using it inside a continuous integration build or any other automated pipeline.
You will need Bazel version 3.0+. Please check the Bazel website for the available installation options.
Bazel is distributed in a form of a single binary, so one of the easiest ways to install it is simply downloading the binary and making it executable:
curl -L https://github.com/bazelbuild/bazel/releases/download/3.2.0/bazel-3.2.0-linux-x86_64 -o bazel
chmod +x bazelBazel build is mostly hermetic, with a few exceptions for Python generator. Specifically it expects Python 3.10+ with the python dev packages to be installed.
On Linux, to install those, simply run:
sudo apt-get install \
python-dev \
python3-devTo generate a client library with Bazel you will need a Bazel workspace. An example of such workspace would be googleapis. It is already integrated with this this generator in its WORKSPACE file.
You need to clone the googleapis repository from GitHub:
$ git clone https://github.com/googleapis/googleapis.gitThe API we use as an example is the Document AI API,
available in the google/cloud/documentai/v1beta2/ subdirectory.
To build something with bazel you need to create the corresponding targets in
your BUILD.bazel file. You can use the Python section of the Document AI
BUILD.bazel file as an example:
load(
"@gapic_generator_python//rules_python_gapic:py_gapic.bzl",
"py_gapic_library"
)
load(
"@gapic_generator_python//rules_python_gapic:py_gapic_pkg.bzl",
"py_gapic_assembly_pkg"
)
py_gapic_library(
name = "documentai_py_gapic",
srcs = [":documentai_proto"],
)
py_gapic_assembly_pkg(
name = "documentai-v1beta2-py",
deps = [
":documentai_py_gapic",
],
)- Some of the
py_gapic_libraryrule that may be of interest: transport: the desired transport(s) to generate, delimited by+e.g.grpc+rest. - Acceptable values aregrpcandrest. - Defaults togrpc.rest_numeric_enums: ifTrue, enables generation of system parameter requesting response enums be encoded as numbers. - Default isFalse. - Only effective whenrestis included as atransportto be generated.
To generate the client library simply run the bazel command from the repository root, specifying the py_gapic_assembly_pkg target name as the argument:
bazel build //google/cloud/documentai/v1beta2:documentai-v1beta2-pyThis will generate a tar.gz archive with the generated library packaged in it. To unpack it in dest location simply run the following command from the Bazel workspace root:
tar -xzpf bazel-bin/google/cloud/documentai/v1beta2/documentai-v1beta2-py.tar.gz -C dest