Skip to content

Commit 61f80e1

Browse files
committed
docs: sync README with synthtool templates
1 parent 3aa67a5 commit 61f80e1

File tree

21 files changed

+897
-177
lines changed

21 files changed

+897
-177
lines changed

gapic/schema/naming.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class Naming(abc.ABC):
4545
proto_package: str = ""
4646
_warehouse_package_name: str = ""
4747
proto_plus_deps: Tuple[str, ...] = dataclasses.field(default_factory=tuple)
48+
api_description: str = ""
49+
_documentation_name: str = ""
50+
documentation_uri: str = ""
51+
release_level: str = ""
52+
title: str = ""
4853

4954
def __post_init__(self):
5055
if not self.product_name:
@@ -154,6 +159,30 @@ def build(
154159
package_info = dataclasses.replace(
155160
package_info, _warehouse_package_name=opts.warehouse_package_name
156161
)
162+
163+
if opts.api_description:
164+
package_info = dataclasses.replace(
165+
package_info, api_description=opts.api_description
166+
)
167+
168+
if opts.documentation_name:
169+
package_info = dataclasses.replace(
170+
package_info, _documentation_name=opts.documentation_name
171+
)
172+
173+
if opts.documentation_uri:
174+
package_info = dataclasses.replace(
175+
package_info, documentation_uri=opts.documentation_uri
176+
)
177+
178+
if opts.release_level:
179+
package_info = dataclasses.replace(
180+
package_info, release_level=opts.release_level
181+
)
182+
183+
if opts.title:
184+
package_info = dataclasses.replace(package_info, title=opts.title)
185+
157186
if opts.proto_plus_deps:
158187
package_info = dataclasses.replace(
159188
package_info,
@@ -212,6 +241,15 @@ def warehouse_package_name(self) -> str:
212241
answer = list(self.namespace) + self.name.split(" ")
213242
return "-".join(answer).lower()
214243

244+
@property
245+
def documentation_name(self) -> str:
246+
"""Return the appropriate name for documentation."""
247+
# If a custom name has been set, use it
248+
if self._documentation_name:
249+
return self._documentation_name
250+
# Otherwise use `name` for backwards compatibility
251+
return self.name.lower()
252+
215253

216254
class NewNaming(Naming):
217255
@property

gapic/templates/README.rst.j2

Lines changed: 88 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
1-
Python Client for {{ api.naming.long_name }} API
2-
=================================================
1+
Python Client for {{ api.naming.title }}
2+
=================={% for i in range( api.naming.title | length ) %}={% endfor %}
3+
4+
5+
|{{ api.naming.release_level }}| |pypi| |versions|
6+
7+
`{{ api.naming.title }}`_: {% if api.naming.api_description %}{{ api.naming.api_description.replace("\n", " ") }}{% endif %}
8+
9+
10+
- `Client Library Documentation`_
11+
- `Product Documentation`_
12+
13+
.. |{{ api.naming.release_level }}| image:: https://img.shields.io/badge/support-{{ api.naming.release_level }}-{% if api.naming.release_level == "stable" %}gold{% else %}orange{% endif %}.svg
14+
:target: https://github.com/googleapis/google-cloud-python/blob/main/README.rst#stability-levels
15+
.. |pypi| image:: https://img.shields.io/pypi/v/{{ api.naming.warehouse_package_name }}.svg
16+
:target: https://pypi.org/project/{{ api.naming.warehouse_package_name }}/
17+
.. |versions| image:: https://img.shields.io/pypi/pyversions/{{ api.naming.warehouse_package_name }}.svg
18+
:target: https://pypi.org/project/{{ api.naming.warehouse_package_name }}/
19+
.. _{{ api.naming.title }}: {{ api.naming.documentation_uri }}
20+
{% if api.naming.module_namespace|length >= 2 and api.naming.module_namespace[0] == "google" and api.naming.module_namespace[1] == "cloud" %}
21+
.. _Client Library Documentation: https://cloud.google.com/python/docs/reference/{{ api.naming.documentation_name }}/latest/summary_overview
22+
{% else %}
23+
.. _Client Library Documentation: https://cloud.google.com/python/docs/reference/{{ api.naming.documentation_name }}/latest
24+
{% endif %}
25+
.. _Product Documentation: {{ api.naming.documentation_uri }}
326

427
Quick Start
528
-----------
@@ -8,26 +31,55 @@ In order to use this library, you first need to go through the following steps:
831

932
1. `Select or create a Cloud Platform project.`_
1033
2. `Enable billing for your project.`_
11-
3. Enable the {{ api.naming.long_name }} API.
12-
4. `Setup Authentication.`_
34+
3. `Enable the {{ api.naming.title }}.`_
35+
4. `Set up Authentication.`_
1336

1437
.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project
1538
.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project
16-
.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html
39+
.. _Enable the {{ api.naming.title }}.: {{ api.naming.documentation_uri }}
40+
.. _Set up Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html
1741

1842
Installation
1943
~~~~~~~~~~~~
2044

21-
Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to
22-
create isolated Python environments. The basic problem it addresses is one of
23-
dependencies and versions, and indirectly permissions.
45+
Install this library in a virtual environment using `venv`_. `venv`_ is a tool that
46+
creates isolated Python environments. These isolated environments can have separate
47+
versions of Python packages, which allows you to isolate one project's dependencies
48+
from the dependencies of other projects.
2449

25-
With `virtualenv`_, it's possible to install this library without needing system
50+
With `venv`_, it's possible to install this library without needing system
2651
install permissions, and without clashing with the installed system
2752
dependencies.
2853

29-
.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/
54+
.. _`venv`: https://docs.python.org/3/library/venv.html
55+
56+
57+
Code samples and snippets
58+
~~~~~~~~~~~~~~~~~~~~~~~~~
59+
60+
Code samples and snippets live in the `samples/`_ folder.
61+
62+
.. _samples/: https://github.com/googleapis/google-cloud-python/tree/main/packages/{{ api.naming.warehouse_package_name }}/samples
63+
64+
65+
Supported Python Versions
66+
^^^^^^^^^^^^^^^^^^^^^^^^^
67+
Our client libraries are compatible with all current `active`_ and `maintenance`_ versions of
68+
Python.
69+
70+
Python >= 3.7
71+
72+
.. _active: https://devguide.python.org/devcycle/#in-development-main-branch
73+
.. _maintenance: https://devguide.python.org/devcycle/#maintenance-branches
3074

75+
Unsupported Python Versions
76+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
77+
Python <= 3.6
78+
79+
If you are using an `end-of-life`_
80+
version of Python, we recommend that you update as soon as possible to an actively supported version.
81+
82+
.. _end-of-life: https://devguide.python.org/devcycle/#end-of-life-branches
3183

3284
Mac/Linux
3385
^^^^^^^^^
@@ -36,18 +88,30 @@ Mac/Linux
3688

3789
python3 -m venv <your-env>
3890
source <your-env>/bin/activate
39-
<your-env>/bin/pip install /path/to/library
91+
pip install {{ api.naming.warehouse_package_name }}
4092

4193

4294
Windows
4395
^^^^^^^
4496

4597
.. code-block:: console
4698

47-
python3 -m venv <your-env>
48-
<your-env>\Scripts\activate
49-
<your-env>\Scripts\pip.exe install \path\to\library
99+
py -m venv <your-env>
100+
.\<your-env>\Scripts\activate
101+
pip install {{ api.naming.warehouse_package_name }}
102+
103+
Next Steps
104+
~~~~~~~~~~
50105

106+
- Read the `Client Library Documentation`_ for {{ api.naming.title }}
107+
to see other available methods on the client.
108+
- Read the `{{ api.naming.title }} Product documentation`_ to learn
109+
more about the product and see How-to Guides.
110+
- View this `README`_ to see the full list of Cloud
111+
APIs that we cover.
112+
113+
.. _{{ api.naming.title }} Product documentation: {{ api.naming.documentation_uri }}
114+
.. _README: https://github.com/googleapis/google-cloud-python/blob/main/README.rst
51115

52116
Logging
53117
-------
@@ -59,7 +123,6 @@ Note the following:
59123
#. Google may refine the occurrence, level, and content of various log messages in this library without flagging such changes as breaking. **Do not depend on immutability of the logging events**.
60124
#. By default, the logging events from this library are not handled. You must **explicitly configure log handling** using one of the mechanisms below.
61125

62-
63126
Simple, environment-based configuration
64127
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65128

@@ -75,9 +138,8 @@ A logging scope is a period-separated namespace that begins with :code:`google`,
75138

76139
**NOTE**: If the logging scope is invalid, the library does not set up any logging handlers.
77140

78-
79-
Examples
80-
^^^^^^^^
141+
Environment-Based Examples
142+
^^^^^^^^^^^^^^^^^^^^^^^^^^
81143

82144
- Enabling the default handler for all Google-based loggers
83145

@@ -97,18 +159,17 @@ Advanced, code-based configuration
97159

98160
You can also configure a valid logging scope using Python's standard `logging` mechanism.
99161

100-
101-
Examples
102-
^^^^^^^^
162+
Code-Based Examples
163+
^^^^^^^^^^^^^^^^^^^
103164

104165
- Configuring a handler for all Google-based loggers
105166

106167
.. code-block:: python
107168

108169
import logging
109-
110-
from google.cloud.translate_v3 import translate
111-
170+
171+
from google.cloud import library_v1
172+
112173
base_logger = logging.getLogger("google")
113174
base_logger.addHandler(logging.StreamHandler())
114175
base_logger.setLevel(logging.DEBUG)
@@ -118,14 +179,13 @@ Examples
118179
.. code-block:: python
119180

120181
import logging
121-
122-
from google.cloud.translate_v3 import translate
123-
182+
183+
from google.cloud import library_v1
184+
124185
base_logger = logging.getLogger("google.cloud.library_v1")
125186
base_logger.addHandler(logging.StreamHandler())
126187
base_logger.setLevel(logging.DEBUG)
127188

128-
129189
Logging details
130190
~~~~~~~~~~~~~~~
131191

gapic/templates/docs/README.rst.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../README.rst.j2

gapic/templates/docs/index.rst.j2

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. include:: README.rst
2+
13
.. include:: multiprocessing.rst
24

35

@@ -8,3 +10,21 @@ API Reference
810

911
{{ api.naming.versioned_module_name }}/services_
1012
{{ api.naming.versioned_module_name }}/types_
13+
14+
15+
Changelog
16+
---------
17+
18+
For a list of all ``{{ api.naming.warehouse_package_name }}`` releases:
19+
20+
.. toctree::
21+
:maxdepth: 2
22+
23+
CHANGELOG
24+
25+
.. toctree::
26+
:hidden:
27+
{% if api.naming.module_namespace|length >= 2 and api.naming.module_namespace[0] == "google" and api.naming.module_namespace[1] == "cloud" %}
28+
29+
summary_overview.md
30+
{% endif %}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
This is a templated file. Adding content to this file may result in it being
3+
reverted. Instead, if you want to place additional content, create an
4+
"overview_content.md" file in `docs/` directory. The Sphinx tool will
5+
pick up on the content and merge the content.
6+
]: #
7+
8+
# {{ api.naming.title }}
9+
10+
Overview of the APIs available for {{ api.naming.title }}.
11+
12+
## All entries
13+
14+
Classes, methods and properties & attributes for
15+
{{ api.naming.title }}.
16+
17+
[classes](https://cloud.google.com/python/docs/reference/{{ api.naming.documentation_name }}/latest/summary_class.html)
18+
19+
[methods](https://cloud.google.com/python/docs/reference/{{ api.naming.documentation_name }}/latest/summary_method.html)
20+
21+
[properties and
22+
attributes](https://cloud.google.com/python/docs/reference/{{ api.naming.documentation_name }}/latest/summary_property.html)

gapic/utils/options.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ class Options:
5050
service_yaml_config: Dict[str, Any] = dataclasses.field(default_factory=dict)
5151
rest_numeric_enums: bool = False
5252
proto_plus_deps: Tuple[str, ...] = dataclasses.field(default=("",))
53+
api_description: str = ""
54+
documentation_name: str = ""
55+
documentation_uri: str = ""
56+
release_level: str = ""
57+
title: str = ""
5358

5459
# Class constants
5560
PYTHON_GAPIC_PREFIX: str = "python-gapic-"
@@ -71,6 +76,8 @@ class Options:
7176
# proto plus dependencies delineated by '+'
7277
# For example, 'google.cloud.api.v1+google.cloud.anotherapi.v2'
7378
"proto-plus-deps",
79+
"release-level", # One of ["preview", "stable"]
80+
"documentation-name",
7481
)
7582
)
7683

@@ -152,6 +159,14 @@ def tweak_path(p):
152159
# but it is not a field in the gogle.api.Service proto.
153160
service_yaml_config.pop("type", None)
154161

162+
api_description = service_yaml_config.get("documentation", {}).get(
163+
"summary", ""
164+
)
165+
166+
documentation_uri = service_yaml_config.get("publishing", {}).get(
167+
"documentation_uri", ""
168+
)
169+
155170
# Build the options instance.
156171
sample_paths = opts.pop("samples", [])
157172

@@ -196,7 +211,14 @@ def tweak_path(p):
196211
transport=opts.pop("transport", ["grpc"])[0].split("+"),
197212
service_yaml_config=service_yaml_config,
198213
rest_numeric_enums=bool(opts.pop("rest-numeric-enums", False)),
214+
title=service_yaml_config.get("title", ""),
215+
documentation_name=opts.pop("documentation-name", [""]).pop(),
216+
documentation_uri=documentation_uri,
217+
api_description=api_description,
199218
proto_plus_deps=proto_plus_deps,
219+
release_level=opts.pop(
220+
"release-level", ["preview"]
221+
).pop(), # Default to "preview" unless explicitly set to "stable"
200222
)
201223

202224
# Note: if we ever need to recursively check directories for sample

tests/integration/cloudasset_v1.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,13 @@ authentication:
4444
- selector: google.longrunning.Operations.GetOperation
4545
oauth:
4646
canonical_scopes: |-
47-
https://www.googleapis.com/auth/cloud-platform
47+
https://www.googleapis.com/auth/cloud-platform
48+
publishing:
49+
organization: CLIENT_LIBRARY_ORGANIZATION_UNSPECIFIED
50+
new_issue_uri: ''
51+
documentation_uri: 'https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/overview'
52+
api_short_name: ''
53+
github_label: ''
54+
doc_tag_prefix: ''
55+
codeowner_github_teams:
56+
library_settings:

tests/integration/eventarc_v1.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ authentication:
119119
120120
121121
publishing:
122+
organization: CLIENT_LIBRARY_ORGANIZATION_UNSPECIFIED
123+
new_issue_uri: ''
124+
documentation_uri: 'https://cloud.google.com/eventarc'
125+
api_short_name: ''
126+
github_label: ''
127+
doc_tag_prefix: ''
128+
codeowner_github_teams:
122129
library_settings:
123130
- version: 'google.cloud.eventarc.v1'
124131
python_settings:

0 commit comments

Comments
 (0)