Skip to content

Commit ad29d40

Browse files
authored
Enhance documentation for generate_py_protobufs. (protocolbuffers#7937)
This change updates the README.md to describe the order of resolution between `options['generate_py_protobufs']`, `--protoc`, and the `PROTOC` env var. Since the `setup.py` script is not the main way to find docs, this change deletes the parts of the docstring that are redundant with `README.md`.
1 parent 344f28d commit ad29d40

File tree

2 files changed

+17
-66
lines changed

2 files changed

+17
-66
lines changed

python/protobuf_distutils/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,19 @@ $ python -m pip install .
103103

104104
By default, the protoc binary (the Protobuf compiler) is found by
105105
searching the environment path. To use a specific protoc binary, its
106-
path can be specified.
106+
path can be specified. Resolution of the `protoc` value is as follows:
107+
1. If the `--protoc=VALUE` flag is passed to `generate_py_protobufs`,
108+
then `VALUE` will be used.
109+
For example:
110+
```shell
111+
$ python setup.py generate_py_protobufs --protoc=/path/to/protoc
112+
```
113+
2. Otherwise, if a value was set in the `options`, it will be used.
114+
(See "Example setup.py configuration," above.)
115+
3. Otherwise, if the `PROTOC` environment variable is set, it will be
116+
used. For example:
117+
For example:
118+
```shell
119+
$ PROTOC=/path/to/protoc python setup.py generate_py_protobufs
120+
```
121+
4. Otherwise, `$PATH` will be searched.

python/protobuf_distutils/setup.py

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -28,71 +28,7 @@
2828
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2929
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030

31-
"""Setuptools/distutils extension for generating Python protobuf code.
32-
33-
This extension uses a prebuilt 'protoc' binary to generate Python types for
34-
protobuf sources. By default, it will use a system-installed protoc binary, but
35-
a custom protoc can be specified by flag.
36-
37-
This command should usually be run before the 'build' command, so that the
38-
generated sources are treated the same way as the rest of the Python
39-
sources.
40-
41-
Options:
42-
43-
source_dir:
44-
This is the directory holding .proto files to be processed.
45-
46-
The default behavior is to generate sources for all .proto files found
47-
under `source_dir`, recursively. This behavior can be controlled with
48-
options below.
49-
50-
proto_root_path:
51-
This is the root path for resolving imports in source .proto files.
52-
53-
The default is the shortest prefix of `source_dir` among:
54-
[source_dir] + self.extra_proto_paths
55-
56-
extra_proto_paths:
57-
Specifies additional paths that should be used to find imports, in
58-
addition to `source_dir`.
59-
60-
This option can be used to specify the path to other protobuf sources,
61-
which are imported by files under `source_dir`. No Python code will be
62-
generated for .proto files under `extra_proto_paths`.
63-
64-
output_dir:
65-
Specifies where generated code should be placed.
66-
67-
Typically, this should be the root package that generated Python modules
68-
should be below.
69-
70-
The generated files will be named according to the relative source paths
71-
under `proto_root_path`. For example, this source .proto file:
72-
${proto_root_path}/subdir/message.proto
73-
will correspond to this generated Python module:
74-
${output_dir}/subdir/message_pb2.py
75-
76-
proto_files:
77-
Specific .proto files can be specified for generating code, instead of
78-
searching for all .proto files under `source_path`.
79-
80-
These paths are relative to `source_dir`. For example, to generate code
81-
for just ${source_dir}/subdir/message.proto, specify
82-
['subdir/message.proto'].
83-
84-
protoc:
85-
By default, the protoc binary (the Protobuf compiler) is found by
86-
searching the environment path. To use a specific protoc binary, its
87-
path can be specified.
88-
89-
recurse:
90-
If `proto_files` are not specified, then the default behavior is to
91-
search `source_dir` recursively. This option controls the recursive
92-
search; if it is False, only .proto files immediately under `source_dir`
93-
will be used to generate sources.
94-
95-
"""
31+
"""Setuptools/distutils extension for generating Python protobuf code."""
9632

9733
__author__ = '[email protected] (David L. Jones)'
9834

0 commit comments

Comments
 (0)