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 bazel
Bazel build is mostly hermetic, with a few exceptions for Python generator. Specifically it expects Python 3.7+ with the python dev packages to be installed.
On Linux, to install those, simply run:
sudo apt-get install \
python-dev \
python3-dev
To 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.git
The API we use as an example is the Document AI API, available in the google/cloud/documentai/v1beta2/
subdirectory.
To build somethign with bazel you need to create the corresponding tagets in your BUIDL.bazel
file. You can use the Python section of the Document AI BUIDL.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",
],
)
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-py
This 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