Skip to content

Commit 02101a7

Browse files
authored
Initial sample generation documentation (#184)
1 parent f83c7d7 commit 02101a7

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

packages/gapic-generator/docker-entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ while [ -n "$1" ]; do
3131
elif [[ $1 == --gapic-* ]]; then
3232
PLUGIN_OPTIONS="$PLUGIN_OPTIONS,$1=$2"
3333
shift 2
34+
elif [[ $1 == --samples* ]]; then
35+
# --samples is a special option that all generators should recognize.
36+
PLUGIN_OPTIONS="$PLUGIN_OPTIONS,$1=$2"
37+
shift 2
3438
else
3539
# Ignore anything we do not recognize.
3640
shift
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Generating Samples
2+
~~~~~~~~~~~~~~~~~~
3+
4+
In addition to generating client libraries, the generator can also create standalone executable code samples.
5+
6+
The user can specify individual sample config files or can pass paths to directories that contain sample configs. Directories are searched recursively, and any file that is not a sample config is ignored.
7+
8+
..
9+
TODO: provide documentation links when they are present
10+
11+
A full description of the sample config, generated manifest, and generated samples is outside the scope of this documentation.
12+
We will provide links to such documentation when it is ready.
13+
14+
Samples and manifests are always generated in a 'samples' subdir of the destination directory.

packages/gapic-generator/docs/getting-started/docker.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,21 @@ Perform the actual code generation step with ``docker run``:
119119
structure present in the imports of the proto files must be preserved
120120
beneath this for compilation to succeed.
121121

122+
.. include:: _samplegen.rst
123+
124+
.. code-block:: shell
125+
126+
# Multiple sample paths or directories can be passed simultaneously by duplicating
127+
# the 'samples' option.
128+
# If no 'samples' option is passed, the generator does not generate a manifest.
129+
$ docker run \
130+
--mount type=bind,source=$(pwd)/path/to/proto/dir,destination=/in/path/to/proto,readonly \
131+
--mount type=bind,source=$(pwd)/dest/,destination=/out/ \
132+
--rm \
133+
--user $UID \
134+
gcr.io/gapic-images/gapic-generator-python \
135+
--samples path/to/sample/config.yaml \
136+
--samples path/to/sample/dir/
137+
122138
123139
.. include:: _verifying.rst

packages/gapic-generator/docs/getting-started/local.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,18 @@ This plugin is invoked under the hood via. the ``--python_gapic_out`` switch.
153153
where it expects to find protos, and *order matters*. In this case,
154154
the common protos must come first, and then the path to the API being built.
155155

156+
.. include:: _samplegen.rst
157+
158+
.. code-block:: shell
159+
160+
# Multiple sample paths or directories can be passed simultaneously by duplicating
161+
# the 'samples' option. Options are comma delimited.
162+
# If no 'samples' option is passed, the generator does not generate a manifest.
163+
$ protoc path/to/api/protos/*.proto \
164+
--proto_path=../api-common-protos/ \
165+
--proto_path=. \
166+
--python_gapic_opt="samples=sample_config.yaml,samples=sample_dir/" \
167+
--python_gapic_out=/dest/
168+
169+
156170
.. include:: _verifying.rst

0 commit comments

Comments
 (0)