Skip to content

Commit

Permalink
Initial sample generation documentation (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
software-dov authored Aug 21, 2019
1 parent 88ab687 commit f71fc44
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ while [ -n "$1" ]; do
elif [[ $1 == --gapic-* ]]; then
PLUGIN_OPTIONS="$PLUGIN_OPTIONS,$1=$2"
shift 2
elif [[ $1 == --samples* ]]; then
# --samples is a special option that all generators should recognize.
PLUGIN_OPTIONS="$PLUGIN_OPTIONS,$1=$2"
shift 2
else
# Ignore anything we do not recognize.
shift
Expand Down
14 changes: 14 additions & 0 deletions docs/getting-started/_samplegen.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Generating Samples
~~~~~~~~~~~~~~~~~~

In addition to generating client libraries, the generator can also create standalone executable code samples.

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.

..
TODO: provide documentation links when they are present
A full description of the sample config, generated manifest, and generated samples is outside the scope of this documentation.
We will provide links to such documentation when it is ready.

Samples and manifests are always generated in a 'samples' subdir of the destination directory.
16 changes: 16 additions & 0 deletions docs/getting-started/docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,21 @@ Perform the actual code generation step with ``docker run``:
structure present in the imports of the proto files must be preserved
beneath this for compilation to succeed.

.. include:: _samplegen.rst

.. code-block:: shell
# Multiple sample paths or directories can be passed simultaneously by duplicating
# the 'samples' option.
# If no 'samples' option is passed, the generator does not generate a manifest.
$ docker run \
--mount type=bind,source=$(pwd)/path/to/proto/dir,destination=/in/path/to/proto,readonly \
--mount type=bind,source=$(pwd)/dest/,destination=/out/ \
--rm \
--user $UID \
gcr.io/gapic-images/gapic-generator-python \
--samples path/to/sample/config.yaml \
--samples path/to/sample/dir/
.. include:: _verifying.rst
14 changes: 14 additions & 0 deletions docs/getting-started/local.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,18 @@ This plugin is invoked under the hood via. the ``--python_gapic_out`` switch.
where it expects to find protos, and *order matters*. In this case,
the common protos must come first, and then the path to the API being built.

.. include:: _samplegen.rst

.. code-block:: shell
# Multiple sample paths or directories can be passed simultaneously by duplicating
# the 'samples' option. Options are comma delimited.
# If no 'samples' option is passed, the generator does not generate a manifest.
$ protoc path/to/api/protos/*.proto \
--proto_path=../api-common-protos/ \
--proto_path=. \
--python_gapic_opt="samples=sample_config.yaml,samples=sample_dir/" \
--python_gapic_out=/dest/
.. include:: _verifying.rst

0 comments on commit f71fc44

Please sign in to comment.